]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Move TCL interface for sqlite3_release_memory() and sqlite3_soft_heap_limit()
authordrh <drh@noemail.net>
Thu, 5 Jan 2006 15:50:06 +0000 (15:50 +0000)
committerdrh <drh@noemail.net>
Thu, 5 Jan 2006 15:50:06 +0000 (15:50 +0000)
out of tclsqlite.c and into test1.c.  Update the TCL interface documention
to describe the "exists" method. (CVS 2862)

FossilOrigin-Name: 98194a45cc60cb9942847f773bc797fb5463bd10

manifest
manifest.uuid
src/tclsqlite.c
src/test1.c
test/malloc5.test
test/tclsqlite.test
www/changes.tcl
www/tclsqlite.tcl

index cf3dd057217bd24836a97577e18cc623df08136b..f889920408683c7d01e047e4c3e2cd0ea89b234e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sfor\sticket\s#1582\s(Double\sdelete\sof\sinvalid\sLIMIT\sclause\sExpr*\sapplied\sto\sa\sUNION\sALL\squery).\s(CVS\s2861)
-D 2006-01-05T14:22:34
+C Move\sTCL\sinterface\sfor\ssqlite3_release_memory()\sand\ssqlite3_soft_heap_limit()\nout\sof\stclsqlite.c\sand\sinto\stest1.c.\s\sUpdate\sthe\sTCL\sinterface\sdocumention\nto\sdescribe\sthe\s"exists"\smethod.\s(CVS\s2862)
+D 2006-01-05T15:50:07
 F Makefile.in e3c6b3a38d734d41574c04f2fc90d18de2b87102
 F Makefile.linux-gcc aee18d8a05546dcf1888bd4547e442008a49a092
 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028
@@ -71,8 +71,8 @@ F src/shell.c 66b073375efbdee19045e7e0cd38b85f9aff71da
 F src/sqlite.h.in ba3a29daa6a16e054191ccb384a981964e882a1d
 F src/sqliteInt.h 6f29c97703b1a1e032916b0bab83efe9b2734984
 F src/table.c 486dcfce532685b53b5a2b5da8bba0ded6fb2316
-F src/tclsqlite.c 0386460a4c017d49d729d44cdcb3fb3ffb2503e0
-F src/test1.c 988dbac66c3ca92d69fbe0283d77e86cd6f73ce8
+F src/tclsqlite.c 351ae47649ac7119d772ab74ed7091f5e400041e
+F src/test1.c 89e25646feceaf09e55c11ecba03ddcfd7cf7c0a
 F src/test2.c 36390cdfc70c08e5ee0b466d0654a117f398bbff
 F src/test3.c 9742aa146eb750cab81c1d5605286c3a0eb88054
 F src/test4.c a8fd681e139e1c61f22a77d07fc3a99cb28fff3f
@@ -187,7 +187,7 @@ F test/malloc.test a5ed721cf7d1b12602ede4f98c11b65ab1582cc0
 F test/malloc2.test e6e321db96d6c94cb18bf82ad7215070c41e624e
 F test/malloc3.test 9797d39eca7087a1022bcc0eb0b22215475c9698
 F test/malloc4.test 2e29d155eb4b4808019ef47eeedfcbe9e09e0f05
-F test/malloc5.test cd31d7be49690abc6845baa1f83bfd7b789ee187
+F test/malloc5.test 4ebf827a8173e1429480a6b276d37e89c6ab96f0
 F test/manydb.test d81debbf5871242e3b5df1d3bb5e14c50431b6f8
 F test/memdb.test 1860e060be810bf0775bc57408a5b7c4954bcaea
 F test/memleak.test df2b2b96e77f8ba159a332299535b1e5f18e49ac
@@ -228,7 +228,7 @@ F test/subselect.test 2d13fb7f450db3595adcdd24079a0dd1d2d6abc2
 F test/sync.test 6e8b885cec5ccba2090e92c90f747a7142f53c88
 F test/table.test 6dc0dfa44dd429520e0e5a0c5e55025f730e9403
 F test/tableapi.test 6a66d58b37d46dc0f2b3c7d4bd2617d209399bd1
