]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Bug fix: sqlite_exec() would sometimes return SQLITE_PROTOCOL when it
authordrh <drh@noemail.net>
Wed, 5 Dec 2001 00:21:20 +0000 (00:21 +0000)
committerdrh <drh@noemail.net>
Wed, 5 Dec 2001 00:21:20 +0000 (00:21 +0000)
should have returned SQLITE_BUSY.  There was also a deadlock that the
previous bug was masking. (CVS 322)

FossilOrigin-Name: 585ed5ebf1c1afc8ae1d569b121208018d8ecd49

manifest
manifest.uuid
src/btree.c
src/build.c
src/main.c
src/os.h
src/pager.c
src/sqliteInt.h
www/changes.tcl
www/faq.tcl

index d44364993041005b5071682787f4a2f995e71c7d..0fd974b91c4a375c4edb747cdb698a0be50c5f6c 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Add\sthe\sability\sto\sdo\sa\ssingle\s.command\sas\sthe\ssecond\sargument\nto\sthe\scommand-line\sshell.\s(CVS\s321)
-D 2001-11-25T13:18:24
+C Bug\sfix:\ssqlite_exec()\swould\ssometimes\sreturn\sSQLITE_PROTOCOL\swhen\sit\nshould\shave\sreturned\sSQLITE_BUSY.\s\sThere\swas\salso\sa\sdeadlock\sthat\sthe\nprevious\sbug\swas\smasking.\s(CVS\s322)
+D 2001-12-05T00:21:20
 F Makefile.in 352fed589f09dd94347e0bb391d047118ebd6105
 F Makefile.template b6c3d3ba089e97e3a721e967f3151350f36cb42b
 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
@@ -19,19 +19,19 @@ F libtool c56e618713c9510a103bda6b95f3ea3900dcacd6
 F ltmain.sh e9ed72eb1d690f447c13945eaf69e28af531eda1
 F publish.sh 33cbe6798969f637698044023c139080e5d772a6
 F src/TODO af7f3cab0228e34149cf98e073aa83d45878e7e6
-F src/btree.c d40fa46c8c578f1d166f4ea70d7a9d365399e0f3
+F src/btree.c 5fbfeb383465ca311ac202cbf6ba8f18196426de
 F src/btree.h 0250a0a577a98cc64ddf1582d50c08b8d2451650
-F src/build.c 2e21d425328e7c8bd6ade235e9eef51bf6fa870f
+F src/build.c 83733f96255db003363e786d1b28a5b85611acca
 F src/delete.c 5d93a21c1388cfb1359bda01c072f25583a2f4f2
 F src/expr.c 6b25c5bb1e750af2e2217c0134a7aa1fc0b11444
 F src/hash.c 6f1a7712ae3aac8351662969aec5693740a2fbf7
 F src/hash.h a5f5b3ce2d086a172c5879b0b06a27a82eac9fac
 F src/insert.c 3526be771a01035198bef28d8f370cbcab94f46d
-F src/main.c 799bdaf30cb33409b04a282aac53a9616d707c0d
+F src/main.c e5fa4773e6684b81fc0bcd9d9ae4578d56660c0c
 F src/md5.c 52f677bfc590e09f71d07d7e327bd59da738d07c
 F src/os.c d7dc681438f311cf8211a78d8d87a7cbdccc2f14
-F src/os.h bed702c9e3b768bc3cb1b12c90b83d099c1546be
-F src/pager.c fd9fc86686319a11cb0eebe5ebb4a250e45e7984
+F src/os.h c5c12f5f25b0a1baf9a62937b456fabcad2c1f49
+F src/pager.c 16173a7b7aff0c7bd7da94070e46d38778ab0f76
 F src/pager.h df1fb8a759ab69112ea88b9f14601a7633d0ccc0
 F src/parse.y 5295f393f41ea89958287e5738e6c12c7cd67482
 F src/printf.c 300a90554345751f26e1fc0c0333b90a66110a1d
