]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Changes to lemon to generate additional comments in the output file and
authordrh <drh@noemail.net>
Tue, 22 Jan 2008 01:48:05 +0000 (01:48 +0000)
committerdrh <drh@noemail.net>
Tue, 22 Jan 2008 01:48:05 +0000 (01:48 +0000)
to remove unreachable code.  Additional test cases for improved test
coverage. (CVS 4736)

FossilOrigin-Name: 2a0bc1e186532a0bfe36ca18fda74a5e7a199227

16 files changed:
manifest
manifest.uuid
src/build.c
src/parse.y
src/pragma.c
src/prepare.c
src/vdbeaux.c
src/vdbemem.c
test/capi3.test
test/enc3.test
test/expr.test
test/mallocF.test
test/mallocG.test [new file with mode: 0644]
test/sqllimits1.test
tool/lemon.c
tool/lempar.c

index 7743fe5e19908f307ef6071cef2d78ab8f14ab53..474bc51a7ee99354369c1129edc3819ffdddb405 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Additional\stest\scases\sfor\sthe\sRTRIM\scollation.\s(CVS\s4735)
-D 2008-01-21T16:47:16
+C Changes\sto\slemon\sto\sgenerate\sadditional\scomments\sin\sthe\soutput\sfile\sand\nto\sremove\sunreachable\scode.\s\sAdditional\stest\scases\sfor\simproved\stest\ncoverage.\s(CVS\s4736)
+D 2008-01-22T01:48:06
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in 30789bf70614bad659351660d76b8e533f3340e9
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -86,7 +86,7 @@ F src/btmutex.c 5d39da37c9d1282f3c6f9967afae6a34ee36b7ff
 F src/btree.c a3125bd53a4112f2f259af858ef2eff63e397c9b
 F src/btree.h 19dcf5ad23c17b98855da548e9a8e3eb4429d5eb
 F src/btreeInt.h 1c5a9da165718ef7de81e35ce9ab5d9ba9283f76
-F src/build.c deb031f71a1797de99db01ec2ffbd060722ce0c6
+F src/build.c b228a333d7de41e80c1f7cd442483e59e97543e1
 F src/callback.c 77b302b0d41468dcda78c70e706e5b84577f0fa0
 F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131
 F src/date.c 8ce763c68143b1e8fb6f79dcfc8b801853c97017
@@ -126,9 +126,9 @@ F src/os_win.c c832d528ea774c7094d887749d71884984c9034c
 F src/os_win.h 41a946bea10f61c158ce8645e7646b29d44f122b
 F src/pager.c fae75270b4e2b2542b905791087f0c52142974f8
 F src/pager.h f504f7ae84060fee0416a853e368d3d113c3d6fa
-F src/parse.y 2ae06e8d3190faace49c5b82e7cea1fc60d084a1
-F src/pragma.c 155315ee3e6a861a0060ba4d184dfffd08ebbc03
-F src/prepare.c c31a879d6795f4765fd0b113675c6debbc96b7fd
+F src/parse.y 0a0878dd99b12056799802a97b6a529f4b37c15f
+F src/pragma.c 2bb8d6882b9a330e041acd05fb6aff5a01bf0a08
+F src/prepare.c 505afbfebcca809f655e04725832bfbfdf1ce697
 F src/printf.c eb27822ba2eec669161409ca31279a24c26ac910
 F src/random.c 02ef38b469237482f1ea14a78b2087cfbaec48bd
 F src/select.c 9fb094cc0c8acdcbf3581fdfc4490e997b5d1d1e
@@ -172,10 +172,10 @@ F src/vdbe.c e7ec3089f1e2ee5ab47b66d2be940f4e8b0029a7
 F src/vdbe.h 58a7d931ffb704e034b2a725981cfa5bd406fad9
 F src/vdbeInt.h 835e6f0337ce89d705ef9a162338788808adc4b7
 F src/vdbeapi.c cb8c427a3ab646490c83204a98e94eff03ee2e89
-F src/vdbeaux.c e73c4ca5c8a66abfb06b5b543afe2819b55e35bf
+F src/vdbeaux.c 4a0c75af5366c9114b340c39bea5df76fb26e215
 F src/vdbeblob.c e386d49d8354aa5a58f0a7f2794303442c149120
 F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6
