diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/btree.c | 33 | ||||
-rw-r--r-- | src/btree.h | 26 | ||||
-rw-r--r-- | src/build.c | 36 | ||||
-rw-r--r-- | src/delete.c | 26 | ||||
-rw-r--r-- | src/expr.c | 28 | ||||
-rw-r--r-- | src/insert.c | 28 | ||||
-rw-r--r-- | src/main.c | 26 | ||||
-rw-r--r-- | src/pager.c | 96 | ||||
-rw-r--r-- | src/pager.h | 26 | ||||
-rw-r--r-- | src/parse.y | 26 | ||||
-rw-r--r-- | src/random.c | 26 | ||||
-rw-r--r-- | src/select.c | 28 | ||||
-rw-r--r-- | src/shell.c | 26 | ||||
-rw-r--r-- | src/sqlite.h.in | 53 | ||||
-rw-r--r-- | src/sqliteInt.h | 26 | ||||
-rw-r--r-- | src/table.c | 24 | ||||
-rw-r--r-- | src/tclsqlite.c | 26 | ||||
-rw-r--r-- | src/test1.c | 26 | ||||
-rw-r--r-- | src/test2.c | 26 | ||||
-rw-r--r-- | src/test3.c | 26 | ||||
-rw-r--r-- | src/tokenize.c | 31 | ||||
-rw-r--r-- | src/update.c | 26 | ||||
-rw-r--r-- | src/util.c | 30 | ||||
-rw-r--r-- | src/vdbe.c | 161 | ||||
-rw-r--r-- | src/vdbe.h | 26 | ||||
-rw-r--r-- | src/where.c | 26 |
26 files changed, 336 insertions, 602 deletions
diff --git a/src/btree.c b/src/btree.c index 2dc2d4c67..09742e62c 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1,27 +1,15 @@ /* -** Copyright (c) 2001 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.28 2001/09/15 13:15:13 drh Exp $ +** $Id: btree.c,v 1.29 2001/09/16 00:13:26 drh Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -53,7 +41,7 @@ ** database page. If the payload is larger than MX_LOCAL_PAYLOAD bytes ** then surplus bytes are stored on overflow pages. The payload for an ** entry and the preceding pointer are combined to form a "Cell". Each -** page has a smaller header which contains the Ptr(N+1) pointer. +** page has a small header which contains the Ptr(N+1) pointer. ** ** The first page of the file contains a magic string used to verify that ** the file really is a valid BTree database, a pointer to a list of unused @@ -74,7 +62,7 @@ */ typedef unsigned int uptr; -/* There are already definedin sqliteInt.h... +/* There are already defined in sqliteInt.h... ** typedef unsigned int u32; ** typedef unsigned short int u16; ** typedef unsigned char u8; @@ -122,7 +110,8 @@ static const char zMagicHeader[] = ** problem. ** ** The number used was obtained at random and has no special -** significance. +** significance other than the fact that it represents a different +** integer on little-endian and big-endian machines. */ #define MAGIC 0xdae37528 diff --git a/src/btree.h b/src/btree.h index e754427f7..02cd9b59e 100644 --- a/src/btree.h +++ b/src/btree.h @@ -1,30 +1,18 @@ /* -** Copyright (c) 2001 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the sqlite B-Tree file ** subsystem. ** -** @(#) $Id: btree.h,v 1.13 2001/09/14 18:54:08 drh Exp $ +** @(#) $Id: btree.h,v 1.14 2001/09/16 00:13:26 drh Exp $ */ #ifndef _BTREE_H_ #define _BTREE_H_ diff --git a/src/build.c b/src/build.c index eb9ea05a0..b6a5074ec 100644 --- a/src/build.c +++ b/src/build.c @@ -1,29 +1,17 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* -** This file contains C code routines that are called by the parser -** when syntax rules are reduced. The routines in this file handle -** the following kinds of syntax: +** This file contains C code routines that are called by the SQLite parser +** when syntax rules are reduced. The routines in this file handle the +** following kinds of SQL syntax: ** ** CREATE TABLE ** DROP TABLE @@ -32,8 +20,12 @@ ** creating expressions and ID lists ** COPY ** VACUUM +** BEGIN TRANSACTION +** COMMIT +** ROLLBACK +** PRAGMA ** -** $Id: build.c,v 1.35 2001/09/15 00:57:28 drh Exp $ +** $Id: build.c,v 1.36 2001/09/16 00:13:26 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> diff --git a/src/delete.c b/src/delete.c index 3d2cff99b..2b712307b 100644 --- a/src/delete.c +++ b/src/delete.c @@ -1,30 +1,18 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle DELETE FROM statements. ** -** $Id: delete.c,v 1.13 2001/09/15 00:57:29 drh Exp $ +** $Id: delete.c,v 1.14 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" diff --git a/src/expr.c b/src/expr.c index e5d4535a5..7710743f7 100644 --- a/src/expr.c +++ b/src/expr.c @@ -1,30 +1,18 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains routines used for analyzing expressions and -** for generating VDBE code that evaluates expressions. +** for generating VDBE code that evaluates expressions in SQLite. ** -** $Id: expr.c,v 1.27 2001/09/14 03:24:25 drh Exp $ +** $Id: expr.c,v 1.28 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" diff --git a/src/insert.c b/src/insert.c index 28a13cdd0..3fcb61e70 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1,30 +1,18 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains C code routines that are called by the parser -** to handle INSERT statements. +** to handle INSERT statements in SQLite. ** -** $Id: insert.c,v 1.17 2001/09/15 00:57:29 drh Exp $ +** $Id: insert.c,v 1.18 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" diff --git a/src/main.c b/src/main.c index e3863e213..c882abf0c 100644 --- a/src/main.c +++ b/src/main.c @@ -1,24 +1,12 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** Main file for the SQLite library. The routines in this file @@ -26,7 +14,7 @@ ** other files are for internal use by SQLite and should not be ** accessed by users of the library. ** -** $Id: main.c,v 1.36 2001/09/15 00:57:29 drh Exp $ +** $Id: main.c,v 1.37 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" #if defined(HAVE_USLEEP) && HAVE_USLEEP diff --git a/src/pager.c b/src/pager.c index 4ca2b20a1..0b8ac722e 100644 --- a/src/pager.c +++ b/src/pager.c @@ -1,33 +1,24 @@ /* -** Copyright (c) 2001 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* -** This is the implementation of the page cache subsystem. +** This is the implementation of the page cache subsystem or "pager". ** -** The page cache is used to access a database file. The pager journals -** all writes in order to support rollback. Locking is used to limit -** access to one or more reader or to one writer. +** The pager is used to access a database disk file. It implements +** atomic commit and rollback through the use of a journal file that +** is separate from the database file. The pager also implements file +** locking to prevent two processes from writing the same database +** file simultaneously, or one process from reading the database while +** another is writing. ** -** @(#) $Id: pager.c,v 1.19 2001/09/15 00:57:29 drh Exp $ +** @(#) $Id: pager.c,v 1.20 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" #include "pager.h" @@ -103,7 +94,7 @@ struct PgHdr { ** How big to make the hash table used for locating in-memory pages ** by page number. Knuth says this should be a prime number. */ -#define N_PG_HASH 907 +#define N_PG_HASH 373 /* ** A open page cache is an instance of the following structure. @@ -684,7 +675,16 @@ int sqlitepager_ref(void *pData){ } /* -** Sync the journal and write all free dirty pages to the database file. +** Sync the journal and then write all free dirty pages to the database +** file. +** +** Writing all free dirty pages to the database after the sync is a +** non-obvious optimization. fsync() is an expensive operation so we +** want to minimize the number that occur. So after an fsync() is forced +** and we are free to write dirty pages back to the database, it is best +** to go ahead and do as much of that as possible to minimize the chance +** of having to do another fsync() later on. Writing dirty free pages +** in this way make database operations go up to 10 times faster. */ static int syncAllPages(Pager *pPager){ PgHdr *pPg; @@ -818,6 +818,19 @@ int sqlitepager_get(Pager *pPager, Pgno pgno, void **ppPage){ while( pPg->dirty && 0<cnt-- && pPg->pNextFree ){ pPg = pPg->pNextFree; } + + /* If we could not find a page that has not been used recently + ** and which is not dirty, then sync the journal and write all + ** dirty free pages into the database file, thus making them + ** clean pages and available for recycling. + ** + ** We have to sync the journal before writing a page to the main + ** database. But syncing is a very slow operation. So after a + ** sync, it is best to write everything we can back to the main + ** database to minimize the risk of having to sync again in the + ** near future. That is way we write all dirty pages after a + ** sync. + */ if( pPg==0 || pPg->dirty ){ int rc = syncAllPages(pPager); if( rc!=0 ){ @@ -828,39 +841,6 @@ int sqlitepager_get(Pager *pPager, Pgno pgno, void **ppPage){ pPg = pPager->pFirst; } assert( pPg->nRef==0 ); - - -#if 0 - /**** Since putting in the call to syncAllPages() above, this code - ** is no longer used. I've kept it here for historical reference - ** only. - */ - /* If the page to be recycled is dirty, sync the journal and write - ** the old page into the database. */ - if( pPg->dirty ){ - int rc; - assert( pPg->inJournal==1 ); - assert( pPager->state==SQLITE_WRITELOCK ); - if( pPager->needSync ){ - rc = fsync(pPager->jfd); - if( rc!=0 ){ - rc = sqlitepager_rollback(pPager); - *ppPage = 0; - if( rc==SQLITE_OK ) rc = SQLITE_IOERR; - return rc; - } - pPager->needSync = 0; - } - pager_seek(pPager->fd, (pPg->pgno-1)*SQLITE_PAGE_SIZE); - rc = pager_write(pPager->fd, PGHDR_TO_DATA(pPg), SQLITE_PAGE_SIZE); - if( rc!=SQLITE_OK ){ - rc = sqlitepager_rollback(pPager); - *ppPage = 0; - if( rc==SQLITE_OK ) rc = SQLITE_FULL; - return rc; - } - } -#endif assert( pPg->dirty==0 ); /* Unlink the old page from the free list and the hash table diff --git a/src/pager.h b/src/pager.h index 363704658..0e72715fe 100644 --- a/src/pager.h +++ b/src/pager.h @@ -1,31 +1,19 @@ /* -** Copyright (c) 2001 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** This header file defines the interface that the sqlite page cache ** 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.10 2001/09/15 13:15:13 drh Exp $ +** @(#) $Id: pager.h,v 1.11 2001/09/16 00:13:27 drh Exp $ */ /* diff --git a/src/parse.y b/src/parse.y index 373497d35..da0eafbec 100644 --- a/src/parse.y +++ b/src/parse.y @@ -1,24 +1,12 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains SQLite's grammar for SQL. Process this file @@ -26,7 +14,7 @@ ** the parser. Lemon will also generate a header file containing ** numeric codes for all of the tokens. ** -** @(#) $Id: parse.y,v 1.29 2001/09/14 18:54:09 drh Exp $ +** @(#) $Id: parse.y,v 1.30 2001/09/16 00:13:27 drh Exp $ */ %token_prefix TK_ %token_type {Token} diff --git a/src/random.c b/src/random.c index bf666b403..416b5dc53 100644 --- a/src/random.c +++ b/src/random.c @@ -1,24 +1,12 @@ /* -** Copyright (c) 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains code to implement a pseudo-random number @@ -27,7 +15,7 @@ ** Random numbers are used by some of the database backends in order ** to generate random integer keys for tables or random filenames. ** -** $Id: random.c,v 1.4 2001/09/14 03:24:25 drh Exp $ +** $Id: random.c,v 1.5 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" #include <time.h> diff --git a/src/select.c b/src/select.c index 07f0fbaca..7b9c47942 100644 --- a/src/select.c +++ b/src/select.c @@ -1,30 +1,18 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains C code routines that are called by the parser -** to handle SELECT statements. +** to handle SELECT statements in SQLite. ** -** $Id: select.c,v 1.36 2001/09/14 03:24:25 drh Exp $ +** $Id: select.c,v 1.37 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" diff --git a/src/shell.c b/src/shell.c index 7548e6819..59c5f6a0c 100644 --- a/src/shell.c +++ b/src/shell.c @@ -1,30 +1,18 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. ** -** $Id: shell.c,v 1.32 2001/09/13 13:46:57 drh Exp $ +** $Id: shell.c,v 1.33 2001/09/16 00:13:27 drh Exp $ */ #include <stdlib.h> #include <string.h> diff --git a/src/sqlite.h.in b/src/sqlite.h.in index c22b9cb3c..d757cd45e 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -1,30 +1,18 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* -** This header file defines the interface that the sqlite library +** This header file defines the interface that the SQLite library ** presents to client programs. ** -** @(#) $Id: sqlite.h.in,v 1.16 2001/09/15 13:15:13 drh Exp $ +** @(#) $Id: sqlite.h.in,v 1.17 2001/09/16 00:13:27 drh Exp $ */ #ifndef _SQLITE_H_ #define _SQLITE_H_ @@ -109,9 +97,10 @@ typedef int (*sqlite_callback)(void*,int,char**, char**); ** to the callback function as its first parameter. ** ** The 2nd parameter to the callback function is the number of -** columns in the query result. The 3rd parameter is an array -** of string holding the values for each column. The 4th parameter -** is an array of strings holding the names of each column. +** columns in the query result. The 3rd parameter to the callback +** is an array of strings holding the values for each column. +** The 4th parameter to the callback is an array of strings holding +** the names of each column. ** ** The callback function may be NULL, even for queries. A NULL ** callback is not an error. It just means that no callback @@ -120,18 +109,18 @@ typedef int (*sqlite_callback)(void*,int,char**, char**); ** If an error occurs while parsing or evaluating the SQL (but ** not while executing the callback) then an appropriate error ** message is written into memory obtained from malloc() and -** *errmsg is made to point to that message. If errmsg==NULL, -** then no error message is ever written. The return value is -** SQLITE_ERROR if an error occurs. The calling function is -** responsible for freeing the memory that holds the error -** message. +** *errmsg is made to point to that message. The calling function +** is responsible for freeing the memory that holds the error +** message. If errmsg==NULL, then no error message is ever written. +** +** The return value is is SQLITE_OK if there are no errors and +** some other return code if there is an error. The particular +** return value depends on the type of error. ** ** If the query could not be executed because a database file is ** locked or busy, then this function returns SQLITE_BUSY. (This ** behavior can be modified somewhat using the sqlite_busy_handler() -** and sqlite_busy_timeout() functions below.) If the query could -** not be executed because a file is missing or has incorrect -** permissions, this function returns SQLITE_ERROR. +** and sqlite_busy_timeout() functions below.) */ int sqlite_exec( sqlite*, /* An open database */ @@ -153,7 +142,7 @@ int sqlite_exec( #define SQLITE_NOMEM 6 /* A malloc() failed */ #define SQLITE_READONLY 7 /* Attempt to write a readonly database */ #define SQLITE_INTERRUPT 8 /* Operation terminated by sqlite_interrupt() */ -#define SQLITE_IOERR 9 /* Disk full or other I/O error */ +#define SQLITE_IOERR 9 /* Some kind of disk I/O error occurred */ #define SQLITE_CORRUPT 10 /* The database disk image is malformed */ #define SQLITE_NOTFOUND 11 /* Table or record not found */ #define SQLITE_FULL 12 /* Insertion failed because database is full */ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index a22061aac..9ba03cb06 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1,29 +1,17 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.50 2001/09/15 14:43:39 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.51 2001/09/16 00:13:27 drh Exp $ */ #include "sqlite.h" #include "vdbe.h" diff --git a/src/table.c b/src/table.c index 8f61d6f2f..e27c71460 100644 --- a/src/table.c +++ b/src/table.c @@ -1,24 +1,12 @@ /* -** Copyright (c) 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains the sqlite_get_table() and sqlite_free_table() diff --git a/src/tclsqlite.c b/src/tclsqlite.c index ade3ddb61..9537a451c 100644 --- a/src/tclsqlite.c +++ b/src/tclsqlite.c @@ -1,29 +1,17 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** A TCL Interface to SQLite ** -** $Id: tclsqlite.c,v 1.22 2001/08/20 00:33:58 drh Exp $ +** $Id: tclsqlite.c,v 1.23 2001/09/16 00:13:27 drh Exp $ */ #ifndef NO_TCL /* Omit this whole file if TCL is unavailable */ diff --git a/src/test1.c b/src/test1.c index 64cf61cfc..09f1b8a79 100644 --- a/src/test1.c +++ b/src/test1.c @@ -1,31 +1,19 @@ /* -** Copyright (c) 2001 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing the printf() interface to SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test1.c,v 1.2 2001/04/11 14:28:43 drh Exp $ +** $Id: test1.c,v 1.3 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" #include "tcl.h" diff --git a/src/test2.c b/src/test2.c index 70e06eb97..e08c189e2 100644 --- a/src/test2.c +++ b/src/test2.c @@ -1,31 +1,19 @@ /* -** Copyright (c) 2001 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** 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.4 2001/08/20 00:33:58 drh Exp $ +** $Id: test2.c,v 1.5 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" #include "pager.h" diff --git a/src/test3.c b/src/test3.c index 42f44b357..9dd084105 100644 --- a/src/test3.c +++ b/src/test3.c @@ -1,31 +1,19 @@ /* -** Copyright (c) 2001 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** Code for testing the btree.c module in SQLite. This code ** is not included in the SQLite library. It is used for automated ** testing of the SQLite library. ** -** $Id: test3.c,v 1.10 2001/09/13 21:53:10 drh Exp $ +** $Id: test3.c,v 1.11 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" #include "pager.h" diff --git a/src/tokenize.c b/src/tokenize.c index 8b7e82aec..be9711321 100644 --- a/src/tokenize.c +++ b/src/tokenize.c @@ -1,24 +1,12 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** An tokenizer for SQL @@ -27,7 +15,7 @@ ** individual tokens and sends those tokens one-by-one over to the ** parser for analysis. ** -** $Id: tokenize.c,v 1.21 2001/09/14 18:54:09 drh Exp $ +** $Id: tokenize.c,v 1.22 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -305,7 +293,10 @@ int sqliteGetToken(const char *z, int *tokenType){ /* ** Run the parser on the given SQL string. The parser structure is -** passed in. An SQLITE_ status code. +** passed in. An SQLITE_ status code is returned. If an error occurs +** and pzErrMsg!=NULL then an error message might be written into +** memory obtained from malloc() and *pzErrMsg made to point to that +** error message. Or maybe not. */ int sqliteRunParser(Parse *pParse, char *zSql, char **pzErrMsg){ int nErr = 0; diff --git a/src/update.c b/src/update.c index d84aaa5b9..62c024118 100644 --- a/src/update.c +++ b/src/update.c @@ -1,30 +1,18 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** This file contains C code routines that are called by the parser ** to handle UPDATE statements. ** -** $Id: update.c,v 1.13 2001/09/15 00:57:29 drh Exp $ +** $Id: update.c,v 1.14 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" diff --git a/src/util.c b/src/util.c index 58103ba8d..e23561ee2 100644 --- a/src/util.c +++ b/src/util.c @@ -1,24 +1,12 @@ /* -** 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/ +** 2001 September 15 +** +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: +** +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** Utility functions used throughout sqlite. @@ -26,7 +14,7 @@ ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.24 2001/09/15 13:15:13 drh Exp $ +** $Id: util.c,v 1.25 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" #include <stdarg.h> diff --git a/src/vdbe.c b/src/vdbe.c index 6adf20e33..cbdae741b 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -1,24 +1,12 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** The code in this file implements the Virtual Database Engine (VDBE) @@ -33,15 +21,16 @@ ** ignore all three operands. ** ** Computation results are stored on a stack. Each entry on the -** stack is either an integer or a null-terminated string. An -** inplicit conversion from one type to the other occurs as necessary. +** stack is either an integer, a null-terminated string, a floating point +** number, or the SQL "NULL" value. An inplicit conversion from one +** type to the other occurs as necessary. ** ** Most of the code in this file is taken up by the sqliteVdbeExec() ** function which does the work of interpreting a VDBE program. ** But other routines are also provided to help in building up ** a program instruction by instruction. ** -** $Id: vdbe.c,v 1.69 2001/09/15 14:43:39 drh Exp $ +** $Id: vdbe.c,v 1.70 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -1121,8 +1110,12 @@ case OP_Goto: { /* Opcode: Halt * * * ** -** Exit immediately. All open DBs, Lists, Sorts, etc are closed +** Exit immediately. All open cursors, Lists, Sorts, etc are closed ** automatically. +** +** There is an implied Halt instruction inserted at the very end of +** every program. So a jump past the last instruction of the program +** is the same as executing Halt. */ case OP_Halt: { pc = p->nOp-1; @@ -1185,6 +1178,8 @@ case OP_Pop: { ** The top of the stack is element 0. So the ** instruction "Dup 0 0 0" will make a copy of the ** top of the stack. +** +** Also see the Pull instruction. */ case OP_Dup: { int i = p->tos - pOp->p1; @@ -1207,7 +1202,10 @@ case OP_Dup: { ** The P1-th element is removed from its current location on ** the stack and pushed back on top of the stack. The ** top of the stack is element 0, so "Pull 0 0 0" is -** a no-op. +** a no-op. "Pull 1 0 0" swaps the top two elements of +** the stack. +** +** See also the Dup instruction. */ case OP_Pull: { int from = p->tos - pOp->p1; @@ -1783,7 +1781,7 @@ case OP_NotNull: { ** which hold the offset of the beginning of each column data from the ** beginning of the completed record including the header. ** -** The OP_Column opcode is used to unpack a record manufactured with +** The Column opcode is used to unpack a record manufactured with ** the opcode. */ case OP_MakeRecord: { @@ -1836,10 +1834,9 @@ case OP_MakeRecord: { /* Opcode: MakeKey P1 P2 * ** ** Convert the top P1 entries of the stack into a single entry suitable -** for use as the key in an index or a sort. The top P1 records are -** converted to strings and merged. The null-terminator on each string -** is retained and used as a separator. The entire string is also -** null-terminated. +** for use as the key in an index. The top P1 records are +** converted to strings and merged. The null-terminators +** are retained and used as separators. ** The lowest entry in the stack is the first field and the top of the ** stack becomes the last. ** @@ -1956,8 +1953,12 @@ case OP_MakeIdxKey: { ** ** Begin a transaction. The transaction ends when a Commit or Rollback ** opcode is encountered or whenever there is an execution error that causes -** a script to abort. +** a script to abort. A transaction is not ended by a Halt. ** +** A write lock is obtained on the database file when a transaction is +** started. No other process can read or write the file while the +** transaction is underway. Starting a transaction also creates a +** rollback journal. ** A transaction must be started before any changes can be made to the ** database. */ @@ -1970,7 +1971,9 @@ case OP_Transaction: { ** ** Cause all modifications to the database that have been made since the ** last Transaction to actually take effect. No additional modifications -** are allowed until another transaction is started. +** are allowed until another transaction is started. The Commit instruction +** deletes the journal file and releases the write lock on the database. +** A read lock continues to be held if there are still cursors open. */ case OP_Commit: { rc = sqliteBtreeCommit(pBt); @@ -1988,6 +1991,9 @@ case OP_Commit: { ** last Transaction to be undone. The database is restored to its state ** before the Transaction opcode was executed. No additional modifications ** are allowed until another transaction is started. +** +** This instruction automatically closes all cursors and releases both +** the read and write locks on the database. */ case OP_Rollback: { rc = sqliteBtreeRollback(pBt); @@ -1997,15 +2003,15 @@ case OP_Rollback: { /* Opcode: ReadCookie * * * ** -** Read the magic cookie from the database file and push it onto the -** stack. The magic cookie is an integer that is used like a version +** Read the schema cookie from the database file and push it onto the +** stack. The schema cookie is an integer that is used like a version ** number for the database schema. Everytime the schema changes, the ** cookie changes to a new random value. This opcode is used during ** initialization to read the initial cookie value so that subsequent ** database accesses can verify that the cookie has not changed. ** ** There must be a read-lock on the database (either a transaction -** must be started or there must be a prior OP_Open opcode) before +** must be started or there must be an open cursor) before ** executing this instruction. */ case OP_ReadCookie: { @@ -2020,10 +2026,10 @@ case OP_ReadCookie: { /* Opcode: SetCookie P1 * * ** -** This operation changes the value of the cookie on the database. +** This operation changes the value of the schema cookie on the database. ** The new value is P1. ** -** The cookie changes its value whenever the database schema changes. +** The schema cookie changes its value whenever the database schema changes. ** That way, other processes can recognize when the schema has changed ** and reread it. ** @@ -2041,11 +2047,11 @@ case OP_SetCookie: { /* Opcode: VerifyCookie P1 * * ** -** Check the current value of the database cookie and make sure it is +** Check the current value of the schema cookie and make sure it is ** equal to P1. If it is not, abort with an SQLITE_SCHEMA error. ** ** The cookie changes its value whenever the database schema changes. -** This operation is used to detech when that the cookie has changed +** This operation is used to detect when that the cookie has changed ** and that the current process needs to reread the schema. ** ** Either a transaction needs to have been started or an OP_Open needs @@ -2071,6 +2077,15 @@ case OP_VerifyCookie: { ** ** If P2==0 then take the root page number from the top of the stack. ** +** There will be a read lock on the database whenever there is an +** open cursor. If the database was unlocked prior to this instruction +** then a read lock is acquired as part of this instruction. A read +** lock allows other processes to read the database but prohibits +** any other process from modifying the database. The read lock is +** released when all cursors are closed. If this instruction attempts +** to get a read lock but fails, the script terminates with an +** SQLITE_BUSY error code. +** ** The P3 value is the name of the table or index being opened. ** The P3 value is not actually used by this opcode and may be ** omitted. But the code generator usually inserts the index or @@ -2129,7 +2144,7 @@ case OP_Open: { /* Opcode: OpenTemp P1 * * ** ** Open a new cursor that points to a table in a temporary database -** file. The temporary file is opened read/write event if the main +** file. The temporary file is opened read/write even if the main ** database is read-only. The temporary file is deleted when the ** cursor is closed. */ @@ -2178,6 +2193,8 @@ case OP_Close: { ** cursor P1 so that it points to an entry with a matching key. If ** the table contains no record with a matching key, then the cursor ** is left pointing at a nearby record. +** +** See also: Found, NotFound, Distinct */ case OP_MoveTo: { int i = pOp->p1; @@ -2204,7 +2221,7 @@ case OP_MoveTo: { /* Opcode: Fcnt * * * ** ** Push an integer onto the stack which is the total number of -** OP_Fetch opcodes that have been executed by this virtual machine. +** MoveTo opcodes that have been executed by this virtual machine. ** ** This instruction is used to implement the special fcnt() function ** in the SQL dialect that SQLite understands. fcnt() is used for @@ -2220,30 +2237,36 @@ case OP_Fcnt: { /* Opcode: Distinct P1 P2 * ** -** Use the top of the stack as a key. If a record with that key -** does not exist in file P1, then jump to P2. If the record +** Use the top of the stack as a key. If a record with that key does +** not exist in the table of cursor P1, then jump to P2. If the record ** does already exist, then fall thru. The cursor is left pointing ** at the record if it exists. The key is not popped from the stack. ** ** This operation is similar to NotFound except that this operation ** does not pop the key from the stack. +** +** See also: Found, NotFound, MoveTo */ /* Opcode: Found P1 P2 * ** ** Use the top of the stack as a key. If a record with that key -** does exist in file P1, then jump to P2. If the record +** does exist in table of P1, then jump to P2. If the record ** does not exist, then fall thru. The cursor is left pointing ** to the record if it exists. The key is popped from the stack. +** +** See also: Distinct, NotFound, MoveTo */ /* Opcode: NotFound P1 P2 * ** ** Use the top of the stack as a key. If a record with that key -** does not exist in file P1, then jump to P2. If the record +** does not exist in table of P1, then jump to P2. If the record ** does exist, then fall thru. The cursor is left pointing to the ** record if it exists. The key is popped from the stack. ** ** The difference between this operation and Distinct is that ** Distinct does not pop the key from the stack. +** +** See also: Distinct, Found, MoveTo */ case OP_Distinct: case OP_NotFound: @@ -2278,8 +2301,8 @@ case OP_Found: { /* Opcode: NewRecno P1 * * ** ** Get a new integer record number used as the key to a table. -** The record number is not previous used by the database file -** associated with cursor P1. The new record number pushed +** The record number is not previously used as a key in the database +** table that cursor P1 points to. The new record number pushed ** onto the stack. */ case OP_NewRecno: { @@ -2321,7 +2344,7 @@ case OP_NewRecno: { /* Opcode: Put P1 * * ** ** Write an entry into the database file P1. A new entry is -** created if it doesn't already exist, or the data for an existing +** created if it doesn't already exist or the data for an existing ** entry is overwritten. The data is the value on the top of the ** stack. The key is the next value down on the stack. The stack ** is popped twice by this instruction. @@ -2356,8 +2379,8 @@ case OP_Put: { ** ** The cursor will be left pointing at either the next or the previous ** record in the table. If it is left pointing at the next record, then -** the next OP_Next will be a no-op. Hence it is OK to delete a record -** from within an OP_Next loop. +** the next Next instruction will be a no-op. Hence it is OK to delete +** a record from within an Next loop. */ case OP_Delete: { int i = pOp->p1; @@ -2370,7 +2393,7 @@ case OP_Delete: { /* Opcode: KeyAsData P1 P2 * ** ** Turn the key-as-data mode for cursor P1 either on (if P2==1) or -** off (if P2==0). In key-as-data mode, the OP_Field opcode pulls +** off (if P2==0). In key-as-data mode, the Field opcode pulls ** data off of the key rather than the data. This is useful for ** processing compound selects. */ @@ -2507,9 +2530,12 @@ case OP_Recno: { /* Opcode: FullKey P1 * * ** -** Push a string onto the stack which is the full text key associated -** with the last Next operation on file P1. Compare this with the -** Key operator which pushs an integer key. +** Extract the complete key from the record that cursor P1 is currently +** pointing to and push the key onto the stack as a string. +** +** Compare this opcode to Recno. The Recno opcode extracts the first +** 4 bytes of the key and pushes those bytes onto the stack as an +** integer. This instruction pushes the entire key as a string. */ case OP_FullKey: { int i = pOp->p1; @@ -2622,9 +2648,9 @@ case OP_BeginIdx: { ** ** The P1 cursor points to an SQL index for which a BeginIdx operation ** has been issued. This operation retrieves the next record from that -** cursor and verifies that the key on the record matches the key that -** was pulled from the stack by the BeginIdx instruction. If they do -** match, then the last 4 bytes of the key on the record hold a record +** cursor and verifies that the key on the record minus the last 4 bytes +** matches the key that was pulled from the stack by the BeginIdx instruction. +** If they match, then the last 4 bytes of the key on the record hold a record ** number and that record number is extracted and pushed on the stack. ** If the keys do not match, there is an immediate jump to instruction P2. */ @@ -2707,6 +2733,8 @@ case OP_DeleteIdx: { ** ** Delete an entire database table or index whose root page in the database ** file is given by P1. +** +** See also: Clear */ case OP_Destroy: { sqliteBtreeDropTable(pBt, pOp->p1); @@ -2716,8 +2744,10 @@ case OP_Destroy: { /* Opcode: Clear P1 * * ** ** Delete all contents of the database table or index whose root page -** in the database file is given by P1. But, unlike OP_Destroy, do not +** in the database file is given by P1. But, unlike Destroy, do not ** remove the table or index from the database file. +** +** See also: Destroy */ case OP_Clear: { sqliteBtreeClearTable(pBt, pOp->p1); @@ -2735,6 +2765,8 @@ case OP_Clear: { ** memory location. This writing of the page number into a memory location ** is used by the SQL parser to record the page number in its internal ** data structures. +** +** See also: CreateIndex */ case OP_CreateTable: { int i = ++p->tos; @@ -2754,19 +2786,19 @@ case OP_CreateTable: { break; } -/* Opcode: CreateIndex * * * +/* Opcode: CreateIndex P1 * * ** ** Allocate a new Index in the main database file. Push the page number ** for the root page of the new table onto the stack. ** -** If P1>=0 then open a cursor named P1 on the newly created index. -** ** The root page number is also written to a memory location which has ** be set up by the parser. The difference between CreateTable and ** CreateIndex is that each writes its root page number into a different ** memory location. This writing of the page number into a memory location ** is used by the SQL parser to record the page number in its internal ** data structures. +** +** See also: CreateTable */ case OP_CreateIndex: { int i = ++p->tos; @@ -2790,6 +2822,8 @@ case OP_CreateIndex: { ** ** Compress, optimize, and tidy up table or index whose root page in the ** database file is P1. +** +** In the current implementation, this is a no-op. */ case OP_Reorganize: { /* This is currently a no-op */ @@ -2799,8 +2833,7 @@ case OP_Reorganize: { /* Opcode: ListOpen P1 * * ** ** Open a "List" structure used for temporary storage of integer -** table keys. P1 -** will server as a handle to this list for future +** record numbers. P1 will server as a handle to this list for future ** interactions. If another list with the P1 handle is ** already opened, the prior list is closed and a new one opened ** in its place. @@ -3004,7 +3037,7 @@ case OP_SortMakeRec: { ** in the result. The whole key is terminated by two \000 characters ** in a row. ** -** See also the MakeKey opcode. +** See also the MakeKey and MakeIdxKey opcodes. */ case OP_SortMakeKey: { char *zNewKey; @@ -3217,7 +3250,7 @@ case OP_FileClose: { ** a delimiter. There should be P1 fields. If the input line contains ** more than P1 fields, ignore the excess. If the input line contains ** fewer than P1 fields, assume the remaining fields contain an -** empty string. +** empty strings. */ case OP_FileRead: { int n, eol, nField, i, c, nDelim; @@ -3301,7 +3334,7 @@ fileread_jump: /* Opcode: FileColumn P1 * * ** -** Push onto the stack the P1-th field of the most recently read line +** Push onto the stack the P1-th column of the most recently read line ** from the input file. */ case OP_FileColumn: { diff --git a/src/vdbe.h b/src/vdbe.h index 46ebf9955..b5634982a 100644 --- a/src/vdbe.h +++ b/src/vdbe.h @@ -1,24 +1,12 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** Header file for the Virtual DataBase Engine (VDBE) @@ -27,7 +15,7 @@ ** or VDBE. The VDBE implements an abstract machine that runs a ** simple program to access and modify the underlying database. ** -** $Id: vdbe.h,v 1.22 2001/09/15 00:57:29 drh Exp $ +** $Id: vdbe.h,v 1.23 2001/09/16 00:13:27 drh Exp $ */ #ifndef _SQLITE_VDBE_H_ #define _SQLITE_VDBE_H_ diff --git a/src/where.c b/src/where.c index bc99942d6..d03be7eb8 100644 --- a/src/where.c +++ b/src/where.c @@ -1,31 +1,19 @@ /* -** Copyright (c) 1999, 2000 D. Richard Hipp +** 2001 September 15 ** -** 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. +** The author disclaims copyright to this source code. In place of +** a legal notice, here is a blessing: ** -** 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/ +** May you do good and not evil. +** May you find forgiveness for yourself and forgive others. +** May you share freely, never taking more than you give. ** ************************************************************************* ** This module contains C code that generates VDBE code used to process ** the WHERE clause of SQL statements. Also found here are subroutines ** to generate VDBE code to evaluate expressions. ** -** $Id: where.c,v 1.19 2001/09/15 00:57:29 drh Exp $ +** $Id: where.c,v 1.20 2001/09/16 00:13:27 drh Exp $ */ #include "sqliteInt.h" |