@@ -40,7 +40,7 @@ F src/select.c fa1c7144a9ad7ce3f16373b443bc25e764af4be7
 F src/shell.c 407095aaeeae78f42deb3e846b1ad77f8ed3b4ef
 F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
 F src/sqlite.h.in 934de9112747ad8d8e7d5fec44876246b24ca5a3
-F src/sqliteInt.h 1d812fd1eed0008d31f7e31293f058bb6dbe3f09
+F src/sqliteInt.h 3990eeee362d1fb48dff841b56b7fe39577ea590
 F src/table.c c89698bd5bb4b8d14722d6ee7e9be014c383d24a
 F src/tclsqlite.c b82e4faeae89fdb7304b3c970979ade299336a1f
 F src/test1.c 41eabe255970ef947263b94145c9b2766bab8675
@@ -104,11 +104,11 @@ F www/arch.fig d5f9752a4dbf242e9cfffffd3f5762b6c63b3bcf
 F www/arch.png 82ef36db1143828a7abc88b1e308a5f55d4336f4
 F www/arch.tcl 72a0c80e9054cc7025a50928d28d9c75c02c2b8b
 F www/c_interface.tcl 58922228e8fdb0f6af3561a051ee8ccec6dbfd17
-F www/changes.tcl 6aa1912a7da010dee96b904bbf74694eb4d4445c
+F www/changes.tcl 9e0fc062862a3f99081b5a42ff91567c92b4bd64
 F www/crosscompile.tcl 3622ebbe518927a3854a12de51344673eb2dd060
 F www/download.tcl 1ea61f9d89a2a5a9b2cee36b0d5cf97321bdefe0
 F www/dynload.tcl 02eb8273aa78cfa9070dd4501dca937fb22b466c
-F www/faq.tcl f1fd488bef706934f6e13cc56bc642ae09c72515
+F www/faq.tcl 3c26fb2f2acfc9254f2685e23a34acae2490b44f
 F www/index.tcl 6d6d847dd3e39e9aa7b0c9b8f3144819ff3f9f51
 F www/lang.tcl 6482d90e40fb5ee004a86cf98f3007312a75444e
 F www/mingw.tcl f1c7c0a7f53387dd9bb4f8c7e8571b7561510ebc
@@ -117,7 +117,7 @@ F www/speed.tcl 83457b2bf6bb430900bd48ca3dd98264d9a916a5
 F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
 F www/tclsqlite.tcl 880ef67cb4f2797b95bf1368fc4e0d8ca0fda956
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 3be8a189e8ccf8a82acc4ee72cc75b6cc92aa193
-R bef40867b94c97a0a18ccef8081a3db9
+P 653f37c365a0b5d59c11b7dbba57905ffaeff2dc
+R 63aae37ccfcafcca670cad8f7e9ab9ed
 U drh
-Z c7c502054afc4f55970b082ddb69834b
+Z 57898bef4e7a90862dc49491082c0c29
index 70e8b599b157d0c1210622798d66880e67ec634f..15882d5bcd009e4b41acd30d161062d2823654f1 100644 (file)
@@ -1 +1 @@
-653f37c365a0b5d59c11b7dbba57905ffaeff2dc
\ No newline at end of file
+585ed5ebf1c1afc8ae1d569b121208018d8ecd49
\ No newline at end of file
index 574627d7a5d6b91f545a92bf5959af1f1e153fa1..00f898202fc738667ecb44d909f5966156f77b07 100644 (file)
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree.c,v 1.41 2001/11/23 00:24:12 drh Exp $
+** $Id: btree.c,v 1.42 2001/12/05 00:21:20 drh Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** For a detailed discussion of BTrees, refer to
@@ -676,6 +676,24 @@ page1_init_failed:
   return rc;
 }
 
