From 092e4bdb9119a1365a8919ef18d646cb5ab09ee0 Mon Sep 17 00:00:00 2001 From: drh Date: Fri, 22 Apr 2011 22:55:10 +0000 Subject: [PATCH 1/9] Add the "getlock" utility for determining if a database file (on unix) is currently locked. FossilOrigin-Name: 0ab24b133e332ad7f4517b8e113e9c241ee9af9f --- manifest | 13 ++--- manifest.uuid | 2 +- tool/getlock.c | 134 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+), 7 deletions(-) create mode 100644 tool/getlock.c diff --git a/manifest b/manifest index bcd5754bbe..65bc4f3b22 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sa\scomment\sin\se_createtable.test. -D 2011-04-20T13:35:44.094 +C Add\sthe\s"getlock"\sutility\sfor\sdetermining\sif\sa\sdatabase\sfile\s(on\sunix)\sis\ncurrently\slocked. +D 2011-04-22T22:55:10.113 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -899,6 +899,7 @@ F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b F tool/fragck.tcl 5265a95126abcf6ab357f7efa544787e5963f439 F tool/genfkey.README cf68fddd4643bbe3ff8e31b8b6d8b0a1b85e20f4 F tool/genfkey.test 4196a8928b78f51d54ef58e99e99401ab2f0a7e5 +F tool/getlock.c f4c39b651370156cae979501a7b156bdba50e7ce F tool/lemon.c dfd81a51b6e27e469ba21d01a75ddf092d429027 F tool/lempar.c 01ca97f87610d1dac6d8cd96ab109ab1130e76dc F tool/mkkeywordhash.c d2e6b4a5965e23afb80fbe74bb54648cd371f309 @@ -929,7 +930,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 0dd09fc034c127718366d3a3183e367d2f9fd82d -R 056a0ea57c930302e35ea6c4f7c5b4b7 -U dan -Z b72241c9e230cb141bfcaf5fbf022480 +P d8b149f5e465f7794739ed0210e1e5c53110ee9a +R 46d4cc9c199137dd735f2ac252175f1e +U drh +Z 48df56ba9c3ee078a0d4702e2f08ce89 diff --git a/manifest.uuid b/manifest.uuid index fde4759710..92d78b219d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d8b149f5e465f7794739ed0210e1e5c53110ee9a \ No newline at end of file +0ab24b133e332ad7f4517b8e113e9c241ee9af9f \ No newline at end of file diff --git a/tool/getlock.c b/tool/getlock.c new file mode 100644 index 0000000000..7eff04d7f9 --- /dev/null +++ b/tool/getlock.c @@ -0,0 +1,134 @@ +/* +** This utility program looks at an SQLite database and determines whether +** or not it is locked, the kind of lock, and who is holding this lock. +** +** This only works on unix when the posix advisory locking method is used +** (which is the default on unix) and when the PENDING_BYTE is in its +** usual place. +*/ +#include +#include +#include +#include +#include +#include +#include +#include + +static void usage(const char *argv0){ + fprintf(stderr, "Usage: %s database\n", argv0); + exit(1); +} + +/* Check for a conflicting lock. If one is found, print an this +** on standard output using the format string given and return 1. +** If there are no conflicting locks, return 0. +*/ +static int isLocked( + int h, /* File descriptor to check */ + int type, /* F_RDLCK or F_WRLCK */ + unsigned int iOfst, /* First byte of the lock */ + unsigned int iCnt, /* Number of bytes in the lock range */ + const char *zType /* Type of lock */ +){ + struct flock lk; + + memset(&lk, 0, sizeof(lk)); + lk.l_type = type; + lk.l_whence = SEEK_SET; + lk.l_start = iOfst; + lk.l_len = iCnt; + if( fcntl(h, F_GETLK, &lk)==(-1) ){ + fprintf(stderr, "fcntl(%d) failed: errno=%d\n", h, errno); + exit(1); + } + if( lk.l_type==F_UNLCK ) return 0; + printf("%s lock held by %d\n", zType, (int)lk.l_pid); + return 1; +} + +/* +** Location of locking bytes in the database file +*/ +#define PENDING_BYTE (0x40000000) +#define RESERVED_BYTE (PENDING_BYTE+1) +#define SHARED_FIRST (PENDING_BYTE+2) +#define SHARED_SIZE 510 + +/* +** Lock locations for shared-memory locks used by WAL mode. +*/ +#define SHM_BASE 120 +#define SHM_WRITE SHM_BASE +#define SHM_CHECKPOINT (SHM_BASE+1) +#define SHM_RECOVER (SHM_BASE+2) +#define SHM_READ_FIRST (SHM_BASE+3) +#define SHM_READ_SIZE 5 + + +int main(int argc, char **argv){ + int hDb; /* File descriptor for the open database file */ + int hShm; /* File descriptor for WAL shared-memory file */ + char *zShm; /* Name of the shared-memory file for WAL mode */ + ssize_t got; /* Bytes read from header */ + int isWal; /* True if in WAL mode */ + int nName; /* Length of filename */ + unsigned char aHdr[100]; /* Database header */ + int nLock = 0; /* Number of locks held */ + int i; /* Loop counter */ + + if( argc!=2 ) usage(argv[0]); + hDb = open(argv[1], O_RDONLY, 0); + if( hDb<0 ){ + fprintf(stderr, "cannot open %s\n", argv[1]); + return 1; + } + + /* Make sure we are dealing with an database file */ + got = read(hDb, aHdr, 100); + if( got!=100 || memcmp(aHdr, "SQLite format 3",16)!=0 ){ + fprintf(stderr, "not an SQLite database: %s\n", argv[1]); + exit(1); + } + + /* First check for an exclusive lock */ + if( isLocked(hDb, F_RDLCK, SHARED_FIRST, SHARED_SIZE, "EXCLUSIVE") ){ + return 0; + } + isWal = aHdr[18]==2; + if( isWal==0 ){ + /* Rollback mode */ + if( isLocked(hDb, F_RDLCK, PENDING_BYTE, 1, "PENDING") ) return 0; + if( isLocked(hDb, F_RDLCK, RESERVED_BYTE, 1, "RESERVED") ) return 0; + if( isLocked(hDb, F_WRLCK, SHARED_FIRST, SHARED_SIZE, "SHARED") ){ + return 0; + } + }else{ + /* WAL mode */ + nName = (int)strlen(argv[1]); + zShm = malloc( nName + 100 ); + if( zShm==0 ){ + fprintf(stderr, "out of memory\n"); + exit(1); + } + memcpy(zShm, argv[1], nName); + memcpy(&zShm[nName], "-shm", 5); + hShm = open(zShm, O_RDONLY, 0); + if( hShm<0 ){ + fprintf(stderr, "cannot open %s\n", zShm); + return 1; + } + if( isLocked(hShm, F_RDLCK, SHM_RECOVER, 1, "WAL-RECOVERY") ){ + return 0; + } + nLock += isLocked(hShm, F_RDLCK, SHM_CHECKPOINT, 1, "WAL-CHECKPOINT"); + nLock += isLocked(hShm, F_RDLCK, SHM_WRITE, 1, "WAL-WRITE"); + for(i=0; i Date: Sun, 24 Apr 2011 22:56:07 +0000 Subject: [PATCH 2/9] Disable the transfer optimization if the destination table contains any foreign key constraint and foreign key constraints are enabled. Ticket [6284df89debdf]. FossilOrigin-Name: ddeea5ab5f6c0c4a86cdfbbb9f24d9d54bf8d301 --- manifest | 14 +++++------ manifest.uuid | 2 +- src/insert.c | 12 ++++++++++ test/insert4.test | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 65bc4f3b22..8eaf915520 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s"getlock"\sutility\sfor\sdetermining\sif\sa\sdatabase\sfile\s(on\sunix)\sis\ncurrently\slocked. -D 2011-04-22T22:55:10.113 +C Disable\sthe\stransfer\soptimization\sif\sthe\sdestination\stable\scontains\nany\sforeign\skey\sconstraint\sand\sforeign\skey\sconstraints\sare\senabled.\nTicket\s[6284df89debdf]. +D 2011-04-24T22:56:07.596 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -138,7 +138,7 @@ F src/global.c 02335177cf6946fe5525c6f0755cf181140debf3 F src/hash.c 458488dcc159c301b8e7686280ab209f1fb915af F src/hash.h 2894c932d84d9f892d4b4023a75e501f83050970 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08 -F src/insert.c acfb89fe4a73d703e425e167bfcc72985f4299ae +F src/insert.c cdee360e5cea59db6c4a980e4360499631222af6 F src/journal.c 552839e54d1bf76fb8f7abe51868b66acacf6a0e F src/legacy.c a199d7683d60cef73089e892409113e69c23a99f F src/lempar.c 7f026423f4d71d989e719a743f98a1cbd4e6d99e @@ -505,7 +505,7 @@ F test/init.test 15c823093fdabbf7b531fe22cf037134d09587a7 F test/insert.test aef273dd1cee84cc92407469e6bd1b3cdcb76908 F test/insert2.test 4f3a04d168c728ed5ec2c88842e772606c7ce435 F test/insert3.test 1b7db95a03ad9c5013fdf7d6722b6cd66ee55e30 -F test/insert4.test c1469999a58e86a85b74df645a820f4cc7a8273b +F test/insert4.test b3e02648a5fc3075c29e13c369b5127bf859b5a2 F test/insert5.test 1f93cbe9742110119133d7e8e3ccfe6d7c249766 F test/intarray.test 066b7d7ac38d25bf96f87f1b017bfc687551cdd4 F test/interrupt.test 42e7cf98646fd9cb4a3b131a93ed3c50b9e149f1 @@ -930,7 +930,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P d8b149f5e465f7794739ed0210e1e5c53110ee9a -R 46d4cc9c199137dd735f2ac252175f1e +P 0ab24b133e332ad7f4517b8e113e9c241ee9af9f +R 40e74cf200b39d155b455f390ce862eb U drh -Z 48df56ba9c3ee078a0d4702e2f08ce89 +Z 87bc3e585b95e6d3397bca153c02ab82 diff --git a/manifest.uuid b/manifest.uuid index 92d78b219d..6503aa6c35 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0ab24b133e332ad7f4517b8e113e9c241ee9af9f \ No newline at end of file +ddeea5ab5f6c0c4a86cdfbbb9f24d9d54bf8d301 \ No newline at end of file diff --git a/src/insert.c b/src/insert.c index 588a84f36d..02456e776f 100644 --- a/src/insert.c +++ b/src/insert.c @@ -1734,6 +1734,18 @@ static int xferOptimization( return 0; /* Tables have different CHECK constraints. Ticket #2252 */ } #endif +#ifndef SQLITE_OMIT_FOREIGN_KEY + /* Disallow the transfer optimization if the destination table constains + ** any foreign key constraints. This is more restrictive than necessary. + ** But the main beneficiary of the transfer optimization is the VACUUM + ** command, and the VACUUM command disables foreign key constraints. So + ** the extra complication to make this rule less restrictive is probably + ** not worth the effort. Ticket [6284df89debdfa61db8073e062908af0c9b6118e] + */ + if( (pParse->db->flags & SQLITE_ForeignKeys)!=0 && pDest->pFKey!=0 ){ + return 0; + } +#endif /* If we get this far, it means either: ** diff --git a/test/insert4.test b/test/insert4.test index 0b069e996d..44b428a1c7 100644 --- a/test/insert4.test +++ b/test/insert4.test @@ -326,4 +326,64 @@ do_test insert4-6.7 { } } {1 {constraint failed}} +# Ticket [6284df89debdfa61db8073e062908af0c9b6118e] +# Disable the xfer optimization if the destination table contains +# a foreign key constraint +# +ifcapable foreignkey { + do_test insert4-7.1 { + set ::sqlite3_xferopt_count 0 + execsql { + CREATE TABLE t7a(x INTEGER PRIMARY KEY); INSERT INTO t7a VALUES(123); + CREATE TABLE t7b(y INTEGER REFERENCES t7a); + CREATE TABLE t7c(z INT); INSERT INTO t7c VALUES(234); + INSERT INTO t7b SELECT * FROM t7c; + SELECT * FROM t7b; + } + } {234} + do_test insert4-7.2 { + set ::sqlite3_xferopt_count + } {1} + do_test insert4-7.3 { + set ::sqlite3_xferopt_count 0 + execsql { + DELETE FROM t7b; + PRAGMA foreign_keys=ON; + } + catchsql { + INSERT INTO t7b SELECT * FROM t7c; + } + } {1 {foreign key constraint failed}} + do_test insert4-7.4 { + execsql {SELECT * FROM t7b} + } {} + do_test insert4-7.5 { + set ::sqlite3_xferopt_count + } {0} + do_test insert4-7.6 { + set ::sqlite3_xferopt_count 0 + execsql { + DELETE FROM t7b; DELETE FROM t7c; + INSERT INTO t7c VALUES(123); + INSERT INTO t7b SELECT * FROM t7c; + SELECT * FROM t7b; + } + } {123} + do_test insert4-7.7 { + set ::sqlite3_xferopt_count + } {0} + do_test insert4-7.7 { + set ::sqlite3_xferopt_count 0 + execsql { + PRAGMA foreign_keys=OFF; + DELETE FROM t7b; + INSERT INTO t7b SELECT * FROM t7c; + SELECT * FROM t7b; + } + } {123} + do_test insert4-7.8 { + set ::sqlite3_xferopt_count + } {1} +} + finish_test From 9a3baf10ca3bd1f8069c95832c07c0aafe0066d7 Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 25 Apr 2011 18:01:27 +0000 Subject: [PATCH 3/9] Invoke the unix open() system call through a wrapper to avoid problems resulting from differing declarations to that function in various systems. FossilOrigin-Name: 4c7ff4dd352276e9c01cc536e188cbcd69396952 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_unix.c | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index 8eaf915520..b78804e62d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Disable\sthe\stransfer\soptimization\sif\sthe\sdestination\stable\scontains\nany\sforeign\skey\sconstraint\sand\sforeign\skey\sconstraints\sare\senabled.\nTicket\s[6284df89debdf]. -D 2011-04-24T22:56:07.596 +C Invoke\sthe\sunix\sopen()\ssystem\scall\sthrough\sa\swrapper\sto\savoid\sproblems\s\nresulting\sfrom\sdiffering\sdeclarations\sto\sthat\sfunction\sin\svarious\ssystems. +D 2011-04-25T18:01:27.439 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -162,7 +162,7 @@ F src/os.c 22ac61d06e72a0dac900400147333b07b13d8e1d F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9 F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440 -F src/os_unix.c d7889a0f9389c8c2e1d3b380f5aa1256c22a90e8 +F src/os_unix.c 2c67d126874b78eb427371db4793f0e8fbc7448b F src/os_win.c d149b9a7dfdd38de09afc054f8168cd3cd80630b F src/pager.c 055239dcdfe12b3f5d97f6f01f85da01e2d6d912 F src/pager.h 3f8c783de1d4706b40b1ac15b64f5f896bcc78d1 @@ -930,7 +930,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 0ab24b133e332ad7f4517b8e113e9c241ee9af9f -R 40e74cf200b39d155b455f390ce862eb +P ddeea5ab5f6c0c4a86cdfbbb9f24d9d54bf8d301 +R c3c570e59b4504f5792e40be1884b2ad U drh -Z 87bc3e585b95e6d3397bca153c02ab82 +Z 99b5b07687fe54475ef75b698d77b786 diff --git a/manifest.uuid b/manifest.uuid index 6503aa6c35..f4b8a8d726 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ddeea5ab5f6c0c4a86cdfbbb9f24d9d54bf8d301 \ No newline at end of file +4c7ff4dd352276e9c01cc536e188cbcd69396952 \ No newline at end of file diff --git a/src/os_unix.c b/src/os_unix.c index 2d3a616373..a760e2c147 100644 --- a/src/os_unix.c +++ b/src/os_unix.c @@ -281,6 +281,18 @@ struct unixFile { #define threadid 0 #endif +/* +** Different Unix systems declare open() in different ways. Same use +** open(const char*,int,mode_t). Others use open(const char*,int,...). +** The difference is important when using a pointer to the function. +** +** The safest way to deal with the problem is to always use this wrapper +** which always has the same well-defined interface. +*/ +static int posixOpen(const char *zFile, int flags, int mode){ + return open(zFile, flags, mode); +} + /* ** Many system calls are accessed through pointer-to-functions so that ** they may be overridden at runtime to facilitate fault injection during @@ -292,8 +304,8 @@ static struct unix_syscall { sqlite3_syscall_ptr pCurrent; /* Current value of the system call */ sqlite3_syscall_ptr pDefault; /* Default value */ } aSyscall[] = { - { "open", (sqlite3_syscall_ptr)open, 0 }, -#define osOpen ((int(*)(const char*,int,...))aSyscall[0].pCurrent) + { "open", (sqlite3_syscall_ptr)posixOpen, 0 }, +#define osOpen ((int(*)(const char*,int,int))aSyscall[0].pCurrent) { "close", (sqlite3_syscall_ptr)close, 0 }, #define osClose ((int(*)(int))aSyscall[1].pCurrent) From 3ca84ef62395d14bf5aa51a4bb945412ef10edbc Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 25 Apr 2011 18:03:10 +0000 Subject: [PATCH 4/9] Add the (deliberately undocumented) sqlite_log() SQL function as a built-in. FossilOrigin-Name: f7806e03995b314771aa72a08ce55d56d60096cf --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/func.c | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index b78804e62d..3f91515d1b 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Invoke\sthe\sunix\sopen()\ssystem\scall\sthrough\sa\swrapper\sto\savoid\sproblems\s\nresulting\sfrom\sdiffering\sdeclarations\sto\sthat\sfunction\sin\svarious\ssystems. -D 2011-04-25T18:01:27.439 +C Add\sthe\s(deliberately\sundocumented)\ssqlite_log()\sSQL\sfunction\sas\sa\sbuilt-in. +D 2011-04-25T18:03:10.263 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -133,7 +133,7 @@ F src/delete.c 7a24fcc9a31664d145acb97ce56b6d9f249a25e4 F src/expr.c e3cf0957c6b8faaaf7386a3bc69e53c0dc9705be F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c a43ba8a005fb5efd1deeee06853e3a6120d46a91 -F src/func.c 3a8cb2fb2de3e3aed7f39106daf4878d9d17fcce +F src/func.c 6d907d397c9e6eded680f8946499efdf224d34bd F src/global.c 02335177cf6946fe5525c6f0755cf181140debf3 F src/hash.c 458488dcc159c301b8e7686280ab209f1fb915af F src/hash.h 2894c932d84d9f892d4b4023a75e501f83050970 @@ -930,7 +930,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P ddeea5ab5f6c0c4a86cdfbbb9f24d9d54bf8d301 -R c3c570e59b4504f5792e40be1884b2ad +P 4c7ff4dd352276e9c01cc536e188cbcd69396952 +R 02826977cda64533dcdcab57c0092168 U drh -Z 99b5b07687fe54475ef75b698d77b786 +Z ae88889f134cbeb0e55dabbab9faed47 diff --git a/manifest.uuid b/manifest.uuid index f4b8a8d726..428479b63d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -4c7ff4dd352276e9c01cc536e188cbcd69396952 \ No newline at end of file +f7806e03995b314771aa72a08ce55d56d60096cf \ No newline at end of file diff --git a/src/func.c b/src/func.c index 6a4f7c09c3..e75fa47e7a 100644 --- a/src/func.c +++ b/src/func.c @@ -774,6 +774,21 @@ static void sourceidFunc( sqlite3_result_text(context, sqlite3_sourceid(), -1, SQLITE_STATIC); } +/* +** Implementation of the sqlite_log() function. This is a wrapper around +** sqlite3_log(). The return value is NULL. The function exists purely for +** its side-effects. +*/ +static void logFunc( + sqlite3_context *context, + int argc, + sqlite3_value **argv +){ + UNUSED_PARAMETER(argc); + UNUSED_PARAMETER(context); + sqlite3_log(sqlite3_value_int(argv[0]), "%s", sqlite3_value_text(argv[1])); +} + /* ** Implementation of the sqlite_compileoption_used() function. ** The result is an integer that identifies if the compiler option @@ -1541,6 +1556,7 @@ void sqlite3RegisterGlobalFunctions(void){ FUNCTION(nullif, 2, 0, 1, nullifFunc ), FUNCTION(sqlite_version, 0, 0, 0, versionFunc ), FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), + FUNCTION(sqlite_log, 2, 0, 0, logFunc ), #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ), FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), From 53a9d15826ea9c0513a167585264437f805fa4ce Mon Sep 17 00:00:00 2001 From: drh Date: Mon, 25 Apr 2011 18:20:04 +0000 Subject: [PATCH 5/9] Test case for the ".log" command to the command-line shell. FossilOrigin-Name: 7d0ff26a95cb1e9fcace4641245dda787f3522b4 --- manifest | 12 ++++++------ manifest.uuid | 2 +- tool/shell1.test | 5 +++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 3f91515d1b..cca88e6f6d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sthe\s(deliberately\sundocumented)\ssqlite_log()\sSQL\sfunction\sas\sa\sbuilt-in. -D 2011-04-25T18:03:10.263 +C Test\scase\sfor\sthe\s".log"\scommand\sto\sthe\scommand-line\sshell. +D 2011-04-25T18:20:04.278 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -912,7 +912,7 @@ F tool/omittest.tcl b1dd290c1596e0f31fd335160a74ec5dfea3df4a F tool/opcodeDoc.awk b3a2a3d5d3075b8bd90b7afe24283efdd586659c F tool/restore_jrnl.tcl 6957a34f8f1f0f8285e07536225ec3b292a9024a F tool/rollback-test.c 9fc98427d1e23e84429d7e6d07d9094fbdec65a5 -F tool/shell1.test fee04fce1bf55e6e081523545fd4e0e83490ff8e +F tool/shell1.test 44705d6078b37f58853005d2ad5f1e67bc9dbbed F tool/shell2.test 5dc76b8005b465f420fed8241621da7513060ff3 F tool/shell3.test 4fad469e8003938426355afdf34155f08c587836 F tool/shell4.test 35f9c3d452b4e76d5013c63e1fd07478a62f14ce @@ -930,7 +930,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 4c7ff4dd352276e9c01cc536e188cbcd69396952 -R 02826977cda64533dcdcab57c0092168 +P f7806e03995b314771aa72a08ce55d56d60096cf +R 90125b981bcf635951ddc9b0441cae0d U drh -Z ae88889f134cbeb0e55dabbab9faed47 +Z da6f87ac8d880cc9cef1dbf3763cd407 diff --git a/manifest.uuid b/manifest.uuid index 428479b63d..6f42c53a3b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f7806e03995b314771aa72a08ce55d56d60096cf \ No newline at end of file +7d0ff26a95cb1e9fcace4641245dda787f3522b4 \ No newline at end of file diff --git a/tool/shell1.test b/tool/shell1.test index 6980dab219..d066fc3c1a 100644 --- a/tool/shell1.test +++ b/tool/shell1.test @@ -711,4 +711,9 @@ do_test shell1-3.27.4 { catchcmd "test.db" ".timer OFF BAD" } {1 {Error: unknown command or invalid arguments: "timer". Enter ".help" for help}} +do_test shell1-3-28.1 { + catchcmd test.db \ + ".log stdout\nSELECT coalesce(sqlite_log(123,'hello'),'456');" +} "0 {(123) hello\n456}" + puts "CLI tests completed successfully" From 5275d2ee6315eeb5b3ffa3c2569607d001cfd5cc Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Apr 2011 01:00:17 +0000 Subject: [PATCH 6/9] Fix a comment typo. FossilOrigin-Name: 19c6625abd5b4e6a4406a8e421ae22527529e305 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbeaux.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index cca88e6f6d..fb51f7cc4a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Test\scase\sfor\sthe\s".log"\scommand\sto\sthe\scommand-line\sshell. -D 2011-04-25T18:20:04.278 +C Fix\sa\scomment\stypo. +D 2011-04-27T01:00:17.858 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -239,7 +239,7 @@ F src/vdbe.c 05deeec6659f2579674a5e6510b3ada2a442f8d5 F src/vdbe.h 8a675fefdf7119441fe817c800a9a52440c2e797 F src/vdbeInt.h fe8f58d305e629fff02f61f655aca1d299f1f6ae F src/vdbeapi.c e0e2672e0a96ae3f8575c8ecd02912a3e8a554a1 -F src/vdbeaux.c 9ae5074b19bdff2d8806a278533956fb281510d5 +F src/vdbeaux.c 5b8150112b490360fdf46f62f470a2ef75b0480a F src/vdbeblob.c c3ccb7c8732858c680f442932e66ad06bb036562 F src/vdbemem.c 0498796b6ffbe45e32960d6a1f5adfb6e419883b F src/vdbetrace.c 5d0dc3d5fd54878cc8d6d28eb41deb8d5885b114 @@ -930,7 +930,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P f7806e03995b314771aa72a08ce55d56d60096cf -R 90125b981bcf635951ddc9b0441cae0d +P 7d0ff26a95cb1e9fcace4641245dda787f3522b4 +R d24ac9411a98171848004eba2e415ab8 U drh -Z da6f87ac8d880cc9cef1dbf3763cd407 +Z 23b5de7727bb069a870fe57a3628ffd6 diff --git a/manifest.uuid b/manifest.uuid index 6f42c53a3b..4c573a5e04 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7d0ff26a95cb1e9fcace4641245dda787f3522b4 \ No newline at end of file +19c6625abd5b4e6a4406a8e421ae22527529e305 \ No newline at end of file diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 4d4bb224f9..b594e13277 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -2929,7 +2929,7 @@ int sqlite3VdbeRecordCompare( /* Compilers may complain that mem1.u.i is potentially uninitialized. ** We could initialize it, as shown here, to silence those complaints. - ** But in fact, mem1.u.i will never actually be used initialized, and doing + ** But in fact, mem1.u.i will never actually be used uninitialized, and doing ** the unnecessary initialization has a measurable negative performance ** impact, since this routine is a very high runner. And so, we choose ** to ignore the compiler warnings and leave this variable uninitialized. From 5b92f192d9dcba108532d62488d8ce49330b85d5 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Apr 2011 16:05:42 +0000 Subject: [PATCH 7/9] Expose the UTF8 to MBCS conversion routine in os_win.c to external applications. FossilOrigin-Name: 7b479b9bee93df909edecd44c7d6584d943b39c9 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_win.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index fb51f7cc4a..b4059728e0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\scomment\stypo. -D 2011-04-27T01:00:17.858 +C Expose\sthe\sUTF8\sto\sMBCS\sconversion\sroutine\sin\sos_win.c\sto\sexternal\napplications. +D 2011-04-27T16:05:42.346 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -163,7 +163,7 @@ F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9 F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440 F src/os_unix.c 2c67d126874b78eb427371db4793f0e8fbc7448b -F src/os_win.c d149b9a7dfdd38de09afc054f8168cd3cd80630b +F src/os_win.c 0d2fb750f74e403b40286fd500882dcea93db275 F src/pager.c 055239dcdfe12b3f5d97f6f01f85da01e2d6d912 F src/pager.h 3f8c783de1d4706b40b1ac15b64f5f896bcc78d1 F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58 @@ -930,7 +930,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 7d0ff26a95cb1e9fcace4641245dda787f3522b4 -R d24ac9411a98171848004eba2e415ab8 +P 19c6625abd5b4e6a4406a8e421ae22527529e305 +R fcd8fa82794547de86a43c56e868f9a6 U drh -Z 23b5de7727bb069a870fe57a3628ffd6 +Z f1379103c390c9054c004f3716fc6621 diff --git a/manifest.uuid b/manifest.uuid index 4c573a5e04..5cdcab0b2d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -19c6625abd5b4e6a4406a8e421ae22527529e305 \ No newline at end of file +7b479b9bee93df909edecd44c7d6584d943b39c9 \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 654a964468..cd7a69bce0 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -286,7 +286,7 @@ char *sqlite3_win32_mbcs_to_utf8(const char *zFilename){ ** Convert UTF-8 to multibyte character string. Space to hold the ** returned string is obtained from malloc(). */ -static char *utf8ToMbcs(const char *zFilename){ +char *sqlite3_win32_utf8_to_mbcs(const char *zFilename){ char *zFilenameMbcs; WCHAR *zTmpWide; @@ -2004,7 +2004,7 @@ static void *convertUtf8Filename(const char *zFilename){ */ #if SQLITE_OS_WINCE==0 }else{ - zConverted = utf8ToMbcs(zFilename); + zConverted = sqlite3_win32_utf8_to_mbcs(zFilename); #endif } /* caller will handle out of memory */ From 840561f2a4972438f4f867b86285efcda7353454 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Apr 2011 18:08:42 +0000 Subject: [PATCH 8/9] Change the name of an internal function to avoid conflicts with the math library. FossilOrigin-Name: 1bd1484cd7e09709d87aa84b82e87597d00a4162 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/func.c | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index b4059728e0..33d8213904 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Expose\sthe\sUTF8\sto\sMBCS\sconversion\sroutine\sin\sos_win.c\sto\sexternal\napplications. -D 2011-04-27T16:05:42.346 +C Change\sthe\sname\sof\san\sinternal\sfunction\sto\savoid\sconflicts\swith\sthe\smath\nlibrary. +D 2011-04-27T18:08:42.071 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -133,7 +133,7 @@ F src/delete.c 7a24fcc9a31664d145acb97ce56b6d9f249a25e4 F src/expr.c e3cf0957c6b8faaaf7386a3bc69e53c0dc9705be F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c a43ba8a005fb5efd1deeee06853e3a6120d46a91 -F src/func.c 6d907d397c9e6eded680f8946499efdf224d34bd +F src/func.c b9117e40975245b8504cf3625d7e321d8d4b63dc F src/global.c 02335177cf6946fe5525c6f0755cf181140debf3 F src/hash.c 458488dcc159c301b8e7686280ab209f1fb915af F src/hash.h 2894c932d84d9f892d4b4023a75e501f83050970 @@ -930,7 +930,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 19c6625abd5b4e6a4406a8e421ae22527529e305 -R fcd8fa82794547de86a43c56e868f9a6 +P 7b479b9bee93df909edecd44c7d6584d943b39c9 +R 896972878681caa8688ae0b699a33ade U drh -Z f1379103c390c9054c004f3716fc6621 +Z 901a5c52f94c833aabdd9b6dd2fd3b65 diff --git a/manifest.uuid b/manifest.uuid index 5cdcab0b2d..f22bfc0a4d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7b479b9bee93df909edecd44c7d6584d943b39c9 \ No newline at end of file +1bd1484cd7e09709d87aa84b82e87597d00a4162 \ No newline at end of file diff --git a/src/func.c b/src/func.c index e75fa47e7a..0b9b600d79 100644 --- a/src/func.c +++ b/src/func.c @@ -779,7 +779,7 @@ static void sourceidFunc( ** sqlite3_log(). The return value is NULL. The function exists purely for ** its side-effects. */ -static void logFunc( +static void errlogFunc( sqlite3_context *context, int argc, sqlite3_value **argv @@ -1556,7 +1556,7 @@ void sqlite3RegisterGlobalFunctions(void){ FUNCTION(nullif, 2, 0, 1, nullifFunc ), FUNCTION(sqlite_version, 0, 0, 0, versionFunc ), FUNCTION(sqlite_source_id, 0, 0, 0, sourceidFunc ), - FUNCTION(sqlite_log, 2, 0, 0, logFunc ), + FUNCTION(sqlite_log, 2, 0, 0, errlogFunc ), #ifndef SQLITE_OMIT_COMPILEOPTION_DIAGS FUNCTION(sqlite_compileoption_used,1, 0, 0, compileoptionusedFunc ), FUNCTION(sqlite_compileoption_get, 1, 0, 0, compileoptiongetFunc ), From 4d953fd5b167908d16ede9f41a29087e98d57dc8 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Apr 2011 19:54:44 +0000 Subject: [PATCH 9/9] In windows, ignore ERROR_NOT_LOCKED when calling the read-lock removal routine. FossilOrigin-Name: f55156c5194e85c47728b8a97fde3e5f0a5c9b56 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/os_win.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 33d8213904..51018c9381 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Change\sthe\sname\sof\san\sinternal\sfunction\sto\savoid\sconflicts\swith\sthe\smath\nlibrary. -D 2011-04-27T18:08:42.071 +C In\swindows,\signore\sERROR_NOT_LOCKED\swhen\scalling\sthe\sread-lock\sremoval\nroutine. +D 2011-04-27T19:54:44.305 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 7a4d9524721d40ef9ee26f93f9bd6a51dba106f2 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -163,7 +163,7 @@ F src/os.h 9dbed8c2b9c1f2f2ebabc09e49829d4777c26bf9 F src/os_common.h a8f95b81eca8a1ab8593d23e94f8a35f35d4078f F src/os_os2.c 4a75888ba3dfc820ad5e8177025972d74d7f2440 F src/os_unix.c 2c67d126874b78eb427371db4793f0e8fbc7448b -F src/os_win.c 0d2fb750f74e403b40286fd500882dcea93db275 +F src/os_win.c 4271f0bf733c0b45635ddcfb41c935573de8284c F src/pager.c 055239dcdfe12b3f5d97f6f01f85da01e2d6d912 F src/pager.h 3f8c783de1d4706b40b1ac15b64f5f896bcc78d1 F src/parse.y 12b7ebd61ea54f0e1b1083ff69cc2c8ce9353d58 @@ -930,7 +930,7 @@ F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/split-sqlite3c.tcl d9be87f1c340285a3e081eb19b4a247981ed290c F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 7b479b9bee93df909edecd44c7d6584d943b39c9 -R 896972878681caa8688ae0b699a33ade +P 1bd1484cd7e09709d87aa84b82e87597d00a4162 +R 9628f97d1cf37de85ec8d2f9df941216 U drh -Z 901a5c52f94c833aabdd9b6dd2fd3b65 +Z cb18bd6131d197c3ee5b628d2860f479 diff --git a/manifest.uuid b/manifest.uuid index f22bfc0a4d..68e76d018c 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1bd1484cd7e09709d87aa84b82e87597d00a4162 \ No newline at end of file +f55156c5194e85c47728b8a97fde3e5f0a5c9b56 \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index cd7a69bce0..4e91f7ab32 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -1052,7 +1052,7 @@ static int unlockReadLock(winFile *pFile){ res = UnlockFile(pFile->h, SHARED_FIRST + pFile->sharedLockByte, 0, 1, 0); #endif } - if( res == 0 ){ + if( res==0 && GetLastError()!=ERROR_NOT_LOCKED ){ pFile->lastErrno = GetLastError(); winLogError(SQLITE_IOERR_UNLOCK, "unlockReadLock", pFile->zPath); }