mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Pager is working, mostly. (CVS 211)
FossilOrigin-Name: f82fa7070ae281804c019e6b05cd767dadaf0827
This commit is contained in:
20
Makefile.in
20
Makefile.in
@ -48,8 +48,8 @@ LIBREADLINE = @TARGET_READLINE_LIBS@
|
||||
# Object files for the SQLite library.
|
||||
#
|
||||
LIBOBJ = build.o dbbe.o dbbegdbm.o dbbemem.o delete.o expr.o insert.o \
|
||||
main.o parse.o printf.o random.o select.o table.o tokenize.o \
|
||||
update.o util.o vdbe.o where.o tclsqlite.o
|
||||
main.o pager.o parse.o printf.o random.o select.o table.o \
|
||||
tokenize.o update.o util.o vdbe.o where.o tclsqlite.o
|
||||
|
||||
# All of the source code files.
|
||||
#
|
||||
@ -63,6 +63,7 @@ SRC = \
|
||||
$(TOP)/src/expr.c \
|
||||
$(TOP)/src/insert.c \
|
||||
$(TOP)/src/main.c \
|
||||
$(TOP)/src/pager.c \
|
||||
$(TOP)/src/parse.y \
|
||||
$(TOP)/src/printf.c \
|
||||
$(TOP)/src/random.c \
|
||||
@ -79,6 +80,12 @@ SRC = \
|
||||
$(TOP)/src/vdbe.h \
|
||||
$(TOP)/src/where.c
|
||||
|
||||
# Source code to the test files.
|
||||
#
|
||||
TESTSRC = \
|
||||
$(TOP)/src/test1.c \
|
||||
$(TOP)/src/test2.c
|
||||
|
||||
# This is the default Makefile target. The objects listed here
|
||||
# are what get build when you type just "make" with no arguments.
|
||||
#
|
||||
@ -182,6 +189,9 @@ tclsqlite.o: $(TOP)/src/tclsqlite.c $(HDR)
|
||||
printf.o: $(TOP)/src/printf.c $(HDR)
|
||||
$(TCC) $(GDBM_FLAGS) $(TCL_FLAGS) -c $(TOP)/src/printf.c
|
||||
|
||||
pager.o: $(TOP)/src/pager.c $(HDR)
|
||||
$(TCC) $(GDBM_FLAGS) $(TCL_FLAGS) -c $(TOP)/src/pager.c
|
||||
|
||||
gdbmdump: $(TOP)/tool/gdbmdump.c
|
||||
$(TCC) $(GDBM_FLAGS) -o gdbmdump $(TOP)/tool/gdbmdump.c $(LIBGDBM)
|
||||
|
||||
@ -189,9 +199,9 @@ tclsqlite: $(TOP)/src/tclsqlite.c libsqlite.a
|
||||
$(TCC) $(TCL_FLAGS) -DTCLSH=1 -o sqlite_tester \
|
||||
$(TOP)/src/tclsqlite.c libsqlite.a $(LIBGDBM) $(LIBTCL)
|
||||
|
||||
sqlite_tester: $(TOP)/src/tclsqlite.c libsqlite.a $(TOP)/src/test1.c
|
||||
$(TCC) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST1=1 -o sqlite_tester \
|
||||
$(TOP)/src/test1.c $(TOP)/src/tclsqlite.c \
|
||||
sqlite_tester: $(TOP)/src/tclsqlite.c libsqlite.a $(TESTSRC)
|
||||
$(TCC) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1 -o sqlite_tester \
|
||||
$(TESTSRC) $(TOP)/src/tclsqlite.c \
|
||||
libsqlite.a $(LIBGDBM) $(LIBTCL)
|
||||
|
||||
test: sqlite_tester sqlite
|
||||
|
24
manifest
24
manifest
@ -1,7 +1,7 @@
|
||||
C Getting\sready\sto\sredo\sthe\sjournal\sfile\sformat.\s(CVS\s210)
|
||||
D 2001-04-14T16:38:23
|
||||
C Pager\sis\sworking,\smostly.\s(CVS\s211)
|
||||
D 2001-04-15T00:37:09
|
||||
F COPYRIGHT 74a8a6531a42e124df07ab5599aad63870fa0bd4
|
||||
F Makefile.in 4775f7fd1ed543606bb24fa3fada1bc90a23a6b9
|
||||
F Makefile.in ac01d6145714b0d1c9e99382caf03cf30d6f4c8d
|
||||
F README 51f6a4e7408b34afa5bc1c0485f61b6a4efb6958
|
||||
F VERSION 71874cb7e2a53c2bd22bb6affa7d223dd94a7a13
|
||||
F configure 260d3be664b6d9b4d2d985e66b6dae1ef723c86e x
|
||||
@ -9,7 +9,7 @@ F configure.in 6940e3f88bf3d28a10c73b06ab99fd3a7e039a61
|
||||
F doc/lemon.html e233a3e97a779c7a87e1bc4528c664a58e49dd47
|
||||
F doc/report1.txt 734cbae63b1310cc643fe5e9e3da1ab55a79b99e
|
||||
F src/TODO 38a68a489e56e9fd4a96263e0ff9404a47368ad4
|
||||
F src/build.c 6afbb6106c1e8c771ffcb81107b755e200310574
|
||||
F src/build.c 4f6a2d551c56342cd4a0420654835be3ad179651
|
||||
F src/dbbe.c ec82c602c598748204a61a35ab0c31e34ca58223
|
||||
F src/dbbe.h 7235b15c6c5d8be0c4da469cef9620cee70b1cc8
|
||||
F src/dbbegdbm.c 9d3a3c18b27f9f2533a3aaa3741e8668bdda7e98
|
||||
@ -26,8 +26,8 @@ F src/ex/sizes.tcl f54bad4a2ac567624be59131a6ee42d71b41a3d7
|
||||
F src/expr.c c4c24c3af1eba094a816522eb0e085bed518ee16
|
||||
F src/insert.c aa528e20a787af85432a61daaea6df394bd251d7
|
||||
F src/main.c 92ce30a89f622ba36cc8b7d912829e14a480722c
|
||||
F src/pager.c 67227909b9a16a2463bbfddf19347fcab7a251ae
|
||||
F src/pager.h 889c5cf517ad30704e295540793c893ac843fd5f
|
||||
F src/pager.c 52dc932c937cfd5ccdd3c40527ea57878994a99c
|
||||
F src/pager.h 8678d9a97fdf1c111b619a13a351e5c8ab97cb81
|
||||
F src/parse.y 8fc096948994a7ffbf61ba13129cc589f794a9cb
|
||||
F src/printf.c b1e22a47be8cdf707815647239991e08e8cb69f9
|
||||
F src/random.c b36c3f57dc80c8f354e6bfbf39cf1e1de021d54a
|
||||
@ -37,8 +37,9 @@ F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
|
||||
F src/sqlite.h.in 3e5906f72608f0fd4394dfbb1d7e8d35b8353677
|
||||
F src/sqliteInt.h fc1000f023b41882bbdb8db4f80172f77b44307b
|
||||
F src/table.c adcaf074f6c1075e86359174e68701fa2acfc4d6
|
||||
F src/tclsqlite.c 83dcbf015ea0319c2a97514b8b812a12d621e40a
|
||||
F src/tclsqlite.c 1f2bf4691a6bd81fbff1856ae4a12db24d1265f7
|
||||
F src/test1.c abb3cb427e735ae87e6533f5b3b7164b7da91bc4
|
||||
F src/test2.c 49e27f03d1866635c2c4539e0983e5590a322872
|
||||
F src/tokenize.c 0118b57702cb6550769316e8443b06760b067acf
|
||||
F src/update.c 0cf789656a936d4356668393267692fa4b03ffc6
|
||||
F src/util.c 1b396ac34e30dd6222d82e996c17b161bbc906bc
|
||||
@ -58,6 +59,7 @@ F test/insert2.test 732405e30331635af8d159fccabe835eea5cd0c6
|
||||
F test/lock.test bca7d53de73138b1f670a2fbdb1f481ff7eaa45a
|
||||
F test/main.test da635f9e078cd21ddf074e727381a715064489ff
|
||||
F test/malloc.test 3daa97f6a9577d8f4c6e468b274333af19ce5861
|
||||
F test/pager.test 2317ccf5821f15a637b84fa5f4d36b4c85a52a12
|
||||
F test/printf.test 4c71871e1a75a2dacb673945fc13ddb30168798f
|
||||
F test/rowid.test 128453599def7435e988216f7fe89c7450b8a9a3
|
||||
F test/select1.test 223507655cdb4f9901d83fa7f5c5328e022c211f
|
||||
@ -88,7 +90,7 @@ F www/arch.fig 4f246003b7da23bd63b8b0af0618afb4ee3055c8
|
||||
F www/arch.png 8dae0766d42ed3de9ed013c1341a5792bcf633e6
|
||||
F www/arch.tcl a40380c1fe0080c43e6cc5c20ed70731511b06be
|
||||
F www/c_interface.tcl ddca19005c47dd5a15882addc02fff5de83d8ed9
|
||||
F www/changes.tcl e89e31b688833f6393dc1add45e3b4bd1da966b8
|
||||
F www/changes.tcl 822b425cc50cb8e21563dd1aa0e4b79cf780f3dc
|
||||
F www/crosscompile.tcl c99efacb3aefaa550c6e80d91b240f55eb9fd33e
|
||||
F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c
|
||||
F www/fileformat.tcl cfb7fba80b7275555281ba2f256c00734bcdd1c9
|
||||
@ -99,7 +101,7 @@ F www/opcode.tcl cb3a1abf8b7b9be9f3a228d097d6bf8b742c2b6f
|
||||
F www/sqlite.tcl cb0d23d8f061a80543928755ec7775da6e4f362f
|
||||
F www/tclsqlite.tcl 06f81c401f79a04f2c5ebfb97e7c176225c0aef2
|
||||
F www/vdbe.tcl 0c8aaa529dd216ccbf7daaabd80985e413d5f9ad
|
||||
P 3bde128418fe70a2fd62bf9e013999827a16053c
|
||||
R e5aeeb4c78022c778bcfebd97e61f590
|
||||
P 42c2f3fe68c8a6bab96e035371ecd64296c5491f
|
||||
R 558a8ad440acd3c96149b89f77d45a0d
|
||||
U drh
|
||||
Z 3ef685e141624dcddb66699cb8550c69
|
||||
Z 6080de1bb9d6e86286ceffe08ee69ef0
|
||||
|
@ -1 +1 @@
|
||||
42c2f3fe68c8a6bab96e035371ecd64296c5491f
|
||||
f82fa7070ae281804c019e6b05cd767dadaf0827
|
21
src/build.c
21
src/build.c
@ -33,7 +33,7 @@
|
||||
** COPY
|
||||
** VACUUM
|
||||
**
|
||||
** $Id: build.c,v 1.27 2001/04/11 14:28:42 drh Exp $
|
||||
** $Id: build.c,v 1.28 2001/04/15 00:37:09 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@ -196,7 +196,7 @@ static void sqliteDeleteIndex(sqlite *db, Index *pIndex){
|
||||
** Table. No changes are made to disk by this routine.
|
||||
**
|
||||
** This routine just deletes the data structure. It does not unlink
|
||||
** the table data structure from the hash table. But does it destroy
|
||||
** the table data structure from the hash table. But it does destroy
|
||||
** memory structures of the indices associated with the table.
|
||||
**
|
||||
** Indices associated with the table are unlinked from the "db"
|
||||
@ -236,7 +236,13 @@ char *sqliteTableNameFromToken(Token *pName){
|
||||
/*
|
||||
** Begin constructing a new table representation in memory. This is
|
||||
** the first of several action routines that get called in response
|
||||
** to a CREATE TABLE statement.
|
||||
** to a CREATE TABLE statement. In particular, this routine is called
|
||||
** after seeing tokens "CREATE" and "TABLE" and the table name. The
|
||||
** pStart token is the CREATE and pName is the table name.
|
||||
**
|
||||
** The new table is constructed in files of the pParse structure. As
|
||||
** more of the CREATE TABLE statement is parsed, additional action
|
||||
** routines are called to build up more of the table.
|
||||
*/
|
||||
void sqliteStartTable(Parse *pParse, Token *pStart, Token *pName){
|
||||
Table *pTable;
|
||||
@ -273,6 +279,11 @@ void sqliteStartTable(Parse *pParse, Token *pStart, Token *pName){
|
||||
|
||||
/*
|
||||
** Add a new column to the table currently being constructed.
|
||||
**
|
||||
** The parser calls this routine once for each column declaration
|
||||
** in a CREATE TABLE statement. sqliteStartTable() gets called
|
||||
** first to get things going. Then this routine is called for each
|
||||
** column.
|
||||
*/
|
||||
void sqliteAddColumn(Parse *pParse, Token *pName){
|
||||
Table *p;
|
||||
@ -295,6 +306,9 @@ void sqliteAddColumn(Parse *pParse, Token *pName){
|
||||
** The given token is the default value for the last column added to
|
||||
** the table currently under construction. If "minusFlag" is true, it
|
||||
** means the value token was preceded by a minus sign.
|
||||
**
|
||||
** This routine is called by the parser while in the middle of
|
||||
** parsing a CREATE TABLE statement.
|
||||
*/
|
||||
void sqliteAddDefaultValue(Parse *pParse, Token *pVal, int minusFlag){
|
||||
Table *p;
|
||||
@ -403,6 +417,7 @@ Table *sqliteTableFromToken(Parse *pParse, Token *pTok){
|
||||
|
||||
/*
|
||||
** This routine is called to do the work of a DROP TABLE statement.
|
||||
** pName is the name of the table to be dropped.
|
||||
*/
|
||||
void sqliteDropTable(Parse *pParse, Token *pName){
|
||||
Table *pTable;
|
||||
|
723
src/pager.c
723
src/pager.c
File diff suppressed because it is too large
Load Diff
23
src/pager.h
23
src/pager.h
@ -25,9 +25,8 @@
|
||||
** subsystem. The page cache subsystem reads and writes a file a page
|
||||
** at a time and provides a journal for rollback.
|
||||
**
|
||||
** @(#) $Id: pager.h,v 1.1 2001/04/03 16:53:22 drh Exp $
|
||||
** @(#) $Id: pager.h,v 1.2 2001/04/15 00:37:09 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
/*
|
||||
** The size of one page
|
||||
@ -45,12 +44,14 @@ typedef unsigned int Pgno;
|
||||
*/
|
||||
typedef struct Pager Pager;
|
||||
|
||||
int sqlite_pager_open(Pager **ppPager, const char *zFilename);
|
||||
int sqlite_pager_close(Pager *pPager);
|
||||
int sqlite_pager_get(Pager *pPager, Pgno pgno, void **ppPage);
|
||||
int sqlite_pager_unref(void*);
|
||||
Pgno sqlite_pager_pagenumber(void*);
|
||||
int sqlite_pager_write(void*);
|
||||
int sqlite_pager_pagecount(Pager*);
|
||||
int sqlite_pager_commit(Pager*);
|
||||
int sqlite_pager_rollback(Pager*);
|
||||
int sqlitepager_open(Pager **ppPager, const char *zFilename, int nPage);
|
||||
int sqlitepager_close(Pager *pPager);
|
||||
int sqlitepager_get(Pager *pPager, Pgno pgno, void **ppPage);
|
||||
int sqlitepager_unref(void*);
|
||||
Pgno sqlitepager_pagenumber(void*);
|
||||
int sqlitepager_write(void*);
|
||||
int sqlitepager_pagecount(Pager*);
|
||||
int sqlitepager_commit(Pager*);
|
||||
int sqlitepager_rollback(Pager*);
|
||||
|
||||
int *sqlitepager_stats(Pager*);
|
||||
|
@ -23,7 +23,7 @@
|
||||
*************************************************************************
|
||||
** A TCL Interface to SQLite
|
||||
**
|
||||
** $Id: tclsqlite.c,v 1.17 2001/04/07 15:24:33 drh Exp $
|
||||
** $Id: tclsqlite.c,v 1.18 2001/04/15 00:37:09 drh Exp $
|
||||
*/
|
||||
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
|
||||
|
||||
@ -507,10 +507,12 @@ int TCLSH_MAIN(int argc, char **argv){
|
||||
Tcl_FindExecutable(argv[0]);
|
||||
interp = Tcl_CreateInterp();
|
||||
Sqlite_Init(interp);
|
||||
#ifdef SQLITE_TEST1
|
||||
#ifdef SQLITE_TEST
|
||||
{
|
||||
extern int Sqlitetest1_Init(Tcl_Interp*);
|
||||
extern int Sqlitetest2_Init(Tcl_Interp*);
|
||||
Sqlitetest1_Init(interp);
|
||||
Sqlitetest2_Init(interp);
|
||||
}
|
||||
#endif
|
||||
if( argc>=2 ){
|
||||
|
384
src/test2.c
Normal file
384
src/test2.c
Normal file
@ -0,0 +1,384 @@
|
||||
/*
|
||||
** Copyright (c) 2001 D. Richard Hipp
|
||||
**
|
||||
** This program is free software; you can redistribute it and/or
|
||||
** modify it under the terms of the GNU General Public
|
||||
** License as published by the Free Software Foundation; either
|
||||
** version 2 of the License, or (at your option) any later version.
|
||||
**
|
||||
** This program is distributed in the hope that it will be useful,
|
||||
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
** General Public License for more details.
|
||||
**
|
||||
** You should have received a copy of the GNU General Public
|
||||
** License along with this library; if not, write to the
|
||||
** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
** Boston, MA 02111-1307, USA.
|
||||
**
|
||||
** Author contact information:
|
||||
** drh@hwaci.com
|
||||
** http://www.hwaci.com/drh/
|
||||
**
|
||||
*************************************************************************
|
||||
** Code for testing the pager.c module in SQLite. This code
|
||||
** is not included in the SQLite library. It is used for automated
|
||||
** testing of the SQLite library.
|
||||
**
|
||||
** $Id: test2.c,v 1.1 2001/04/15 00:37:09 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
#include "pager.h"
|
||||
#include "tcl.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
** Interpret an SQLite error number
|
||||
*/
|
||||
static char *errorName(int rc){
|
||||
char *zName;
|
||||
switch( rc ){
|
||||
case SQLITE_OK: zName = "SQLITE_OK"; break;
|
||||
case SQLITE_ERROR: zName = "SQLITE_ERROR"; break;
|
||||
case SQLITE_INTERNAL: zName = "SQLITE_INTERNAL"; break;
|
||||
case SQLITE_PERM: zName = "SQLITE_PERM"; break;
|
||||
case SQLITE_ABORT: zName = "SQLITE_ABORT"; break;
|
||||
case SQLITE_BUSY: zName = "SQLITE_BUSY"; break;
|
||||
case SQLITE_NOMEM: zName = "SQLITE_NOMEM"; break;
|
||||
case SQLITE_READONLY: zName = "SQLITE_READONLY"; break;
|
||||
case SQLITE_INTERRUPT: zName = "SQLITE_INTERRUPT"; break;
|
||||
case SQLITE_IOERR: zName = "SQLITE_IOERR"; break;
|
||||
case SQLITE_CORRUPT: zName = "SQLITE_CORRUPT"; break;
|
||||
case SQLITE_NOTFOUND: zName = "SQLITE_NOTFOUND"; break;
|
||||
case SQLITE_FULL: zName = "SQLITE_FULL"; break;
|
||||
case SQLITE_CANTOPEN: zName = "SQLITE_CANTOPEN"; break;
|
||||
case SQLITE_PROTOCOL: zName = "SQLITE_PROTOCOL"; break;
|
||||
default: zName = "SQLITE_Unknown"; break;
|
||||
}
|
||||
return zName;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_open FILENAME N-PAGE
|
||||
**
|
||||
** Open a new pager
|
||||
*/
|
||||
static int pager_open(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
int nPage;
|
||||
int rc;
|
||||
char zBuf[100];
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" FILENAME N-PAGE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[2], &nPage) ) return TCL_ERROR;
|
||||
rc = sqlitepager_open(&pPager, argv[1], nPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"0x%x",(int)pPager);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_close ID
|
||||
**
|
||||
** Close the given pager.
|
||||
*/
|
||||
static int pager_close(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
int rc;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlitepager_close(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_rollback ID
|
||||
**
|
||||
** Rollback changes
|
||||
*/
|
||||
static int pager_rollback(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
int rc;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlitepager_rollback(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_commit ID
|
||||
**
|
||||
** Commit all changes
|
||||
*/
|
||||
static int pager_commit(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
int rc;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
rc = sqlitepager_commit(pPager);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_stats ID
|
||||
**
|
||||
** Return pager statistics.
|
||||
*/
|
||||
static int pager_stats(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
int i, *a;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
a = sqlitepager_stats(pPager);
|
||||
for(i=0; i<9; i++){
|
||||
static char *zName[] = {
|
||||
"ref", "page", "max", "size", "state", "err",
|
||||
"hit", "miss", "ovfl",
|
||||
};
|
||||
char zBuf[100];
|
||||
Tcl_AppendElement(interp, zName[i]);
|
||||
sprintf(zBuf,"%d",a[i]);
|
||||
Tcl_AppendElement(interp, zBuf);
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: pager_pagecount ID
|
||||
**
|
||||
** Return the size of the database file.
|
||||
*/
|
||||
static int pager_pagecount(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
char zBuf[100];
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
sprintf(zBuf,"%d",sqlitepager_pagecount(pPager));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: page_get ID PGNO
|
||||
**
|
||||
** Return a pointer to a page from the database.
|
||||
*/
|
||||
static int page_get(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
Pager *pPager;
|
||||
char zBuf[100];
|
||||
void *pPage;
|
||||
int pgno;
|
||||
int rc;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" ID PGNO\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPager) ) return TCL_ERROR;
|
||||
if( Tcl_GetInt(interp, argv[2], &pgno) ) return TCL_ERROR;
|
||||
rc = sqlitepager_get(pPager, pgno, &pPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
sprintf(zBuf,"0x%x",(int)pPage);
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: page_unref PAGE
|
||||
**
|
||||
** Drop a pointer to a page.
|
||||
*/
|
||||
static int page_unref(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
void *pPage;
|
||||
int rc;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" PAGE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
rc = sqlitepager_unref(pPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: page_read PAGE
|
||||
**
|
||||
** Return the content of a page
|
||||
*/
|
||||
static int page_read(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
char zBuf[100];
|
||||
void *pPage;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" PAGE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
memcpy(zBuf, pPage, sizeof(zBuf));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: page_number PAGE
|
||||
**
|
||||
** Return the page number for a page.
|
||||
*/
|
||||
static int page_number(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
char zBuf[100];
|
||||
void *pPage;
|
||||
if( argc!=2 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" PAGE\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
sprintf(zBuf, "%d", sqlitepager_pagenumber(pPage));
|
||||
Tcl_AppendResult(interp, zBuf, 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Usage: page_write PAGE DATA
|
||||
**
|
||||
** Write something into a page.
|
||||
*/
|
||||
static int page_write(
|
||||
void *NotUsed,
|
||||
Tcl_Interp *interp, /* The TCL interpreter that invoked this command */
|
||||
int argc, /* Number of arguments */
|
||||
char **argv /* Text of each argument */
|
||||
){
|
||||
void *pPage;
|
||||
int rc;
|
||||
if( argc!=3 ){
|
||||
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
|
||||
" PAGE DATA\"", 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( Tcl_GetInt(interp, argv[1], (int*)&pPage) ) return TCL_ERROR;
|
||||
rc = sqlitepager_write(pPage);
|
||||
if( rc!=SQLITE_OK ){
|
||||
Tcl_AppendResult(interp, errorName(rc), 0);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
strncpy((char*)pPage, argv[2], SQLITE_PAGE_SIZE-1);
|
||||
((char*)pPage)[SQLITE_PAGE_SIZE-1] = 0;
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
*/
|
||||
int Sqlitetest2_Init(Tcl_Interp *interp){
|
||||
Tcl_CreateCommand(interp, "pager_open", pager_open, 0, 0);
|
||||
Tcl_CreateCommand(interp, "pager_close", pager_close, 0, 0);
|
||||
Tcl_CreateCommand(interp, "pager_commit", pager_commit, 0, 0);
|
||||
Tcl_CreateCommand(interp, "pager_rollback", pager_rollback, 0, 0);
|
||||
Tcl_CreateCommand(interp, "pager_stats", pager_stats, 0, 0);
|
||||
Tcl_CreateCommand(interp, "pager_pagecount", pager_pagecount, 0, 0);
|
||||
Tcl_CreateCommand(interp, "page_get", page_get, 0, 0);
|
||||
Tcl_CreateCommand(interp, "page_unref", page_unref, 0, 0);
|
||||
Tcl_CreateCommand(interp, "page_read", page_read, 0, 0);
|
||||
Tcl_CreateCommand(interp, "page_write", page_write, 0, 0);
|
||||
Tcl_CreateCommand(interp, "page_number", page_number, 0, 0);
|
||||
return TCL_OK;
|
||||
}
|
176
test/pager.test
Normal file
176
test/pager.test
Normal file
@ -0,0 +1,176 @@
|
||||
# Copyright (c) 1999, 2000 D. Richard Hipp
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public
|
||||
# License along with this library; if not, write to the
|
||||
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
# Boston, MA 02111-1307, USA.
|
||||
#
|
||||
# Author contact information:
|
||||
# drh@hwaci.com
|
||||
# http://www.hwaci.com/drh/
|
||||
#
|
||||
#***********************************************************************
|
||||
# This file implements regression tests for SQLite library. The
|
||||
# focus of this script is page cache subsystem.
|
||||
#
|
||||
# $Id: pager.test,v 1.1 2001/04/15 00:37:21 drh Exp $
|
||||
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
if {$dbprefix!="mem:" && [info commands pager_open]!=""} {
|
||||
|
||||
# Basic sanity check. Open and close a pager.
|
||||
#
|
||||
do_test pager-1.0 {
|
||||
catch {file delete -force ptf1.db}
|
||||
catch {file delete -force ptf1.db-journal}
|
||||
set v [catch {
|
||||
set ::p1 [pager_open ptf1.db 10]
|
||||
} msg]
|
||||
} {0}
|
||||
do_test pager-1.1 {
|
||||
pager_stats $::p1
|
||||
} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
|
||||
do_test pager-1.2 {
|
||||
pager_pagecount $::p1
|
||||
} {0}
|
||||
do_test pager-1.3 {
|
||||
pager_stats $::p1
|
||||
} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 0 ovfl 0}
|
||||
do_test pager-1.4 {
|
||||
pager_close $::p1
|
||||
} {}
|
||||
|
||||
# Try to write a few pages.
|
||||
#
|
||||
do_test pager-2.1 {
|
||||
set v [catch {
|
||||
set ::p1 [pager_open ptf1.db 10]
|
||||
} msg]
|
||||
} {0}
|
||||
do_test pager-2.2 {
|
||||
set v [catch {
|
||||
set ::g1 [page_get $::p1 0]
|
||||
} msg]
|
||||
lappend v $msg
|
||||
} {1 SQLITE_ERROR}
|
||||
do_test pager-2.3 {
|
||||
set v [catch {
|
||||
set ::g1 [page_get $::p1 1]
|
||||
} msg]
|
||||
if {$v} {lappend v $msg}
|
||||
set v
|
||||
} {0}
|
||||
do_test pager-2.4 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size -1 state 1 err 0 hit 0 miss 1 ovfl 0}
|
||||
do_test pager-2.5 {
|
||||
pager_pagecount $::p1
|
||||
} {0}
|
||||
do_test pager-2.6 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size 0 state 1 err 0 hit 0 miss 1 ovfl 0}
|
||||
do_test pager-2.7 {
|
||||
page_number $::g1
|
||||
} {1}
|
||||
do_test pager-2.8 {
|
||||
page_read $::g1
|
||||
} {}
|
||||
do_test pager-2.9 {
|
||||
page_unref $::g1
|
||||
} {}
|
||||
do_test pager-2.10 {
|
||||
pager_stats $::p1
|
||||
} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 1 ovfl 0}
|
||||
do_test pager-2.11 {
|
||||
set ::g1 [page_get $::p1 1]
|
||||
expr {$::g1!=0}
|
||||
} {1}
|
||||
do_test pager-2.12 {
|
||||
page_number $::g1
|
||||
} {1}
|
||||
do_test pager-2.13 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size -1 state 1 err 0 hit 0 miss 2 ovfl 0}
|
||||
do_test pager-2.14 {
|
||||
set v [catch {
|
||||
page_write $::g1 "Page-One"
|
||||
} msg]
|
||||
lappend v $msg
|
||||
} {0 {}}
|
||||
do_test pager-2.15 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size 0 state 2 err 0 hit 0 miss 2 ovfl 0}
|
||||
do_test pager-2.16 {
|
||||
page_read $::g1
|
||||
} {Page-One}
|
||||
do_test pager-2.17 {
|
||||
set v [catch {
|
||||
pager_commit $::p1
|
||||
} msg]
|
||||
lappend v $msg
|
||||
} {0 {}}
|
||||
do_test pager-2.20 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size -1 state 1 err 0 hit 0 miss 2 ovfl 0}
|
||||
do_test pager-2.19 {
|
||||
pager_pagecount $::p1
|
||||
} {1}
|
||||
do_test pager-2.21 {
|
||||
pager_stats $::p1
|
||||
} {ref 1 page 1 max 10 size 1 state 1 err 0 hit 0 miss 2 ovfl 0}
|
||||
do_test pager-2.22 {
|
||||
page_unref $::g1
|
||||
} {}
|
||||
do_test pager-2.23 {
|
||||
pager_stats $::p1
|
||||
} {ref 0 page 0 max 10 size -1 state 0 err 0 hit 0 miss 2 ovfl 0}
|
||||
do_test pager-2.24 {
|
||||
set v [catch {
|
||||
page_get $::p1 1
|
||||
} ::g1]
|
||||
if {$v} {lappend v $::g1}
|
||||
set v
|
||||
} {0}
|
||||
do_test pager-2.25 {
|
||||
page_read $::g1
|
||||
} {Page-One}
|
||||
do_test pager-2.26 {
|
||||
set v [catch {
|
||||
page_write $::g1 {page-one}
|
||||
} msg]
|
||||
lappend v $msg
|
||||
} {0 {}}
|
||||
do_test pager-2.27 {
|
||||
page_read $::g1
|
||||
} {page-one}
|
||||
do_test pager-2.28 {
|
||||
set v [catch {
|
||||
pager_rollback $::p1
|
||||
} msg]
|
||||
lappend v $msg
|
||||
} {0 {}}
|
||||
do_test pager-2.29 {
|
||||
page_read $::g1
|
||||
} {Page-One}
|
||||
|
||||
do_test pager-2.99 {
|
||||
pager_close $::p1
|
||||
} {}
|
||||
|
||||
|
||||
} ;# end if( not mem: and has pager_open command );
|
||||
|
||||
finish_test
|
@ -17,7 +17,8 @@ proc chng {date desc} {
|
||||
puts "<DD><P><UL>$desc</UL></P></DD>"
|
||||
}
|
||||
|
||||
chng {2001 Apr 12 (1.0.31)} {
|
||||
chng {2001 Apr 14 (1.0.31)} {
|
||||
<li>Pager subsystem added but not yet used.</li>
|
||||
<li>More robust handling of out-of-memory errors.</li>
|
||||
<li>New tests added to the test suite.</li>
|
||||
}
|
||||
|
Reference in New Issue
Block a user