-F test/tclsqlite.test 19578d32a7692311918caf0ae3521d19525bcb62
+F test/tclsqlite.test 2c4b5fb2f21e6740479463c263f3020f08e472d7
 F test/temptable.test 7927261befdbc7b0a7ffebb85ecc70a74fa7b15b
 F test/tester.tcl 58dcfde5265c3c46e05ae2af4accaa29f0b44d91
 F test/thread1.test 776c9e459b75ba905193b351926ac4019b049f35
@@ -294,7 +294,7 @@ F www/autoinc.tcl b357f5ba954b046ee35392ce0f884a2fcfcdea06
 F www/c_interface.tcl b51b08591554c16a0c3ef718364a508ac25abc7e
 F www/capi3.tcl 7a7cc225fe02eb7ab861a6019b08baa0014409e1
 F www/capi3ref.tcl c4bf23a0110ad0ffdf4fe6b74d464965116dcea4
-F www/changes.tcl ef5874a59698da63ec914cbfbd64b4033892ddc4
+F www/changes.tcl 567069a3dc7d066f3687fe3697be62e6dd19e671
 F www/common.tcl 14d121c28532ad20c3e349caa4db708b0b822083
 F www/compile.tcl 276546d7eb445add5a867193bbd80f6919a6b084
 F www/conflict.tcl cdd0f4b59b0ba6d61f67e6a38f3ae45853bacb30
@@ -332,11 +332,11 @@ F www/speed.tcl 656ed5be8cc9d536353e1a96927b925634a62933
 F www/sqlite.tcl a883ed7b47371d31d471e6aea5ed1f972ae8e1be
 F www/support.tcl 7961ce16290692578d783bb11f0dc8391a9be9c3
 F www/table-ex1b2.gif a588d21a2d88bb2a2ef0431fcc5ed5aa48c0bbc5
-F www/tclsqlite.tcl ddcf912ea48695603c8ed7efb29f0812ef8d1b49
+F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl a99cf5f6d8bd4d5537584a2b342f0fb9fa601d8b
 F www/whentouse.tcl 97e2b5cd296f7d8057e11f44427dea8a4c2db513
-P 6fdbb8b771e490f0d791326689245302c4fe18f5
-R b489dd3c565f674bf68347d5b31f3b83
-U danielk1977
-Z 74556dd90bea6451105d7798d9757184
+P 5dec3a392ba3c249bbca899c12e99c26cc1b8cdb
+R 6ce19bb1451171f34823f6ee27789bdd
+U drh
+Z 920e9b3cd2f7e8da26bd87500adce907
index 1c90776d18a94f0e59bb829d6ca4be3559f2c54b..55fce8cf5248d1ddc4a34f4526e9ac0bd1f53c73 100644 (file)
@@ -1 +1 @@
-5dec3a392ba3c249bbca899c12e99c26cc1b8cdb
\ No newline at end of file
+98194a45cc60cb9942847f773bc797fb5463bd10
\ No newline at end of file
index 610e9063ec17f1c86453f70626e63b75ce69e98b..c469f75eb3f41d89bd17e1712daf8b968a273c7a 100644 (file)
@@ -11,7 +11,7 @@
 *************************************************************************
 ** A TCL Interface to SQLite
 **
-** $Id: tclsqlite.c,v 1.144 2006/01/04 18:13:26 drh Exp $
+** $Id: tclsqlite.c,v 1.145 2006/01/05 15:50:07 drh Exp $
 */
 #ifndef NO_TCL     /* Omit this whole file if TCL is unavailable */
 
@@ -666,9 +666,9 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
     "exists",             "function",          "last_insert_rowid",
     "nullvalue",          "onecolumn",         "profile",
     "progress",           "rekey",             "rollback_hook",
