]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix the columnar output modes in the CLI so that they work with parameters.
authordrh <drh@noemail.net>
Thu, 6 Aug 2020 16:45:22 +0000 (16:45 +0000)
committerdrh <drh@noemail.net>
Thu, 6 Aug 2020 16:45:22 +0000 (16:45 +0000)
See [https://sqlite.org/forum/forumpost/17ba6aac24] for details of the
problem fixed.

FossilOrigin-Name: d573aa9b1299bc25e46fc8a4b4f7c665263490db86c66f11e2d903dcd7071995

manifest
manifest.uuid
src/shell.c.in

index 1dd48007795b1d134d85693e00a5a19f6551b09e..ae81ad9289e404b14f9c97dd92d251d74abc8615 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Back\sout\sa\sNEVER()\sthat\sturns\sout\sto\sbe\sreachable.
-D 2020-07-31T23:34:53.477
+C Fix\sthe\scolumnar\soutput\smodes\sin\sthe\sCLI\sso\sthat\sthey\swork\swith\sparameters.\nSee\s[https://sqlite.org/forum/forumpost/17ba6aac24]\sfor\sdetails\sof\sthe\nproblem\sfixed.
+D 2020-08-06T16:45:22.355
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -536,7 +536,7 @@ F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
 F src/resolve.c 2dd6821aac2cd27de9fcf6aa6d1f8c41b4b5841c9bc58bf1c9109008009a3a2e
 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
 F src/select.c d977d463bdeb9be4bec16829c7c2c6193330bf0962bfdf23113e8f6ba548cd86
-F src/shell.c.in 352a0a6399ccae40a30f72ea06f52f3791a062bde9b8929a97f345e1584ba310
+F src/shell.c.in 889c7235f1a7a9139ee3a069d4db7e5499958df04fb2048c86b816c3ab94d46e
 F src/sqlite.h.in d2c03414a8ee5d4a6855c04dd7cd5998e45139b0fe66b65bae86d4223edd091f
 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
 F src/sqlite3ext.h 2d1af80082edffd71c6f96f70ad1ce6a4fb46615ad10291fc77fe0dea9ff0197
@@ -1879,7 +1879,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 12bb75d9edc4c11de58d8b1105b95366c58ac4daaa9ad659499dded89a0d7cb5
-R ec32fd21b67eba4dfa0bc1bd617b932c
+P 8cf342d4e5eb67b17aee595d9d75f7798eccaebc1ec88e646d344d8d4ab64977
+R aa3df3bdbe9cc494e95acc400ec796e1
 U drh
-Z b679f04324fcd77ac82962da751a9b3c
+Z 3ebb4b63c036480a822fc2485a6f6aae
index 5fb532c11f8e5b89d146a352c0b8c2b40aff3994..9f6e977aca2c1ca8e0ec0d8eb81699fe12db144e 100644 (file)
@@ -1 +1 @@
-8cf342d4e5eb67b17aee595d9d75f7798eccaebc1ec88e646d344d8d4ab64977
\ No newline at end of file
+d573aa9b1299bc25e46fc8a4b4f7c665263490db86c66f11e2d903dcd7071995
\ No newline at end of file
index ee0bc82beca1b09103509d895869644a19fa6523..562da927de41cf90d4d153e4439fb2c2ddfe9c6f 100644 (file)
@@ -3051,25 +3051,38 @@ static void exec_prepared_stmt_columnar(
   ShellState *p,                        /* Pointer to ShellState */
   sqlite3_stmt *pStmt                   /* Statment to run */
 ){
-  int nRow = 0;
+  sqlite3_int64 nRow = 0;
   int nColumn = 0;
   char **azData = 0;
-  char *zMsg = 0;
+  sqlite3_int64 nAlloc = 0;
   const char *z;
   int rc;
-  int i, j, nTotal, w, n;
+  sqlite3_int64 i, nData;
+  int j, nTotal, w, n;
   const char *colSep = 0;
   const char *rowSep = 0;
 
-  rc = sqlite3_get_table(p->db, sqlite3_sql(pStmt),
-                         &azData, &nRow, &nColumn, &zMsg);
-  if( rc ){
-    utf8_printf(p->out, "ERROR: %s\n", zMsg);
-    sqlite3_free(zMsg);
-    sqlite3_free_table(azData);
-    return;
+  rc = sqlite3_step(pStmt);
+  if( rc!=SQLITE_ROW ) return;
+  nColumn = sqlite3_column_count(pStmt);
+  nAlloc = nColumn*4;
+  azData = sqlite3_malloc64( nAlloc*sizeof(char*) );
+  if( azData==0 ) shell_out_of_memory();
+  for(i=0; i<nColumn; i++){
+    azData[i] = strdup(sqlite3_column_name(pStmt,i));
   }
-  if( nRow==0 || nColumn==0 ) goto columnar_end;
+  do{
+    if( (nRow+2)*nColumn >= nAlloc ){
+      nAlloc *= 2;
+      azData = sqlite3_realloc64(azData, nAlloc*sizeof(char*));
+      if( azData==0 ) shell_out_of_memory();
+    }
+    nRow++;
+    for(i=0; i<nColumn; i++){
+      z = (const char*)sqlite3_column_text(pStmt,i);
+      azData[nRow*nColumn + i] = z ? strdup(z) : 0;
+    }
+  }while( (rc = sqlite3_step(pStmt))==SQLITE_ROW );
   if( nColumn>p->nWidth ){
     p->colWidth = realloc(p->colWidth, nColumn*2*sizeof(int));
     if( p->colWidth==0 ) shell_out_of_memory();
@@ -3179,7 +3192,9 @@ columnar_end:
   if( seenInterrupt ){
     utf8_printf(p->out, "Interrupt\n");
   }
-  sqlite3_free_table(azData);
+  nData = (nRow+1)*nColumn;
+  for(i=0; i<nData; i++) free(azData[i]);
+  sqlite3_free(azData);
 }
 
 /*