-F src/vdbemem.c e15122efe8868e400c2aba8ea101588944e83317
+F src/vdbemem.c bb8d4f70e387bd7ff7f4ee349e9f6a9c77cd67c3
 F src/vtab.c 9924e37cf7f5c527aeabb5da025874af505fb91d
 F src/where.c 0c18a6d88d78886fd5f3c11ef2cf001321acd918
 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
@@ -219,7 +219,7 @@ F test/btree9.test 5d8711b241145b90f65dd1795d5dd8290846fa5e
 F test/busy.test 0271c854738e23ad76e10d4096a698e5af29d211
 F test/cache.test 3ff445c445742a7b6b9ba6e1d62a25263f9424b9
 F test/capi2.test cc64df7560a96f848f919ea2926c60acf639684b
-F test/capi3.test 432fabf9c6402ed8ff1ae291e01f0e04b64df3ea
+F test/capi3.test 27734b8b96e3d31acbdb861cff409a82d3499ae4
 F test/capi3b.test 664eb55318132f292f2c436f90906f578cad6b97
 F test/capi3c.test 7bcff27698351b6fbe45be5ebae95c1d2a1f4b1a
 F test/cast.test ce8f14fc80f70b30ed984480cc0d8914a459e8f9
@@ -259,12 +259,12 @@ F test/diskfull.test 34ef53e88372c5b5e488ad1581514559a224c2b1
 F test/distinctagg.test 2b89d1c5220d966a30ba4b40430338669301188b
 F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
 F test/enc2.test 6d91a5286f59add0cfcbb2d0da913b76f2242398
-F test/enc3.test adb01b50ca1084658437eb68987969e8fa409276
+F test/enc3.test 5c550d59ff31dccdba5d1a02ae11c7047d77c041
 F test/exclusive.test ebaf72ce9ff8f7ab3a09bf8f58fd65393dfff386
 F test/exclusive2.test d13bf66753dca46e61241d35d36ab7c868b0d313
 F test/exclusive3.test 0e49c35b7e7cb8e7280b4ce3f0359d30b207d2ff
 F test/exec.test e949714dc127eaa5ecc7d723efec1ec27118fdd7
-F test/expr.test 6e666e5f47fbe6c23295d8c9f2b6c28109bf9ba8
+F test/expr.test 5c606f12045dd640ede7f840270340baf5ef1450
 F test/filefmt.test 053b622009fbbb74dd37921ffad374d852c13cd8
 F test/fkey1.test dcb4f28eb22d5141f15161d6bdca9a4f58c95729
 F test/format4.test 1f0cac8ff3895e9359ed87e41aaabee982a812eb
@@ -378,7 +378,8 @@ F test/mallocB.test 82ecf4d3fa6c389cabc747daa2deddfe94af2a74
 F test/mallocC.test 9daac0aa8e5b0afa7b0a3fb0cd792f02fe0cc838
 F test/mallocD.test d638fb8f214b47fd31edfae8af738b92bd943dc0
 F test/mallocE.test e15333c394d7c330c8372a7cdf7b0f7c16573082
-F test/mallocF.test e1804792a6365ad43589b26608850a38e491170a
+F test/mallocF.test 6f25bc474f2b29954e5fac274d0e6ed9d86efea5
+F test/mallocG.test ac896f96098a30ed0dcc001b6f9243770a463081
 F test/malloc_common.tcl 262c71dd4af005bc3a6b8fe449237688255072a0
 F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
 F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
@@ -439,7 +440,7 @@ F test/speed1.test 22e1b27af0683ed44dcd2f93ed817a9c3e65084a
 F test/speed2.test 53177056baf6556dcbdcf032bbdfc41c1aa74ded
 F test/speed3.test e312d7e442a5047d730569fdae2ba99bc94e1a13
 F test/speed4.test 20d8ea20bea3ca09c3ef3b5ec820a17e58e132cb
-F test/sqllimits1.test 81827ef286ff0d156cad84fb192590d69337c393
+F test/sqllimits1.test f861e6179aa985d8ee168233a65d745f7aaca2e4
 F test/subquery.test 8203f85db56ba022a57a0589890090c8feed4e59
 F test/subselect.test 974e87f8fc91c5f00dd565316d396a5a6c3106c4
 F test/substr.test 4be572ac017143e59b4058dc75c91a0d0dc6d4e0