-    "release_memory",     "soft_heap_limit",   "timeout",
-    "total_changes",      "trace",             "transaction",
-    "update_hook",        "version",           0                    
+    "timeout",            "total_changes",     "trace",
+    "transaction",        "update_hook",       "version",
+    0                    
   };
   enum DB_enum {
     DB_AUTHORIZER,        DB_BUSY,             DB_CACHE,
@@ -678,9 +678,8 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
     DB_EXISTS,            DB_FUNCTION,         DB_LAST_INSERT_ROWID,
     DB_NULLVALUE,         DB_ONECOLUMN,        DB_PROFILE,
     DB_PROGRESS,          DB_REKEY,            DB_ROLLBACK_HOOK,
-    DB_RELEASE_MEMORY,    DB_SOFT_HEAP_LIMIT,  DB_TIMEOUT,
-    DB_TOTAL_CHANGES,     DB_TRACE,            DB_TRANSACTION,
-    DB_UPDATE_HOOK,       DB_VERSION
+    DB_TIMEOUT,           DB_TOTAL_CHANGES,    DB_TRACE,
+    DB_TRANSACTION,       DB_UPDATE_HOOK,      DB_VERSION
   };
   /* don't leave trailing commas on DB_enum, it confuses the AIX xlc compiler */
 
@@ -1752,57 +1751,6 @@ static int DbObjCmd(void *cd, Tcl_Interp *interp, int objc,Tcl_Obj *const*objv){
     sqlite3_busy_timeout(pDb->db, ms);
     break;
   }
-
-  /*
-  **     $db soft_heap_limit N
-  **
-  ** Set the soft-heap-limit for this thread. Note that the limit is 
-  ** per-thread, not per-database. The previous limit is returned.
-  */
-  case DB_SOFT_HEAP_LIMIT: {
-#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
-    int n;
-    int ret;
-    if( objc!=3 ){
-      Tcl_WrongNumArgs(interp, 2, objv, "BYTES");
-      return TCL_ERROR;
-    }
-    if( Tcl_GetIntFromObj(interp, objv[2], &n) ){
-      return TCL_ERROR;
-    }
-    ret = sqlite3Tsd()->nSoftHeapLimit;
-    sqlite3_soft_heap_limit(n);
-    Tcl_SetObjResult(interp, Tcl_NewIntObj(ret));
-#endif
-    break;
-  }
-
-  /*
-  **     $db release_memory ?N?
-  **
-  ** Try to release memory currently held (but not really required) by 
-  ** SQLite database connections opened by the current thread. If an
-  ** integer argument is supplied, then SQLite stops trying to free memory
-  ** after N bytes have been freed.
-  **
-  ** The value returned is the number of bytes actually freed.
-  **/
-  case DB_RELEASE_MEMORY: {
-    int nRelease = 0;
-    int N = -1;
-    if( objc!=2 && objc!=3 ){
-      Tcl_WrongNumArgs(interp, 2, objv, "?N?");
-      return TCL_ERROR;
-    }
-#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
-    if( objc==3 && TCL_OK!=Tcl_GetIntFromObj(interp, objv[2], &N) ){
-      return TCL_ERROR;
-    }
-    nRelease = sqlite3_release_memory(N);
-#endif
-    Tcl_SetObjResult(interp, Tcl_NewIntObj(nRelease));
-    break;
-  }
   
   /*
   **     $db total_changes
index 263666ca97c1f14a6705d65aa6a71e6538a0bbdd..f960ef746c9336aca9668d6e57fd978955e3f998 100644 (file)
@@ -13,7 +13,7 @@
 ** is not included in the SQLite library.  It is used for automated
 ** testing of the SQLite library.
 **
-** $Id: test1.c,v 1.179 2006/01/03 00:33:50 drh Exp $
+** $Id: test1.c,v 1.180 2006/01/05 15:50:07 drh Exp $
 */
 #include "sqliteInt.h"
 #include "tcl.h"
@@ -2938,6 +2938,67 @@ static int tcl_variable_type(
   return TCL_OK;
 }
 
