]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Added %Q format specifier: like %q but automatic enclosing in
authorchw <chw@noemail.net>
Sun, 16 Jun 2002 04:55:48 +0000 (04:55 +0000)
committerchw <chw@noemail.net>
Sun, 16 Jun 2002 04:55:48 +0000 (04:55 +0000)
single quotes, NULL pointers replaced by NULL w/o single-quotes. (CVS 621)

FossilOrigin-Name: b9c7ecc2f9d8d7d57c51dc4ba0aaa520e89eb31f

manifest
manifest.uuid
src/printf.c

index c8782b8af79d9d9691929b3b32b5ee71eebe1bd7..aa89e0b24b0200cc4d67273efc4f3c0897cc8348 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Changed\ssqlite_mprintf_str\sto\sallow\sa\sNULL\sstring\sparameter.\nCommand\stemplate\snow\sis\scmd\sFORMAT\sINT\sINT\s?STRING?.\sWhen\nSTRING\somitted\sa\sNULL\sis\spassed\sto\ssqlite_mprintf.\s(CVS\s620)
-D 2002-06-16T04:54:29
+C Added\s%Q\sformat\sspecifier:\slike\s%q\sbut\sautomatic\senclosing\sin\nsingle\squotes,\sNULL\spointers\sreplaced\sby\sNULL\sw/o\ssingle-quotes.\s(CVS\s621)
+D 2002-06-16T04:55:48
 F Makefile.in 6291a33b87d2a395aafd7646ee1ed562c6f2c28c
 F Makefile.template 4e11752e0b5c7a043ca50af4296ec562857ba495
 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
@@ -35,7 +35,7 @@ F src/os.h 4a361fccfbc4e7609b3e1557f604f94c1e96ad10
 F src/pager.c 1e41053c949cea1f09d8dafada5fe8f90785e650
 F src/pager.h 6fddfddd3b73aa8abc081b973886320e3c614f0e
 F src/parse.y 42920305d49666419358b469e4ec522ac867a39f
-F src/printf.c d8032ee18b860c812eeff596c9bebfdacb7930fd
+F src/printf.c 236ed7a79386feed4456fa728fff8be793f1547c
 F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
 F src/select.c 6c3a92d7a0bdf3448265d530cc0e6f6e5a764997
 F src/shell.c 1d22fe870ee852cfb975fd000dbe3973713d0a15
@@ -137,7 +137,7 @@ F www/speed.tcl da8afcc1d3ccc5696cfb388a68982bc3d9f7f00f
 F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 699cf362083043615eb88635a228bfa46a315c9c
-R e8c65548643704a0ca06e48f56b72d31
+P 8bc711571d752a81957007be22ed8a3c6877f676
+R b88f44ec684ed6abc5b7b24fd62abad4
 U chw
-Z d2eb26e5d1d3f143fd19e7582867015a
+Z fa4085981e2ff6e4da01d48425d29821
index a9fb9dc673e56d68d55ee3e69decd41b5c962231..b2dd20c55df2e031bce756cd08ad5b5abad0cb8b 100644 (file)
@@ -1 +1 @@
-8bc711571d752a81957007be22ed8a3c6877f676
\ No newline at end of file
+b9c7ecc2f9d8d7d57c51dc4ba0aaa520e89eb31f
\ No newline at end of file
index 8cc511a071d11162b41e8b1438b083eb75655414..827b7bbcb90499844bb7e8571173cb6eb711fa18 100644 (file)
@@ -72,6 +72,8 @@ enum et_type {    /* The type of the format field */
 /* The rest are extensions, not normally found in printf() */
    etCHARLIT,          /* Literal characters.  %' */
    etSQLESCAPE,        /* Strings with '\'' doubled.  %q */
+   etSQLESCAPE2,       /* Strings with '\'' doubled and enclosed in '',
+                          NULL pointers replaced by SQL NULL.  %Q */
    etORDINAL           /* 1st, 2nd, 3rd and so forth */
 };
 
@@ -96,6 +98,7 @@ static et_info fmtinfo[] = {
   { 'd',  10,  "0123456789",       1,    0, etRADIX,      },
   { 's',   0,  0,                  0,    0, etSTRING,     }, 
   { 'q',   0,  0,                  0,    0, etSQLESCAPE,  },
+  { 'Q',   0,  0,                  0,    0, etSQLESCAPE2, },
   { 'c',   0,  0,                  0,    0, etCHARX,      },
   { 'o',   8,  "01234567",         0,  "0", etRADIX,      },
   { 'u',  10,  "0123456789",       0,    0, etRADIX,      },
@@ -553,24 +556,29 @@ static int vxprintf(
         if( precision>=0 && precision<length ) length = precision;
         break;
       case etSQLESCAPE:
+      case etSQLESCAPE2:
         {
-          int i, j, n, c;
+          int i, j, n, c, isnull;
           char *arg = va_arg(ap,char*);
-          if( arg==0 ) arg = "(NULL)";
+          isnull = arg==0;
+          if( isnull ) arg = (xtype==etSQLESCAPE2 ? "NULL" : "(NULL)");
           for(i=n=0; (c=arg[i])!=0; i++){
             if( c=='\'' )  n++;
           }
-          n += i + 1;
+          n += i + 1 + ((!isnull && xtype==etSQLESCAPE2) ? 2 : 0);
           if( n>etBUFSIZE ){
             bufpt = zExtra = sqliteMalloc( n );
             if( bufpt==0 ) return -1;
           }else{
             bufpt = buf;
           }
-          for(i=j=0; (c=arg[i])!=0; i++){
+          j = 0;
+          if( !isnull && xtype==etSQLESCAPE2 ) bufpt[j++] = '\'';
+          for(i=0; (c=arg[i])!=0; i++){
             bufpt[j++] = c;
             if( c=='\'' ) bufpt[j++] = c;
           }
+          if( !isnull && xtype==etSQLESCAPE2 ) bufpt[j++] = '\'';
           bufpt[j] = 0;
           length = j;
           if( precision>=0 && precision<length ) length = precision;