@@ -532,8 +533,8 @@ F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2
 F test/zeroblob.test 7d1854ea79d048e023e5f2e38106a7e99a17435c
 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
 F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439
-F tool/lemon.c 1c5a788bdeccfcc61f2e11665e77cc74fd5ca92f
-F tool/lempar.c 8f998bf8d08e2123149c2cc5d0597cd5d5d1abdd
+F tool/lemon.c 5d1731de7eb31238e42ff424c0c78efb4a7be635
+F tool/lempar.c 71f92c138d8288f1a36b438ad39d94cc6835afb7
 F tool/memleak.awk 4e7690a51bf3ed757e611273d43fe3f65b510133
 F tool/memleak2.awk 9cc20c8e8f3c675efac71ea0721ee6874a1566e8
 F tool/memleak3.tcl 7707006ee908cffff210c98158788d85bb3fcdbf
@@ -609,7 +610,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 720bc20a11275ffe139df9203f23e0683b9b4db1
-R d03e78e82114013abb8d1522ad14c7c0
+P 51452d20f99ecbe0fdb73cfafde5270711aeacad
+R 9db7de996b03087357a154a15493b9be
 U drh
-Z 7f13ab757cd6e736d87dbada7e62ee4e
+Z 821a8fe0db1ecdef250b265a178867b8
index 3c46432b269334a51eaec581752637fa5cd8e526..33bc45eb5f780ea01292d7a2072d60ef826139f8 100644 (file)
@@ -1 +1 @@
-51452d20f99ecbe0fdb73cfafde5270711aeacad
\ No newline at end of file
+2a0bc1e186532a0bfe36ca18fda74a5e7a199227
\ No newline at end of file
index bbfdbd2847e4615a2b96c1ca37c9fc51593b0d02..f374b61f191ae9c7ab75b4e4c70d3befa6efddd7 100644 (file)
@@ -22,7 +22,7 @@
 **     COMMIT
 **     ROLLBACK
 **
