From: danielk1977 Date: Sat, 5 Jun 2004 08:04:36 +0000 (+0000) Subject: Ensure blob values survive the ".dump" command of the shell. (CVS 1531) X-Git-Tag: version-3.6.10~4544 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2a02e339507e6a299002f30779de27f1da236a17;p=thirdparty%2Fsqlite.git Ensure blob values survive the ".dump" command of the shell. (CVS 1531) FossilOrigin-Name: e82eb722b0e0b223ddaf7d85669792c33594f9da --- diff --git a/main.mk b/main.mk index 8e96034491..f884cdd191 100644 --- a/main.mk +++ b/main.mk @@ -60,7 +60,7 @@ LIBOBJ = attach.o auth.o btree.o build.o date.o delete.o \ pager.o parse.o pragma.o printf.o random.o \ select.o table.o tokenize.o trigger.o update.o util.o vacuum.o \ vdbe.o vdbeapi.o vdbeaux.o vdbemem.o \ - where.o tclsqlite.o utf.o legacy.o + where.o utf.o legacy.o # All of the source code files. # diff --git a/manifest b/manifest index 2aba33a84f..21bb3f0fa9 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Critical\sbugs\sfixed\sin\sbtree.c.\s\sIncompatible\sfile\sformat\schange.\s\sUnrelated\ncomment\sfix\sin\sselect.c\s(CVS\s1530) -D 2004-06-05T00:01:45 +C Ensure\sblob\svalues\ssurvive\sthe\s".dump"\scommand\sof\sthe\sshell.\s(CVS\s1531) +D 2004-06-05T08:04:36 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd @@ -16,7 +16,7 @@ F doc/lemon.html f0f682f50210928c07e562621c3b7e8ab912a538 F doc/report1.txt a031aaf37b185e4fa540223cb516d3bccec7eeac F install-sh 9d4de14ab9fb0facae2f48780b874848cbf2f895 F ltmain.sh f6b283068efa69f06eb8aa1fe4bddfdbdeb35826 -F main.mk b717f9861a3acdd3a4e81fc59731a393bf6a0c6e +F main.mk 126f1ca2190fa19cc9944f54943cf3431891c330 F mkdll.sh 68d34a961a1fdfa15ef27fc4f4740be583112124 F publish.sh 2e579b7474d57b6debcead93c73a49eb8cb81718 F spec.template a38492f1c1dd349fc24cb0565e08afc53045304b @@ -45,7 +45,7 @@ F src/os_mac.c b823874690615ace0dd520d3ad1fe8bfd864b7e0 F src/os_mac.h 51d2445f47e182ed32d3bd6937f81070c6fd9bd4 F src/os_unix.c a4feb70b23fa5272f53cd2c74588484b54294800 F src/os_unix.h 7999f2246c6347707e98f7078871ea8ca605df3f -F src/os_win.c 92b51a38437b98d8aa3ac05b57c71e1d1092e5be +F src/os_win.c 0f895f0491a983740c08af8e5d1986f3bc4629a4 F src/os_win.h 5d41af24caaef6c13a2d8e2399caa1c57d45c84d F src/pager.c 944f6b071279887574081281f27bb2af88b42905 F src/pager.h 0c7b5ac45c69e690c45d160d03bdc8fbd2d4657b @@ -54,7 +54,7 @@ F src/pragma.c 1b58d852b84b36a8b84e2245dd29b63c377414ec F src/printf.c ef750e8e2398ca7e8b58be991075f08c6a7f0e53 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3 F src/select.c 02d711160100ef3a730060f7cfb5bc85fde06d72 -F src/shell.c a9e2ad8f6c1d39b04bad61a0ec655e9a3a360b50 +F src/shell.c 79af86d39b2149c7f16219fcbe636e7c2da9df8e F src/sqlite.h.in 8236db65bc6d8f5f47dc5a5e86c4a9bce42f2adf F src/sqliteInt.h 99f2b4ff4ed28123890a0c71359fec3d2c5901c9 F src/table.c af14284fa36c8d41f6829e3f2819dce07d3e2de2 @@ -215,7 +215,7 @@ F www/support.tcl 1801397edd271cc39a2aadd54e701184b5181248 F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 -P d2f69e5ef2f261a00bb8427a4e2a1638ecfd17a9 -R eb52d3018295ee3de4004fb563723044 -U drh -Z ceec225131100608a50f7e5d2660779f +P cb1ffabf86996ab20dfffcb5f133fa9a9b56bbe2 +R ea7bd988d55c4ea96c95b0dedf76ecab +U danielk1977 +Z 4e22795b8cf7e800bcb3f1d60cd6c40a diff --git a/manifest.uuid b/manifest.uuid index 339a01ecd9..81c71f85e5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cb1ffabf86996ab20dfffcb5f133fa9a9b56bbe2 \ No newline at end of file +e82eb722b0e0b223ddaf7d85669792c33594f9da \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 9c21f7cd08..af45a06b50 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -370,6 +370,14 @@ int isNT(void){ #define N_LOCKBYTE 10239 #define FIRST_LOCKBYTE (0xffffffff - N_LOCKBYTE) +int sqlite3OsLock(OsFile *id, int locktype){ + return SQLITE_OK; +} + +int sqlite3OsCheckWriteLock(OsFile *id){ + return 0; +} + /* ** Change the status of the lock on the file "id" to be a readlock. ** If the file was write locked, then this reduces the lock to a read. diff --git a/src/shell.c b/src/shell.c index 0d69ac7c69..84efe0518a 100644 --- a/src/shell.c +++ b/src/shell.c @@ -12,11 +12,12 @@ ** This file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. ** -** $Id: shell.c,v 1.101 2004/05/31 23:56:43 danielk1977 Exp $ +** $Id: shell.c,v 1.102 2004/06/05 08:04:44 danielk1977 Exp $ */ #include #include #include +#include #include "sqlite3.h" #include @@ -444,6 +445,125 @@ static void set_table_name(struct callback_data *p, const char *zName){ z[n] = 0; } +/* zIn is either a pointer to a NULL-terminated string in memory obtained +** from malloc(), or a NULL pointer. The string pointed to by zAppend is +** added to zIn, and the result returned in memory obtained from malloc(). +** zIn, if it was not NULL, is freed. +** +** If the third argument, quote, is not '\0', then it is used as a +** quote character for zAppend. +*/ +static char * appendText(char *zIn, char const *zAppend, char quote){ + int len; + int i; + int nAppend = strlen(zAppend); + int nIn = (zIn?strlen(zIn):0); + + len = nAppend+nIn+1; + if( quote ){ + len += 2; + for(i=0; i>4)&0x0F]; + zText[(i*2)+3] = hexdigits[(zBlob[i])&0x0F]; + } + zText[(nBlob*2)+2] = '\''; + zText[(nBlob*2)+3] = '\0'; + zText[0] = 'X'; + zText[1] = '\''; + sqlite3_result_text(context, zText, -1, 1); + free(zText); + } + break; + } + } +} + /* ** This is a different callback routine used for dumping the database. ** Each row received by this callback consists of a table name, @@ -451,21 +571,78 @@ static void set_table_name(struct callback_data *p, const char *zName){ ** This routine should print text sufficient to recreate the table. */ static int dump_callback(void *pArg, int nArg, char **azArg, char **azCol){ + int rc; + const char *zTable; + const char *zType; + const char *zSql; struct callback_data *p = (struct callback_data *)pArg; + if( nArg!=3 ) return 1; - fprintf(p->out, "%s;\n", azArg[2]); - if( strcmp(azArg[1],"table")==0 ){ - struct callback_data d2; - d2 = *p; - d2.mode = MODE_Insert; - d2.zDestTable = 0; - set_table_name(&d2, azArg[0]); - sqlite3_exec_printf(p->db, - "SELECT * FROM '%q'", - callback, &d2, 0, azArg[0] - ); - set_table_name(&d2, 0); + zTable = azArg[0]; + zType = azArg[1]; + zSql = azArg[2]; + + fprintf(p->out, "%s;\n", zSql); + + if( strcmp(zType, "table")==0 ){ + sqlite3_stmt *pTableInfo = 0; + sqlite3_stmt *pSelect = 0; + char *zSelect = 0; + char *zTableInfo = 0; + char *zTmp = 0; + + zTableInfo = appendText(zTableInfo, "PRAGMA table_info(", 0); + zTableInfo = appendText(zTableInfo, zTable, '"'); + zTableInfo = appendText(zTableInfo, ");", 0); + + rc = sqlite3_prepare(p->db, zTableInfo, -1, &pTableInfo, 0); + if( zTableInfo ) free(zTableInfo); + if( rc!=SQLITE_OK || !pTableInfo ){ + return 1; + } + + zSelect = appendText(zSelect, "SELECT 'INSERT INTO ' || ", 0); + zTmp = appendText(zTmp, zTable, '"'); + if( zTmp ){ + zSelect = appendText(zSelect, zTmp, '\''); + } + zSelect = appendText(zSelect, " || ' VALUES(' || ", 0); + rc = sqlite3_step(pTableInfo); + while( rc==SQLITE_ROW ){ + zSelect = appendText(zSelect, "dump_literal(", 0); + zSelect = appendText(zSelect, sqlite3_column_text(pTableInfo, 1), '"'); + rc = sqlite3_step(pTableInfo); + if( rc==SQLITE_ROW ){ + zSelect = appendText(zSelect, ") || ', ' || ", 0); + }else{ + zSelect = appendText(zSelect, ") ", 0); + } + } + rc = sqlite3_finalize(pTableInfo); + if( rc!=SQLITE_OK ){ + if( zSelect ) free(zSelect); + return 1; + } + zSelect = appendText(zSelect, "|| ')' FROM ", 0); + zSelect = appendText(zSelect, zTable, '"'); + + rc = sqlite3_prepare(p->db, zSelect, -1, &pSelect, 0); + if( zSelect ) free(zSelect); + if( rc!=SQLITE_OK || !pSelect ){ + return 1; + } + + rc = sqlite3_step(pSelect); + while( rc==SQLITE_ROW ){ + fprintf(p->out, "%s;\n", sqlite3_column_text(pSelect, 0)); + rc = sqlite3_step(pSelect); + } + rc = sqlite3_finalize(pSelect); + if( rc!=SQLITE_OK ){ + return 1; + } } + return 0; } @@ -523,6 +700,9 @@ static void open_db(struct callback_data *p){ p->zDbFilename, sqlite3_errmsg(db)); exit(1); } + + /* Add the 'dump_literal' SQL function used by .dump */ + sqlite3_create_function(db,"dump_literal",1,0,0,0,dump_literalFunc,0,0); } } @@ -1063,7 +1243,7 @@ static void process_input(struct callback_data *p, FILE *in){ sqlite3_free(zErrMsg); zErrMsg = 0; }else{ - printf("SQL error: %s\n", sqlite3ErrStr(rc)); + printf("SQL error: %s\n", sqlite3_errmsg(p->db)); } } free(zSql);