+/*
+** Usage:  sqlite3_release_memory ?N?
+**
+** Attempt to release memory currently held but not actually required.
+** The integer N is the number of bytes we are trying to release.  The 
+** return value is the amount of memory actually released.
+*/
+static int test_release_memory(
+  void * clientData,
+  Tcl_Interp *interp,
+  int objc,
+  Tcl_Obj *CONST objv[]
+){
+#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
+  int N;
+  int amt;
+  if( objc!=1 && objc!=2 ){
+    Tcl_WrongNumArgs(interp, 1, objv, "?N?");
+    return TCL_ERROR;
+  }
+  if( objc==2 ){
+    if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR;
+  }else{
+    N = -1;
+  }
+  amt = sqlite3_release_memory(N);
+  Tcl_SetObjResult(interp, Tcl_NewIntObj(amt));
+#endif
+  return TCL_OK;
+}
+
+/*
+** Usage:  sqlite3_soft_heap_limit ?N?
+**
+** Query or set the soft heap limit for the current thread.  The
+** limit is only changed if the N is present.  The previous limit
+** is returned.
+*/
+static int test_soft_heap_limit(
+  void * clientData,
+  Tcl_Interp *interp,
+  int objc,
+  Tcl_Obj *CONST objv[]
+){
+#ifndef SQLITE_OMIT_MEMORY_MANAGEMENT
+  int amt;
+  if( objc!=1 && objc!=2 ){
+    Tcl_WrongNumArgs(interp, 1, objv, "?N?");
+    return TCL_ERROR;
+  }
+  amt = sqlite3Tsd()->nSoftHeapLimit;
+  if( objc==2 ){
+    int N;
+    if( Tcl_GetIntFromObj(interp, objv[1], &N) ) return TCL_ERROR;
+    sqlite3_soft_heap_limit(N);
+  }
+  Tcl_SetObjResult(interp, Tcl_NewIntObj(amt));
+#endif
+  return TCL_OK;
+}
+
 /*
 ** This routine sets entries in the global ::sqlite_options() array variable
 ** according to the compile-time configuration of the database.  Test
@@ -3099,6 +3160,12 @@ static void set_options(Tcl_Interp *interp){
   Tcl_SetVar2(interp, "sqlite_options", "memorydb", "1", TCL_GLOBAL_ONLY);
 #endif
 
+#ifdef SQLITE_OMIT_MEMORY_MANAGEMENT
+  Tcl_SetVar2(interp, "sqlite_options", "memorymanage", "0", TCL_GLOBAL_ONLY);
+#else
+  Tcl_SetVar2(interp, "sqlite_options", "memorymanage", "1", TCL_GLOBAL_ONLY);
+#endif
+
 #ifdef SQLITE_OMIT_OR_OPTIMIZATION
   Tcl_SetVar2(interp, "sqlite_options", "or_opt", "0", TCL_GLOBAL_ONLY);
 #else
@@ -3291,6 +3358,9 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
      { "sqlite3_changes",               test_changes       ,0 },
      { "sqlite3_step",                  test_step          ,0 },
 
+     { "sqlite3_release_memory",        test_release_memory,  0},
+     { "sqlite3_soft_heap_limit",       test_soft_heap_limit, 0},
+
      /* sqlite3_column_*() API */
      { "sqlite3_column_count",          test_column_count  ,0 },
      { "sqlite3_data_count",            test_data_count    ,0 },
index b17a92068bdda806c6dceaf8b4ad0a7108684d11..2b38a160ed27d168cea21e65b1e34d6504d32379 100644 (file)
@@ -12,7 +12,7 @@
 # This file contains test cases focused on the two memory-management APIs, 
 # sqlite3_soft_heap_limit() and sqlite3_release_memory().
 #
-# $Id: malloc5.test,v 1.3 2005/12/30 16:28:02 danielk1977 Exp $
+# $Id: malloc5.test,v 1.4 2006/01/05 15:50:07 drh Exp $
 
 #---------------------------------------------------------------------------
 # NOTES ON EXPECTED BEHAVIOUR