+/*
+** If there are no outstanding cursors and we are not in the middle
+** of a transaction but there is a read lock on the database, then
+** this routine unrefs the first page of the database file which 
+** has the effect of releasing the read lock.
+**
+** If there are any outstanding cursors, this routine is a no-op.
+**
+** If there is a transaction in progress, this routine is a no-op.
+*/
+static void unlockBtreeIfUnused(Btree *pBt){
+  if( pBt->inTrans==0 && pBt->pCursor==0 && pBt->page1!=0 ){
+    sqlitepager_unref(pBt->page1);
+    pBt->page1 = 0;
+    pBt->inTrans = 0;
+  }
+}
+
 /*
 ** Create a new database by initializing the first two pages of the
 ** file.
@@ -725,33 +743,19 @@ int sqliteBtreeBeginTrans(Btree *pBt){
       return rc;
     }
   }
-  if( !sqlitepager_isreadonly(pBt->pPager) ){
-    rc = sqlitepager_write(pBt->page1);
-    if( rc!=SQLITE_OK ){
-      return rc;
-    }
+  if( sqlitepager_isreadonly(pBt->pPager) ){
+    return SQLITE_READONLY;
+  }
+  rc = sqlitepager_write(pBt->page1);
+  if( rc==SQLITE_OK ){
     rc = newDatabase(pBt);
   }
-  pBt->inTrans = 1;
-  return rc;
-}
-
-/*
-** If there are no outstanding cursors and we are not in the middle
-** of a transaction but there is a read lock on the database, then
-** this routine unrefs the first page of the database file which 
-** has the effect of releasing the read lock.
-**
-** If there are any outstanding cursors, this routine is a no-op.
-**
-** If there is a transaction in progress, this routine is a no-op.
-*/
-static void unlockBtreeIfUnused(Btree *pBt){
-  if( pBt->inTrans==0 && pBt->pCursor==0 && pBt->page1!=0 ){
-    sqlitepager_unref(pBt->page1);
-    pBt->page1 = 0;
-    pBt->inTrans = 0;
+  if( rc==SQLITE_OK ){
+    pBt->inTrans = 1;
+  }else{
+    unlockBtreeIfUnused(pBt);
   }
+  return rc;
 }
 
 /*
index 625be67a241d265999018d16c8d12911e0962364..006f4593e09428fcdf79e9dc8587ea5f301c53f0 100644 (file)
@@ -25,7 +25,7 @@
 **     ROLLBACK
 **     PRAGMA
 **
-** $Id: build.c,v 1.57 2001/11/22 00:01:27 drh Exp $
+** $Id: build.c,v 1.58 2001/12/05 00:21:20 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -553,7 +553,7 @@ void sqliteAddDefaultValue(Parse *pParse, Token *pVal, int minusFlag){
 */
 static void changeCookie(sqlite *db){
   if( db->next_cookie==db->schema_cookie ){
-    db->next_cookie = db->schema_cookie + sqliteRandomByte(db) + 1;
+    db->next_cookie = db->schema_cookie + sqliteRandomByte() + 1;
     db->flags |= SQLITE_InternChanges;
   }
 }
index a9beba9c3f7b24c91f7fc843623fd3d3d3fcb78d..d59c612af96ef4b0790055a875adc1c148183619 100644 (file)
@@ -14,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.50 2001/11/23 00:24:12 drh Exp $
+** $Id: main.c,v 1.51 2001/12/05 00:21:20 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -265,7 +265,7 @@ sqlite *sqlite_open(const char *zFilename, int mode, char **pzErrMsg){
   if( db==0 ) goto no_mem_on_open;
   sqliteHashInit(&db->tblHash, SQLITE_HASH_STRING, 0);
   sqliteHashInit(&db->idxHash, SQLITE_HASH_STRING, 0);
-  db->nextRowid = sqliteRandomInteger(db);
+  db->nextRowid = sqliteRandomInteger();
   
   /* Open the backend database driver */
   rc = sqliteBtreeOpen(zFilename, mode, MAX_PAGES, &db->pBe);
index 31edc769ab2dc00325c1cadf0aadc634e015879e..f90b52589052a67822116581a0ce2a36278ba324 100644 (file)
--- a/src/os.h
+++ b/src/os.h
@@ -59,8 +59,8 @@ int sqliteOsLock(OsFile, int wrlock);
 int sqliteOsUnlock(OsFile);
 int sqliteOsRandomSeed(char*);
 int sqliteOsSleep(int ms);
-void sqliteOsEnterMutex();
-void sqliteOsLeaveMutex();
+void sqliteOsEnterMutex(void);
+void sqliteOsLeaveMutex(void);
 
 
 
index a620a3a3309faf0c291d1baa4cfe784899a616bc..378a9e41dcc0b3a0915dd22a11589d8e2f3dd7b2 100644 (file)
@@ -18,7 +18,7 @@
 ** file simultaneously, or one process from reading the database while
 ** another is writing.
 **
-** @(#) $Id: pager.c,v 1.31 2001/11/22 00:01:27 drh Exp $
+** @(#) $Id: pager.c,v 1.32 2001/12/05 00:21:20 drh Exp $
 */
 #include "sqliteInt.h"
 #include "pager.h"
@@ -955,13 +955,20 @@ int sqlitepager_write(void *pData){
     }
     sqliteOsUnlock(pPager->fd);
     if( sqliteOsLock(pPager->fd, 1)!=SQLITE_OK ){
+      sqliteOsUnlock(pPager->fd);
+      rc = sqliteOsLock(pPager->fd, 0);
       sqliteFree(pPager->aInJournal);
       sqliteOsClose(pPager->jfd);
       sqliteOsDelete(pPager->zJournal);
       pPager->journalOpen = 0;
-      pPager->state = SQLITE_UNLOCK;
-      pPager->errMask |= PAGER_ERR_LOCK;
-      return SQLITE_PROTOCOL;
+      if( rc ){
+        pPager->state = SQLITE_UNLOCK;
+        pPager->errMask |= PAGER_ERR_LOCK;
+        return SQLITE_PROTOCOL;
+      }else{
+        pPager->state = SQLITE_READLOCK;
+        return SQLITE_BUSY;
+      }
     }
     pPager->state = SQLITE_WRITELOCK;
     sqlitepager_pagecount(pPager);
index b80eac96a4f590c50d8548500a2d3f44d1eb7a35..03e0504d92d191fb59694cb8ec334b4cea1ccf75 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** Internal interface definitions for SQLite.
 **
-** @(#) $Id: sqliteInt.h,v 1.71 2001/11/22 00:01:27 drh Exp $
+** @(#) $Id: sqliteInt.h,v 1.72 2001/12/05 00:21:20 drh Exp $
 */
 #include "sqlite.h"
 #include "hash.h"
@@ -519,8 +519,8 @@ void sqliteExprResolveInSelect(Parse*, Expr*);
 int sqliteExprAnalyzeAggregates(Parse*, Expr*);
 void sqliteParseInfoReset(Parse*);
 Vdbe *sqliteGetVdbe(Parse*);
-int sqliteRandomByte();
-int sqliteRandomInteger();
+int sqliteRandomByte(void);
+int sqliteRandomInteger(void);
 void sqliteBeginTransaction(Parse*);
 void sqliteCommitTransaction(Parse*);
 void sqliteRollbackTransaction(Parse*);
index ff464d4f42e6b7695f249dd316ba19b2296dda9f..44170b081e2bcd06322ab1225e60de02efe4f097 100644 (file)
@@ -17,9 +17,14 @@ proc chng {date desc} {
   puts "<DD><P><UL>$desc</UL></P></DD>"
 }
 
-chng {2001 Nov ?? (2.1.4)} {
+chng {2001 Dec 4 (2.1.4)} {
+<li>Sometime <b>sqlite_exec()</b> would return SQLITE_PROTOCOL when it
+    should have returned SQLITE_BUSY.</li>
+<li>The fix to the previous bug uncovered a deadlock which was also
+    fixed.</li>
 <li>Add the ability to put a single .command in the second argument
     of the sqlite shell</li>
+<li>Updates to the FAQ</li>
 }
 
 chng {2001 Nov 23 (2.1.3)} {
index 1e1e650ec376710ef2ad24bb4c9778a2138f46a0..20cc8ff4879aa6f848e346df8c133813729feec1 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Run this script to generated a faq.html output file
 #
-set rcsid {$Id: faq.tcl,v 1.2 2001/11/24 13:23:05 drh Exp $}
+set rcsid {$Id: faq.tcl,v 1.3 2001/12/05 00:21:21 drh Exp $}
 
 puts {<html>
 <head>
@@ -93,14 +93,13 @@ faq {
 }
 
 faq {
-  The second INSERT in the following sequence of commands returns with 
-  constraint error.
+  Why does the second INSERT in the following sequence of commands throw
+  a constraint exception?
   <blockquote>
      CREATE TABLE t(s varchar(10) primary key);<br>
      INSERT INTO t VALUES('0');<br>
      INSERT INTO t VALUES('0.0');<br>
   </blockquote>
-  Why is this?
 } {
   <p>Because column <b>s</b> is a primary key, all values of <b>s</b> must
   be unique.  But SQLite thinks that <b>'0'</b> and <b>'0.0'</b> are the
@@ -124,7 +123,7 @@ faq {
   My linux box is not able to read an SQLite database that was created
   on my SparcStation.
 } {
-  <p>The x86 processor on your windows box is little-endian (meaning that
+  <p>The x86 processor on your linux box is little-endian (meaning that
   the least signification byte of integers comes first) but the Sparc is
   big-endian (the most significant bytes comes first).  SQLite databases
   created on a little-endian architecture cannot be used on a big-endian
@@ -234,6 +233,30 @@ ORDER BY name;
   there is no way to get a listing of temporary tables and indices.</p>
 }
 
+faq {
+  Is there any known size limits to SQLite databases.
+} {
+  <p>Internally, SQLite can handle databases up to 2^40 bytes (1 terabyte)
+  in size.  But the backend interface to POSIX and Win32 limits files to
+  2^31 (2 gigabytes).</p>
+
+  <p>SQLite arbitrarily limits the amount of data in one row to 1 megabyte.
+  There is a single #define in the source code that can be changed to raise
+  this limit as high as 16 megabytes if desired.</p>
+
+  <p>There is a theoretical limit of about 2^32 (4 billion) rows
+  in a single table, but there
+  is no way to test this limit without exceeding the maximum file size, so
+  it is not really an issue.  There is also a theoretical limit of about 2^32
+  tables and indices, but again it is not really possible to reach this
+  limit due to the file size constraint.</p>
+
+  <p>The name and "CREATE TABLE" statement for a table must fit entirely
+  within a 1-megabyte row of the SQLITE_MASTER table.  Other than this,
+  there are no constraints on the length of the name of a table, or on the
+  number of columns, etc.  Indices are similarly unconstrained.</p>
+}
+
 # End of questions and answers.
 #############
 
@@ -242,15 +265,16 @@ for {set i 1} {$i<$cnt} {incr i} {
   puts "  <DT><A HREF=\"#q$i\">($i)</A></DT>"
   puts "  <DD>[lindex $faq($i) 0]</DD>"
 }
-puts {</DL><HR />}
+puts {</DL>}
 
 for {set i 1} {$i<$cnt} {incr i} {
-  puts "<A NAME=\"q$i\">"
+  puts "<A NAME=\"q$i\"><HR />"
   puts "<P><B>($i) [lindex $faq($i) 0]</B></P>\n"
-  puts "<BLOCKQUOTE>[lindex $faq($i) 1]</BLOCKQUOTE>\n"
+  puts "<BLOCKQUOTE>[lindex $faq($i) 1]</BLOCKQUOTE></LI>\n"
 }
 
 puts {
+</OL>
 <p><hr /></p>
 <p><a href="index.html"><img src="/goback.jpg" border=0 />
 Back to the SQLite Home Page</a>