-** $Id: build.c,v 1.468 2008/01/21 16:22:46 drh Exp $
+** $Id: build.c,v 1.469 2008/01/22 01:48:06 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -138,6 +138,7 @@ void sqlite3FinishCoding(Parse *pParse){
   db = pParse->db;
   if( db->mallocFailed ) return;
   if( pParse->nested ) return;
+  if( pParse->nErr ) return;
   if( !pParse->pVdbe ){
     if( pParse->rc==SQLITE_OK && pParse->nErr ){
       pParse->rc = SQLITE_ERROR;
index 19edda65b83ef80acc55d5f61b7d8cfbc3db813b..65c64ebf31603871c5b2915bfb9ec746511e52d2 100644 (file)
@@ -14,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.237 2008/01/02 16:27:10 danielk1977 Exp $
+** @(#) $Id: parse.y,v 1.238 2008/01/22 01:48:06 drh Exp $
 */
 
 // All token codes are small integers with #defines that begin with "TK_"
@@ -971,7 +971,7 @@ trigger_decl(A) ::= temp(T) TRIGGER ifnotexists(NOERR) nm(B) dbnm(Z)
   A = (Z.n==0?B:Z);
 }
 
-%type trigger_time  {int}
+%type trigger_time {int}
 trigger_time(A) ::= BEFORE.      { A = TK_BEFORE; }
 trigger_time(A) ::= AFTER.       { A = TK_AFTER;  }
 trigger_time(A) ::= INSTEAD OF.  { A = TK_INSTEAD;}
@@ -1064,7 +1064,7 @@ cmd ::= DETACH database_kw_opt expr(D). {
   sqlite3Detach(pParse, D);
 }
 
-%type key_opt {Expr *}
+%type key_opt {Expr*}
 %destructor key_opt {sqlite3ExprDelete($$);}
 key_opt(A) ::= .                     { A = 0; }
 key_opt(A) ::= KEY expr(X).          { A = X; }
index 7e32012e2c967d89ab4fe2b650b6bc4f985cf254..dc7db612bbcacb3c06b574ddb393913f6a1a71db 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** This file contains code used to implement the PRAGMA command.
 **
-** $Id: pragma.c,v 1.168 2008/01/17 16:22:15 drh Exp $
+** $Id: pragma.c,v 1.169 2008/01/22 01:48:09 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -1156,7 +1156,7 @@ void sqlite3Pragma(
       pBt = db->aDb[i].pBt;
       if( pBt==0 || (pPager = sqlite3BtreePager(pBt))==0 ){
         zState = "closed";
-      }else if( sqlite3_file_control(db, db->aDb[i].zName
+      }else if( sqlite3_file_control(db, i ? db->aDb[i].zName : 0
                                      SQLITE_FCNTL_LOCKSTATE, &j)==SQLITE_OK ){
          zState = azLockName[j];
       }
index ba080fcf34993163c64764d72a241347215f3e65..ed18ad28350f20b16080fc9e97cf14a6ea5a694c 100644 (file)
@@ -13,7 +13,7 @@
 ** interface, and routines that contribute to loading the database schema
 ** from disk.
 **
-** $Id: prepare.c,v 1.71 2008/01/09 02:15:39 drh Exp $
+** $Id: prepare.c,v 1.72 2008/01/22 01:48:09 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -644,9 +644,7 @@ int sqlite3Reprepare(Vdbe *p){
 
   assert( sqlite3_mutex_held(sqlite3VdbeDb(p)->mutex) );
   zSql = sqlite3_sql((sqlite3_stmt *)p);
-  if( zSql==0 ){
-    return 0;
-  }
+  assert( zSql!=0 );  /* Reprepare only called for prepare_v2() statements */
   db = sqlite3VdbeDb(p);
   assert( sqlite3_mutex_held(db->mutex) );
   rc = sqlite3LockAndPrepare(db, zSql, -1, 0, &pNew, 0);
index ecb74b4678b99f33fe75e791deff23c54bd107c5..dc4cc1a5cb1eabd768b39b1cbf60d1aa0e531dd6 100644 (file)
@@ -663,14 +663,13 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){
     }
     case P4_MEM: {
       Mem *pMem = pOp->p4.pMem;
+      assert( (pMem->flags & MEM_Null)==0 );
       if( pMem->flags & MEM_Str ){
         zP4 = pMem->z;
       }else if( pMem->flags & MEM_Int ){
         sqlite3_snprintf(nTemp, zTemp, "%lld", pMem->u.i);
       }else if( pMem->flags & MEM_Real ){
         sqlite3_snprintf(nTemp, zTemp, "%.16g", pMem->r);
-      }else if( pMem->flags & MEM_Null ){
-        sqlite3_snprintf(nTemp, zTemp, "NULL");
       }
       break;
     }
@@ -2111,6 +2110,9 @@ int sqlite3VdbeSerialGet(
 ** or positive integer if {nKey1, pKey1} is less than, equal to or 
 ** greater than {nKey2, pKey2}.  Both Key1 and Key2 must be byte strings
 ** composed by the OP_MakeRecord opcode of the VDBE.
+**
+** Key1 and Key2 do not have to contain the same number of fields.
+** But if the lengths differ, Key2 must be the shorter of the two.
 */
 int sqlite3VdbeRecordCompare(
   void *userData,
@@ -2176,7 +2178,7 @@ int sqlite3VdbeRecordCompare(
       if( d1<nKey1 ){
         rc = 1;
       }else if( d2<nKey2 ){
-        rc = -1;
+        rc = -1;  /* Only occurs on a corrupt database file */
       }
     }
   }else if( pKeyInfo->aSortOrder && i<pKeyInfo->nField
index 4da350e73b0cd4acb8919ecd792865f0f0f6b16a..c2631c970c8eacf9189f1e53b637c99339a5c56d 100644 (file)
@@ -944,7 +944,7 @@ sqlite3_value *sqlite3ValueNew(sqlite3 *db){
 ** Create a new sqlite3_value object, containing the value of pExpr.
 **
 ** This only works for very simple expressions that consist of one constant
-** token (i.e. "5", "5.1", "NULL", "'a string'"). If the expression can
+** token (i.e. "5", "5.1", "'a string'"). If the expression can
 ** be converted directly into a value, then the value is allocated and
 ** a pointer written to *ppVal. The caller is responsible for deallocating
 ** the value by passing it to sqlite3ValueFree() later on. If the expression
index a6d04364d30aea9e608ec9849e928716512ac3a5..aa12e588bad42ada7e8f22843e964984c84b2eac 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this script testing the callback-free C/C++ API.
 #
-# $Id: capi3.test,v 1.57 2007/12/13 21:54:11 drh Exp $
+# $Id: capi3.test,v 1.58 2008/01/22 01:48:09 drh Exp $
 #
 
 set testdir [file dirname $argv0]
@@ -1113,4 +1113,37 @@ do_test capi3-17.3 {
   sqlite3_finalize $STMT
 } {SQLITE_OK}
 
+# Verify that sqlite3_step() fails with an SQLITE_SCHEMA error
+# when the statement is prepared with sqlite3_prepare() (not
+# sqlite3_prepare_v2()) and the schema has changed.
+#
+do_test capi3-18.1 {
+  set STMT [sqlite3_prepare db {SELECT * FROM t2} -1 TAIL]
+  sqlite3 db2 test.db
+  db2 eval {CREATE TABLE t3(x)}
+  db2 close
+breakpoint
+  sqlite3_step $STMT
+} {SQLITE_ERROR}
+do_test capi3-18.2 {
+  sqlite3_reset $STMT
+  sqlite3_errcode db
+} {SQLITE_SCHEMA}
+do_test capi3-18.3 {
+  sqlite3_errmsg db
+} {database schema has changed}
+# The error persist on retry when sqlite3_prepare() has been used.
+do_test capi3-18.4 {
+  sqlite3_step $STMT
+} {SQLITE_ERROR}
+do_test capi3-18.5 {
+  sqlite3_reset $STMT
+  sqlite3_errcode db
+} {SQLITE_SCHEMA}
+do_test capi3-18.6 {
+  sqlite3_errmsg db
+} {database schema has changed}
+sqlite3_finalize $STMT
+
+
 finish_test
index 7f7cb0df6b617f076419b2171ef63fff52b9414c..44b217934e102664750f6911d10632fdc9d0cd7f 100644 (file)
@@ -13,7 +13,7 @@
 # The focus of this file is testing of the proper handling of conversions
 # to the native text representation.
 #
-# $Id: enc3.test,v 1.7 2008/01/19 23:50:26 drh Exp $
+# $Id: enc3.test,v 1.8 2008/01/22 01:48:09 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -79,9 +79,13 @@ ifcapable {bloblit && utf16} {
 
 # Try to attach a database with a different encoding.
 #
-ifcapable {utf16} {
+ifcapable {utf16 && shared_cache} {
+  db close
   file delete -force test8.db test8.db-journal
+  set ::enable_shared_cache [sqlite3_enable_shared_cache 1]
   sqlite3 dbaux test8.db
+  sqlite3 db test.db
+  db eval {SELECT 1 FROM sqlite_master LIMIT 1}
   do_test enc3-3.1 {
     dbaux eval {
       PRAGMA encoding='utf8';
@@ -95,8 +99,9 @@ ifcapable {utf16} {
       SELECT 1 FROM utf16.sqlite_master LIMIT 1;
     } dbaux
   } {1 {attached databases must use the same text encoding as main database}}
-  catch {dbaux close}
+  dbaux close
   file delete -force test8.db test8.db-journal
+  sqlite3_enable_shared_cache $::enable_shared_cache
 }
 
 finish_test
index 3fb6adf2ca7ca287d50db06e127489347ab681f1..9db3acd0d785fbaf7e4e73affbeabf10ec424f8d 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing expressions.
 #
-# $Id: expr.test,v 1.61 2008/01/19 20:11:26 drh Exp $
+# $Id: expr.test,v 1.62 2008/01/22 01:48:09 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -172,6 +172,7 @@ test_expr expr-2.23 {r1=1.23, r2=2.34} {max(r1,r2,r1+r2,r1-r2)} {3.57}
 test_expr expr-2.24 {r1=25.0, r2=11.0} {r1%r2} 3.0
 test_expr expr-2.25 {r1=1.23, r2=NULL} {coalesce(r1+r2,99.0)} 99.0
 test_expr expr-2.26 {r1=1e300, r2=1e300} {coalesce((r1*r2)*0.0,99.0)} 99.0
+test_expr expr-2.26b {r1=1e300, r2=-1e300} {coalesce((r1*r2)*0.0,99.0)} 99.0
 test_expr expr-2.27 {r1=1.1, r2=0.0} {r1/r2} {{}}
 test_expr expr-2.28 {r1=1.1, r2=0.0} {r1%r2} {{}}
 
index 2f49a92ab8f73abb8596508b7cc95979c865a2d7..f46fa11232093daf1c436febfb385d7ae15c2046 100644 (file)
@@ -12,7 +12,7 @@
 # This test script checks that tickets #2794, #2795, #2796, and #2797
 # have been fixed.
 # 
-# $Id: mallocF.test,v 1.2 2007/12/14 15:12:21 drh Exp $
+# $Id: mallocF.test,v 1.3 2008/01/22 01:48:09 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -20,7 +20,7 @@ source $testdir/tester.tcl
 # Only run these tests if memory debugging is turned on.
 #
 ifcapable !memdebug {
-   puts "Skipping mallocE tests: not compiled with -DSQLITE_MEMDEBUG..."
+   puts "Skipping mallocF tests: not compiled with -DSQLITE_MEMDEBUG..."
    finish_test
    return
 }
diff --git a/test/mallocG.test b/test/mallocG.test
new file mode 100644 (file)
index 0000000..a55cbce
--- /dev/null
@@ -0,0 +1,42 @@
+# 2007 Aug 29
+#
+# 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.
+#
+#***********************************************************************
+#
+# This test script checks malloc failures in various obscure operations.
+# 
+# $Id: mallocG.test,v 1.1 2008/01/22 01:48:09 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# Only run these tests if memory debugging is turned on.
+#
+ifcapable !memdebug {
+   puts "Skipping mallocG tests: not compiled with -DSQLITE_MEMDEBUG..."
+   finish_test
+   return
+}
+source $testdir/malloc_common.tcl
+
+# Malloc failures while opening a database connection.
+#
+do_malloc_test malloeG-1 -tclbody {
+  db close
+  sqlite3 db test.db
+}
+
+do_malloc_test mallocG-2 -sqlprep {
+  CREATE TABLE t1(x, y);
+  CREATE TABLE t2(x INTEGER PRIMARY KEY);
+} -sqlbody {
+  SELECT y FROM t1 WHERE x IN t2;
+}
+
+finish_test
index 22014853aa651130ca3d00eeb23ab5ff8fd86da4..9782095b3c9583f3f8f73d725b8d01e40dc5db8e 100644 (file)
@@ -12,7 +12,7 @@
 # This file contains tests to verify that the limits defined in
 # sqlite source file limits.h are enforced.
 #
-# $Id: sqllimits1.test,v 1.22 2008/01/17 20:26:47 drh Exp $
+# $Id: sqllimits1.test,v 1.23 2008/01/22 01:48:09 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -187,6 +187,23 @@ do_test sqllimits-2.2 {
   set ::SQLITE_MAX_SQL_LENGTH 0
   catchsql $sql
 } {0 1}
+do_test sqllimits-2.3 {
+  set ::SQLITE_MAX_SQL_LENGTH 50000
+  set sql "SELECT 1 WHERE 1==1"
+  set tail " /* A comment to take up space in order to make the string\
+                longer without increasing the expression depth */\
+                AND   1  ==  1"
+  set N [expr {($::SQLITE_MAX_SQL_LENGTH / [string length $tail])+1}]
+  append sql [string repeat $tail $N]
+  set nbytes [string length $sql]
+  append sql { AND 0}
+  set rc [catch {sqlite3_prepare $DB $sql $nbytes TAIL} STMT]
+  lappend rc $STMT
+} {1 {(18) statement too long}}
+do_test sqllimits-2.4 {
+  sqlite3_errmsg $DB
+} {statement too long}
+
 
 #--------------------------------------------------------------------
 # Test cases sqllimits-3.* test that the limit set using the
index 64b7a28262a9e1be7459f16abb4d001e66706582..986c088795dfc3781d776692776e9ae3eaf837ec 100644 (file)
@@ -131,6 +131,7 @@ struct symbol {
   } assoc;                 /* Associativity if predecence is defined */
   char *firstset;          /* First-set for all rules of this symbol */
   Boolean lambda;          /* True if NT and can generate an empty string */
+  int useCnt;              /* Number of times used */
   char *destructor;        /* Code which executes whenever this symbol is
                            ** popped from the stack during error processing */
   int destructorln;        /* Line number of destructor code */
@@ -1437,6 +1438,7 @@ char **argv;
   lem.basisflag = basisflag;
   Symbol_new("$");
   lem.errsym = Symbol_new("error");
+  lem.errsym->useCnt = 0;
 
   /* Parse the input file */
   Parse(&lem);
@@ -2136,7 +2138,7 @@ to follow the previous rule.");
       }else if( isalpha(x[0]) ){
         if( psp->nrhs>=MAXRHS ){
           ErrorMsg(psp->filename,psp->tokenlineno,
-            "Too many symbols on RHS or rule beginning at \"%s\".",
+            "Too many symbols on RHS of rule beginning at \"%s\".",
             x);
           psp->errorcnt++;
           psp->state = RESYNC_AFTER_RULE_ERROR;
@@ -3430,7 +3432,9 @@ int mhflag;                 /* True if generating makeheaders output */
     fprintf(out,"  %s yy%d;\n",types[i],i+1); lineno++;
     free(types[i]);
   }
-  fprintf(out,"  int yy%d;\n",lemp->errsym->dtnum); lineno++;
+  if( lemp->errsym->useCnt ){
+    fprintf(out,"  int yy%d;\n",lemp->errsym->dtnum); lineno++;
+  }
   free(stddt);
   free(types);
   fprintf(out,"} YYMINORTYPE;\n"); lineno++;
@@ -3480,6 +3484,25 @@ static int axset_compare(const void *a, const void *b){
   return p2->nAction - p1->nAction;
 }
 
+/*
+** Write text on "out" that describes the rule "rp".
+*/
+static void writeRuleText(FILE *out, struct rule *rp){
+  int j;
+  fprintf(out,"%s ::=", rp->lhs->name);
+  for(j=0; j<rp->nrhs; j++){
+    struct symbol *sp = rp->rhs[j];
+    fprintf(out," %s", sp->name);
+    if( sp->type==MULTITERMINAL ){
+      int k;
+      for(k=1; k<sp->nsubsym; k++){
+        fprintf(out,"|%s",sp->subsym[k]->name);
+      }
+    }
+  }
+}
+
+
 /* Generate C source code for the parser */
 void ReportTable(lemp, mhflag)
 struct lemon *lemp;
@@ -3575,8 +3598,10 @@ int mhflag;     /* Output in makeheaders format if true */
   }
   fprintf(out,"#define YYNSTATE %d\n",lemp->nstate);  lineno++;
   fprintf(out,"#define YYNRULE %d\n",lemp->nrule);  lineno++;
-  fprintf(out,"#define YYERRORSYMBOL %d\n",lemp->errsym->index);  lineno++;
-  fprintf(out,"#define YYERRSYMDT yy%d\n",lemp->errsym->dtnum);  lineno++;
+  if( lemp->errsym->useCnt ){
+    fprintf(out,"#define YYERRORSYMBOL %d\n",lemp->errsym->index);  lineno++;
+    fprintf(out,"#define YYERRSYMDT yy%d\n",lemp->errsym->dtnum);  lineno++;
+  }
   if( lemp->has_fallback ){
     fprintf(out,"#define YYFALLBACK 1\n");  lineno++;
   }
@@ -3775,17 +3800,8 @@ int mhflag;     /* Output in makeheaders format if true */
   */
   for(i=0, rp=lemp->rule; rp; rp=rp->next, i++){
     assert( rp->index==i );
-    fprintf(out," /* %3d */ \"%s ::=", i, rp->lhs->name);
-    for(j=0; j<rp->nrhs; j++){
-      struct symbol *sp = rp->rhs[j];
-      fprintf(out," %s", sp->name);
-      if( sp->type==MULTITERMINAL ){
-        int k;
-        for(k=1; k<sp->nsubsym; k++){
-          fprintf(out,"|%s",sp->subsym[k]->name);
-        }
-      }
-    }
+    fprintf(out," /* %3d */ \"", i);
+    writeRuleText(out, rp);
     fprintf(out,"\",\n"); lineno++;
   }
   tplt_xfer(lemp->name,in,out,&lineno);
@@ -3798,7 +3814,8 @@ int mhflag;     /* Output in makeheaders format if true */
     for(i=0; i<lemp->nsymbol; i++){
       struct symbol *sp = lemp->symbols[i];
       if( sp==0 || sp->type!=TERMINAL ) continue;
-      fprintf(out,"    case %d:\n",sp->index); lineno++;
+      fprintf(out,"    case %d: /* %s */\n",
+              sp->index, sp->name); lineno++;
     }
     for(i=0; i<lemp->nsymbol && lemp->symbols[i]->type!=TERMINAL; i++);
     if( i<lemp->nsymbol ){
@@ -3812,7 +3829,8 @@ int mhflag;     /* Output in makeheaders format if true */
       struct symbol *sp = lemp->symbols[i];
       if( sp==0 || sp->type==TERMINAL ||
           sp->index<=0 || sp->destructor!=0 ) continue;
-      fprintf(out,"    case %d:\n",sp->index); lineno++;
+      fprintf(out,"    case %d: /* %s */\n",
+              sp->index, sp->name); lineno++;
       dflt_sp = sp;
     }
     if( dflt_sp!=0 ){
@@ -3823,7 +3841,8 @@ int mhflag;     /* Output in makeheaders format if true */
   for(i=0; i<lemp->nsymbol; i++){
     struct symbol *sp = lemp->symbols[i];
     if( sp==0 || sp->type==TERMINAL || sp->destructor==0 ) continue;
-    fprintf(out,"    case %d:\n",sp->index); lineno++;
+    fprintf(out,"    case %d: /* %s */\n",
+            sp->index, sp->name); lineno++;
 
     /* Combine duplicate destructors into a single case */
     for(j=i+1; j<lemp->nsymbol; j++){
@@ -3831,7 +3850,8 @@ int mhflag;     /* Output in makeheaders format if true */
       if( sp2 && sp2->type!=TERMINAL && sp2->destructor
           && sp2->dtnum==sp->dtnum
           && strcmp(sp->destructor,sp2->destructor)==0 ){
-         fprintf(out,"    case %d:\n",sp2->index); lineno++;
+         fprintf(out,"    case %d: /* %s */\n",
+                 sp2->index, sp2->name); lineno++;
          sp2->destructor = 0;
       }
     }
@@ -3862,10 +3882,14 @@ int mhflag;     /* Output in makeheaders format if true */
   for(rp=lemp->rule; rp; rp=rp->next){
     struct rule *rp2;
     if( rp->code==0 ) continue;
-    fprintf(out,"      case %d:\n",rp->index); lineno++;
+    fprintf(out,"      case %d: /* ", rp->index);
+    writeRuleText(out, rp);
+    fprintf(out, " */\n"); lineno++;
     for(rp2=rp->next; rp2; rp2=rp2->next){
       if( rp2->code==rp->code ){
-        fprintf(out,"      case %d:\n",rp2->index); lineno++;
+        fprintf(out,"      case %d: /* ", rp2->index);
+        writeRuleText(out, rp2);
+        fprintf(out," */\n"); lineno++;
         rp2->code = 0;
       }
     }
@@ -4291,8 +4315,10 @@ char *x;
     sp->lambda = LEMON_FALSE;
     sp->destructor = 0;
     sp->datatype = 0;
+    sp->useCnt = 0;
     Symbol_insert(sp,sp->name);
   }
+  sp->useCnt++;
   return sp;
 }
 
index 97d146d4c5b41ab5d9066b5cda47936aae241ceb..e9d65a9aff3b2b1ef063c100bc538fb984eecef6 100644 (file)
@@ -647,7 +647,9 @@ void Parse(
   YYMINORTYPE yyminorunion;
   int yyact;            /* The parser action. */
   int yyendofinput;     /* True if we are at the end of input */
+#ifdef YYERRORSYMBOL
   int yyerrorhit = 0;   /* True if yymajor has invoked an error */
+#endif
   yyParser *yypParser;  /* The parser */
 
   /* (re)initialize the parser, if necessary */
@@ -687,8 +689,11 @@ void Parse(
       }
     }else if( yyact < YYNSTATE + YYNRULE ){
       yy_reduce(yypParser,yyact-YYNSTATE);
-    }else if( yyact == YY_ERROR_ACTION ){
+    }else{
+      assert( yyact == YY_ERROR_ACTION );
+#ifdef YYERRORSYMBOL
       int yymx;
+#endif
 #ifndef NDEBUG
       if( yyTraceFILE ){
         fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
@@ -769,9 +774,6 @@ void Parse(
       }
       yymajor = YYNOCODE;
 #endif
-    }else{
-      yy_accept(yypParser);
-      yymajor = YYNOCODE;
     }
   }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
   return;