@@ -30,7 +30,7 @@ if {[info command sqlite_malloc_stat]==""} {
 }
 
 do_test malloc5-1.1 {
-  # Simplest possible test. Call [db release_memory] when there is exactly
+  # Simplest possible test. Call sqlite3_release_memory when there is exactly
   # one unused page in a single pager cache. This test case set's the 
   # value of the ::pgalloc variable, which is used in subsequent tests.
   #
@@ -42,7 +42,7 @@ do_test malloc5-1.1 {
     BEGIN;
     CREATE TABLE abc(a, b, c);
   }
-  set ::pgalloc [db release_memory]
+  set ::pgalloc [sqlite3_release_memory]
   expr $::pgalloc > 0
 } {1}
 do_test malloc5-1.2 {
@@ -56,7 +56,7 @@ do_test malloc5-1.2 {
   } db2
 } {1 {database is locked}}
 do_test malloc5-1.3 {
-  # Again call [db release_memory] when there is exactly one unused page 
+  # Again call [sqlite3_release_memory] when there is exactly one unused page 
   # in the cache. The same amount of memory is required, but no journal-sync
   # or exclusive lock should be established.
   execsql {
@@ -64,7 +64,7 @@ do_test malloc5-1.3 {
     BEGIN;
     SELECT * FROM abc;
   }
-  db release_memory
+  sqlite3_release_memory
 } $::pgalloc
 do_test malloc5-1.4 {
   # Database should not be locked this time.
@@ -79,7 +79,7 @@ do_test malloc5-1.5 {
     SELECT * FROM abc;
     CREATE TABLE def(d, e, f);
   }
-  db release_memory 500
+  sqlite3_release_memory 500
 } $::pgalloc
 do_test malloc5-1.6 {
   # Database should not be locked this time. The above test case only
@@ -92,7 +92,7 @@ do_test malloc5-1.6 {
 do_test malloc5-1.7 {
   # Release another 500 bytes of memory. This time we require a sync(), 
   # so the database file will be locked afterwards.
-  db release_memory 500
+  sqlite3_release_memory 500
 } $::pgalloc
 do_test malloc5-1.8 {
   catchsql {
@@ -127,7 +127,7 @@ do_test malloc5-2.2 {
   }
   set data [list]
   db eval {SELECT * FROM abc} {
-    incr nRelease [db release_memory]
+    incr nRelease [sqlite3_release_memory]
     lappend data $a $b $c
   }
   execsql {
@@ -149,7 +149,7 @@ do_test malloc5-3.1 {
     BEGIN;
     SELECT * FROM def;
   } db2
-  db release_memory
+  sqlite3_release_memory
 } [expr $::pgalloc * 2]
 do_test malloc5-3.2 {
   concat \
@@ -173,7 +173,7 @@ sqlite_malloc_outstanding -clearmaxbytes
 # limit in variable ::soft_limit. The original value is restored after 
 # running the tests.
 #
-set ::soft_limit [db soft_heap_limit -1]
+set ::soft_limit [sqlite3_soft_heap_limit -1]
 do_test malloc5-4.1 {
   execsql {BEGIN;}
   execsql {DELETE FROM abc;}
@@ -185,9 +185,9 @@ do_test malloc5-4.1 {
   expr $::nMaxBytes > 1000000
 } {1}
 do_test malloc5-4.2 {
-  db release_memory
+  sqlite3_release_memory
   sqlite_malloc_outstanding -clearmaxbytes
-  db soft_heap_limit 100000
+  sqlite3_soft_heap_limit 100000
   execsql {BEGIN;}
   for {set i 0} {$i < 10000} {incr i} {
     execsql "INSERT INTO abc VALUES($i, $i, '[string repeat X 100]');"
@@ -204,8 +204,6 @@ do_test malloc5-4.3 {
 } [list 20000 [expr int(20000.0 * 4999.5)] [expr int(20000.0 * 4999.5)]]
 
 # Restore the soft heap limit.
-db soft_heap_limit $::soft_limit
+sqlite3_soft_heap_limit $::soft_limit
 
 finish_test
-
-
index 451559ac9b05fd0f8080ba3e233005fd63e60fdb..14ccb1de8a748bc6be19adff18fafda3e7f3f1a7 100644 (file)
@@ -15,7 +15,7 @@
 # interface is pretty well tested.  This file contains some addition
 # tests for fringe issues that the main test suite does not cover.
 #
-# $Id: tclsqlite.test,v 1.48 2005/12/20 09:19:38 danielk1977 Exp $
+# $Id: tclsqlite.test,v 1.49 2006/01/05 15:50:07 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -34,7 +34,7 @@ do_test tcl-1.1 {
 do_test tcl-1.2 {
   set v [catch {db bogus} msg]
   lappend v $msg
-} {1 {bad option "bogus": must be authorizer, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, errorcode, eval, exists, function, last_insert_rowid, nullvalue, onecolumn, profile, progress, rekey, rollback_hook, release_memory, soft_heap_limit, timeout, total_changes, trace, transaction, update_hook, or version}}
+} {1 {bad option "bogus": must be authorizer, busy, cache, changes, close, collate, collation_needed, commit_hook, complete, copy, errorcode, eval, exists, function, last_insert_rowid, nullvalue, onecolumn, profile, progress, rekey, rollback_hook, timeout, total_changes, trace, transaction, update_hook, or version}}
 do_test tcl-1.3 {
   execsql {CREATE TABLE t1(a int, b int)}
   execsql {INSERT INTO t1 VALUES(10,20)}
index 2bedec287141ae565e4014d8503a3378f367da5d..c240b5f3fff81b29b290b9154fd2ffbf837cd42a 100644 (file)
@@ -25,6 +25,20 @@ proc chng {date desc} {
   puts "<DD><P><UL>$desc</UL></P></DD>"
 }
 
+chng {2006 January ? (3.3.0)} {
+<li>CHECK constraints</li>
+<li>IF EXISTS and IF NOT EXISTS clauses on CREATE/DROP TABLE/INDEX.</li>
+<li>DESC indices</li>
+<li>More efficient encoding of boolean values resulting in smaller database
+files</li>
+<li>More aggressive SQLITE_OMIT_FLOATING_POINT<li>
+<li>Separate INTEGER and REAL affinity</li>
+<li>Add a virtual function layer for the OS interface</li>
+<li>"exists" method added to the TCL interface</li>
+<li>Improved response to out-of-memory errors</li>
+<li>Database cached shared between connections in the same thread</li>
+}
+
 chng {2005 December 19 (3.2.8)} {
 <li>Fix an obscure bug that can cause database corruption under the
 following unusual circumstances: A large INSERT or UPDATE statement which 
index 5eae90b0270af42266c679cdc350461f0946261f..52c2b27a5e9b4e443b1d13dddbd52f2120670005 100644 (file)
@@ -1,7 +1,7 @@
 #
 # Run this Tcl script to generate the tclsqlite.html file.
 #
-set rcsid {$Id: tclsqlite.tcl,v 1.15 2005/09/13 07:00:06 drh Exp $}
+set rcsid {$Id: tclsqlite.tcl,v 1.16 2006/01/05 15:50:07 drh Exp $}
 source common.tcl
 header {The Tcl interface to the SQLite library}
 proc METHOD {name text} {
@@ -71,6 +71,7 @@ foreach m [lsort {
  copy
  errorcode
  eval
+ exists
  function
  last_insert_rowid
  nullvalue
@@ -418,6 +419,28 @@ return "0" if it wants SQLite to try again to open the database and
 should return "1" if it wants SQLite to abandon the current operation.
 }
 
+##############################################################################
+METHOD exists {
+
+<p>The "exists" method is similar to "onecolumn" and "eval" in that
+it executes SQL statements.  The difference is that the "exists" method
+always returns a boolean value which is TRUE if a query in the SQL
+statement it executes returns one or more rows and FALSE if the SQL
+returns an empty set.</p>
+
+<p>The "exists" method is often used to test for the existance of
+rows in a table.  For example:</p>
+
+<blockquote><b>
+if {[db exists {SELECT 1 FROM table1 WHERE user=$user}]} {<br>
+&nbsp;&nbsp;&nbsp;# Processing if $user exists<br>
+} else {<br>
+&nbsp;&nbsp;&nbsp;# Processing if $user does not exist<br>
+}
+</b></blockquote>
+}
+
+
 ##############################################################################
 METHOD last_insert_rowid {