");
- for (i = 0; i < nArg; i++)
- {
- fprintf(p.Out, "| ");
- output_html_string(p.Out, azArg[i] != null ? azArg[i] : p.nullvalue);
- fprintf(p.Out, " | \n");
- }
- fprintf(p.Out, "
\n");
- break;
- }
- case MODE_Tcl:
- {
- if (p.cnt++ == null && p.showHeader)
- {
- for (i = 0; i < nArg; i++)
- {
- output_c_string(p.Out, azCol[i] != null ? azCol[i] : "");
- fprintf(p.Out, "%s", p.separator);
- }
- fprintf(p.Out, "\n");
- }
- if (azArg == null)
- break;
- for (i = 0; i < nArg; i++)
- {
- output_c_string(p.Out, azArg[i] != null ? azArg[i] : p.nullvalue);
- fprintf(p.Out, "%s", p.separator);
- }
- fprintf(p.Out, "\n");
- break;
- }
- case MODE_Csv:
- {
- if (p.cnt++ == null && p.showHeader)
- {
- for (i = 0; i < nArg; i++)
- {
- output_csv(p, azCol[i] != null ? azCol[i] : "", i < nArg - 1);
- }
- fprintf(p.Out, "\n");
- }
- if (azArg == null)
- break;
- for (i = 0; i < nArg; i++)
- {
- output_csv(p, azArg[i], i < nArg - 1);
- }
- fprintf(p.Out, "\n");
- break;
- }
- case MODE_Insert:
- {
- p.cnt++;
- if (azArg == null)
- break;
- fprintf(p.Out, "INSERT INTO %s VALUES(", p.zDestTable);
- for (i = 0; i < nArg; i++)
- {
- string zSep = i > 0 ? "," : "";
- if ((azArg[i] == null) || (aiType != null && i < aiType.Length && aiType[i] == Sqlite3.SQLITE_NULL))
- {
- fprintf(p.Out, "%snull", zSep);
- }
- else if (aiType != null && aiType[i] == Sqlite3.SQLITE_TEXT)
- {
- if (!String.IsNullOrEmpty(zSep))
- fprintf(p.Out, "%s", zSep);
- output_quoted_string(p.Out, azArg[i]);
- }
- else if (aiType != null && (aiType[i] == Sqlite3.SQLITE_INTEGER || aiType[i] == Sqlite3.SQLITE_FLOAT))
- {
- fprintf(p.Out, "%s%s", zSep, azArg[i]);
- }
- else if (aiType != null && aiType[i] == Sqlite3.SQLITE_BLOB && p.pStmt != null)
- {
- byte[] pBlob = Sqlite3.sqlite3_column_blob(p.pStmt, i);
- int nBlob = Sqlite3.sqlite3_column_bytes(p.pStmt, i);
- if (!String.IsNullOrEmpty(zSep))
- fprintf(p.Out, "%s", zSep);
- output_hex_blob(p.Out, pBlob, nBlob);
- }
- else if (isNumber(azArg[i], 0))
- {
- fprintf(p.Out, "%s%s", zSep, azArg[i]);
- }
- else
- {
- if (!String.IsNullOrEmpty(zSep))
- fprintf(p.Out, "%s", zSep);
- output_quoted_string(p.Out, azArg[i]);
- }
- }
- fprintf(p.Out, ");\n");
- break;
- }
- }
- return 0;
- }
-
- /*
- ** This is the callback routine that the SQLite library
- ** invokes for each row of a query result.
- */
- static int callback(object pArg, sqlite3_int64 nArg, object azArg, object azCol)
- {
- /* since we don't have type info, call the shell_callback with a null value */
- callback_data_extra cde = new callback_data_extra();
- cde.azVals = (string[])azArg;
- cde.azCols = (string[])azCol;
- cde.aiTypes = null;
- return shell_callback(pArg, (int)nArg, cde, null);
- }
-
- /*
- ** Set the destination table field of the callback_data structure to
- ** the name of the table given. Escape any quote characters in the
- ** table name.
- */
- static void set_table_name(callback_data p, string zName)
- {
- int i, n;
- bool needQuote;
- string z = "";
-
- if (p.zDestTable != null)
- {
- //free(ref p.zDestTable);
- p.zDestTable = null;
- }
- if (zName == null)
- return;
- needQuote = !isalpha(zName[0]) && zName != "_";
- for (i = n = 0; i < zName.Length; i++, n++)
- {
- if (!isalnum(zName[i]) && zName[i] != '_')
- {
- needQuote = true;
- if (zName[i] == '\'')
- n++;
- }
- }
- if (needQuote)
- n += 2;
- //z = p.zDestTable = malloc( n + 1 );
- //if ( z == 0 )
- //{
- // fprintf( stderr, "Out of memory!\n" );
- // exit( 1 );
- //}
- //n = 0;
- if (needQuote)
- z += '\'';
- for (i = 0; i < zName.Length; i++)
- {
- z += zName[i];
- if (zName[i] == '\'')
- z += '\'';
- }
- if (needQuote)
- z += '\'';
- //z[n] = 0;
- p.zDestTable = z;
- }
-
- /* 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 void appendText(StringBuilder zIn, string zAppend, int noQuote)
- { appendText(zIn, zAppend, '\0'); }
-
- static void appendText(StringBuilder zIn, string zAppend, char quote)
- {
- int len;
- int i;
- int nAppend = strlen30(zAppend);
- int nIn = (zIn != null ? strlen30(zIn) : 0);
-
- len = nAppend + nIn;
- if (quote != '\0')
- {
- len += 2;
- for (i = 0; i < nAppend; i++)
- {
- if (zAppend[i] == quote)
- len++;
- }
- }
-
- //zIn = realloc( zIn, len );
- //if ( !zIn )
- //{
- // return 0;
- //}
-
- if (quote != '\0')
- {
- zIn.Append(quote);
- for (i = 0; i < nAppend; i++)
- {
- zIn.Append(zAppend[i]);
- if (zAppend[i] == quote)
- zIn.Append(quote);
- }
- zIn.Append(quote);
- //zCsr++ = '\0';
- Debug.Assert(zIn.Length == len);
-
- }
- else
- {
- zIn.Append(zAppend);//memcpy( zIn[nIn], zAppend, nAppend );
- //zIn[len - 1] = '\0';
- }
- }
-
-
-
- /*
- ** Execute a query statement that has a single result column. Print
- ** that result column on a line by itself with a semicolon terminator.
- **
- ** This is used, for example, to show the schema of the database by
- ** querying the Sqlite3.SQLITE_MASTER table.
- */
- static int run_table_dump_query(
- FILE Out, /* Send output here */
- sqlite3 db, /* Database to query */
- StringBuilder zSelect, /* SELECT statement to extract content */
- string zFirstRow /* Print before first row, if not null */
- )
- { return run_table_dump_query(Out, db, zSelect.ToString(), zFirstRow); }
-
- static int run_table_dump_query(
- FILE Out, /* Send output here */
- sqlite3 db, /* Database to query */
- string zSelect, /* SELECT statement to extract content */
- string zFirstRow /* Print before first row, if not null */
- )
- {
- sqlite3_stmt pSelect = null;
- int rc;
- rc = Sqlite3.sqlite3_prepare(db, zSelect, -1, ref pSelect, 0);
- if (rc != Sqlite3.SQLITE_OK || null == pSelect)
- {
- return rc;
- }
- rc = Sqlite3.sqlite3_step(pSelect);
- while (rc == Sqlite3.SQLITE_ROW)
- {
- if (zFirstRow != null)
- {
- fprintf(Out, "%s", zFirstRow);
- zFirstRow = null;
- }
- fprintf(Out, "%s;\n", Sqlite3.sqlite3_column_text(pSelect, 0));
- rc = Sqlite3.sqlite3_step(pSelect);
- }
- return Sqlite3.sqlite3_finalize(pSelect);
- }
-
- /*
- ** Allocate space and save off current error string.
- */
- static string save_err_msg(
- sqlite3 db /* Database to query */
- )
- {
- //int nErrMsg = 1 + strlen30(Sqlite3.sqlite3_errmsg(db));
- //string zErrMsg = Sqlite3.sqlite3_malloc(nErrMsg);
- //if (zErrMsg != null)
- //{
- // memcpy(zErrMsg, Sqlite3.sqlite3_errmsg(db), nErrMsg);
- //}
- return Sqlite3.sqlite3_errmsg(db); //zErrMsg;
- }
-
- /*
- ** Display memory stats.
- */
- static int display_stats(
- sqlite3 db, /* Database to query */
- callback_data pArg, /* Pointer to struct callback_data */
- int bReset /* True to reset the stats */
- )
- {
- int iCur;
- int iHiwtr;
-
- if (pArg != null && pArg.Out != null)
- {
-
- iHiwtr = iCur = -1;
- Sqlite3.sqlite3_status(Sqlite3.SQLITE_STATUS_MEMORY_USED, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Memory Used: %d (max %d) bytes\n", iCur, iHiwtr);
- iHiwtr = iCur = -1;
- Sqlite3.sqlite3_status(Sqlite3.SQLITE_STATUS_MALLOC_COUNT, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Number of Outstanding Allocations: %d (max %d)\n", iCur, iHiwtr);
- /*
- ** Not currently used by the CLI.
- ** iHiwtr = iCur = -1;
- ** Sqlite3.SQLITE_status(Sqlite3.SQLITE_STATUS_PAGECACHE_USED,ref iCur,ref iHiwtr, bReset);
- ** fprintf(pArg.Out, "Number of Pcache Pages Used: %d (max %d) pages\n", iCur, iHiwtr);
- */
- iHiwtr = iCur = -1;
- Sqlite3.sqlite3_status(Sqlite3.SQLITE_STATUS_PAGECACHE_OVERFLOW, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Number of Pcache Overflow Bytes: %d (max %d) bytes\n", iCur, iHiwtr);
- /*
- ** Not currently used by the CLI.
- ** iHiwtr = iCur = -1;
- ** Sqlite3.SQLITE_status(Sqlite3.SQLITE_STATUS_SCRATCH_USED,ref iCur,ref iHiwtr, bReset);
- ** fprintf(pArg.Out, "Number of Scratch Allocations Used: %d (max %d)\n", iCur, iHiwtr);
- */
- iHiwtr = iCur = -1;
- Sqlite3.sqlite3_status(Sqlite3.SQLITE_STATUS_SCRATCH_OVERFLOW, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Number of Scratch Overflow Bytes: %d (max %d) bytes\n", iCur, iHiwtr);
- iHiwtr = iCur = -1;
- Sqlite3.sqlite3_status(Sqlite3.SQLITE_STATUS_MALLOC_SIZE, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Largest Allocation: %d bytes\n", iHiwtr);
- iHiwtr = iCur = -1;
- Sqlite3.sqlite3_status(Sqlite3.SQLITE_STATUS_PAGECACHE_SIZE, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Largest Pcache Allocation: %d bytes\n", iHiwtr);
- iHiwtr = iCur = -1;
- Sqlite3.sqlite3_status(Sqlite3.SQLITE_STATUS_SCRATCH_SIZE, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Largest Scratch Allocation: %d bytes\n", iHiwtr);
-#if YYTRACKMAXSTACKDEPTH
-iHiwtr = iCur = -1;
-Sqlite3.SQLITE_status(Sqlite3.SQLITE_STATUS_PARSER_STACK,ref iCur,ref iHiwtr, bReset);
-fprintf(pArg.Out, "Deepest Parser Stack: %d (max %d)\n", iCur, iHiwtr);
-#endif
- }
-
- if (pArg != null && pArg.Out != null && db != null)
- {
- iHiwtr = iCur = -1;
- Sqlite3.sqlite3_db_status(db, Sqlite3.SQLITE_DBSTATUS_LOOKASIDE_USED, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Lookaside Slots Used: %d (max %d)\n", iCur, iHiwtr);
- Sqlite3.sqlite3_db_status(db, Sqlite3.SQLITE_DBSTATUS_LOOKASIDE_HIT, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Successful lookaside attempts: %d\n", iHiwtr);
- Sqlite3.sqlite3_db_status(db, Sqlite3.SQLITE_DBSTATUS_LOOKASIDE_MISS_SIZE, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Lookaside failures due to size: %d\n", iHiwtr);
- Sqlite3.sqlite3_db_status(db, Sqlite3.SQLITE_DBSTATUS_LOOKASIDE_MISS_FULL, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Lookaside failures due to OOM: %d\n", iHiwtr);
- iHiwtr = iCur = -1;
- Sqlite3.sqlite3_db_status(db, Sqlite3.SQLITE_DBSTATUS_CACHE_USED, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Pager Heap Usage: %d bytes\n", iCur);
- iHiwtr = iCur = -1;
- Sqlite3.sqlite3_db_status(db, Sqlite3.SQLITE_DBSTATUS_SCHEMA_USED, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Schema Heap Usage: %d bytes\n", iCur);
- iHiwtr = iCur = -1;
- Sqlite3.sqlite3_db_status(db, Sqlite3.SQLITE_DBSTATUS_STMT_USED, ref iCur, ref iHiwtr, bReset);
- fprintf(pArg.Out, "Statement Heap/Lookaside Usage: %d bytes\n", iCur);
- }
-
- if (pArg != null && pArg.Out != null && db != null && pArg.pStmt != null)
- {
- iCur = Sqlite3.sqlite3_stmt_status(pArg.pStmt, Sqlite3.SQLITE_STMTSTATUS_FULLSCAN_STEP, bReset);
- fprintf(pArg.Out, "Fullscan Steps: %d\n", iCur);
- iCur = Sqlite3.sqlite3_stmt_status(pArg.pStmt, Sqlite3.SQLITE_STMTSTATUS_SORT, bReset);
- fprintf(pArg.Out, "Sort Operations: %d\n", iCur);
- iCur = Sqlite3.sqlite3_stmt_status(pArg.pStmt, Sqlite3.SQLITE_STMTSTATUS_AUTOINDEX, bReset);
- fprintf(pArg.Out, "Autoindex Inserts: %d\n", iCur);
- }
-
- return 0;
- }
-
- /*
- ** Execute a statement or set of statements. Print
- ** any result rows/columns depending on the current mode
- ** set via the supplied callback.
- **
- ** This is very similar to SQLite's built-in Sqlite3.sqlite3_exec()
- ** function except it takes a slightly different callback
- ** and callback data argument.
- */
- static int shell_exec(
- sqlite3 db, /* An open database */
- string zSql, /* SQL to be evaluated */
- dxCallback xCallback, //int (*xCallback)(void*,int,char**,char**,int*), /* Callback function */
- /* (not the same as Sqlite3.sqlite3_exec) */
- callback_data pArg, /* Pointer to struct callback_data */
- ref string pzErrMsg /* Error msg written here */
- )
- {
- sqlite3_stmt pStmt = null; /* Statement to execute. */
- int rc = Sqlite3.SQLITE_OK; /* Return Code */
- string zLeftover = null; /* Tail of unprocessed SQL */
-
- // if( pzErrMsg )
- {
- pzErrMsg = null;
- }
-
- while (!String.IsNullOrEmpty(zSql) && (Sqlite3.SQLITE_OK == rc))
- {
- rc = Sqlite3.sqlite3_prepare_v2(db, zSql, -1, ref pStmt, ref zLeftover);
- if (Sqlite3.SQLITE_OK != rc)
- {
- //if (pzErrMsg != null)
- {
- pzErrMsg = save_err_msg(db);
- }
- }
- else
- {
- if (null == pStmt)
- {
- /* this happens for a comment or white-space */
- zSql = zLeftover.TrimStart();
- //while (isspace(zSql[0]))
- // zSql++;
- continue;
- }
-
- /* save off the prepared statment handle and reset row count */
- if (pArg != null)
- {
- pArg.pStmt = pStmt;
- pArg.cnt = 0;
- }
-
- /* echo the sql statement if echo on */
- if (pArg != null && pArg.echoOn)
- {
- string zStmtSql = Sqlite3.sqlite3_sql(pStmt);
- fprintf(pArg.Out, "%s\n", zStmtSql != null ? zStmtSql : zSql);
- }
-
- /* perform the first step. this will tell us if we
- ** have a result set or not and how wide it is.
- */
- rc = Sqlite3.sqlite3_step(pStmt);
- /* if we have a result set... */
- if (Sqlite3.SQLITE_ROW == rc)
- {
- /* if we have a callback... */
- if (xCallback != null)
- {
- /* allocate space for col name ptr, value ptr, and type */
- int nCol = Sqlite3.sqlite3_column_count(pStmt);
- //void pData = Sqlite3.SQLITE_malloc(3*nCol*sizeof(const char*) + 1);
- //if( !pData ){
- // rc = Sqlite3.SQLITE_NOMEM;
- //}else
- {
- string[] azCols = new string[nCol];//(string *)pData; /* Names of result columns */
- string[] azVals = new string[nCol];//azCols[nCol]; /* Results */
- int[] aiTypes = new int[nCol];//(int *)&azVals[nCol]; /* Result types */
- int i;
- //Debug.Assert(sizeof(int) <= sizeof(string ));
- /* save off ptrs to column names */
- for (i = 0; i < nCol; i++)
- {
- azCols[i] = (string)Sqlite3.sqlite3_column_name(pStmt, i);
- }
- do
- {
- /* extract the data and data types */
- for (i = 0; i < nCol; i++)
- {
- azVals[i] = (string)Sqlite3.sqlite3_column_text(pStmt, i);
- aiTypes[i] = Sqlite3.sqlite3_column_type(pStmt, i);
- if (null == azVals[i] && (aiTypes[i] != Sqlite3.SQLITE_NULL))
- {
- rc = Sqlite3.SQLITE_NOMEM;
- break; /* from for */
- }
- } /* end for */
-
- /* if data and types extracted successfully... */
- if (Sqlite3.SQLITE_ROW == rc)
- {
- /* call the supplied callback with the result row data */
- callback_data_extra cde = new callback_data_extra();
- cde.azVals = azVals;
- cde.azCols = azCols;
- cde.aiTypes = aiTypes;
-
- if (xCallback(pArg, nCol, cde, null) != 0)
- {
- rc = Sqlite3.SQLITE_ABORT;
- }
- else
- {
- rc = Sqlite3.sqlite3_step(pStmt);
- }
- }
- } while (Sqlite3.SQLITE_ROW == rc);
- //Sqlite3.sqlite3_free(ref pData);
- }
- }
- else
- {
- do
- {
- rc = Sqlite3.sqlite3_step(pStmt);
- } while (rc == Sqlite3.SQLITE_ROW);
- }
- }
-
- /* print usage stats if stats on */
- if (pArg != null && pArg.statsOn)
- {
- display_stats(db, pArg, 0);
- }
-
- /* Finalize the statement just executed. If this fails, save a
- ** copy of the error message. Otherwise, set zSql to point to the
- ** next statement to execute. */
- rc = Sqlite3.sqlite3_finalize(pStmt);
- if (rc == Sqlite3.SQLITE_OK)
- {
- zSql = zLeftover.TrimStart();
- //while (isspace(zSql[0]))
- // zSql++;
- }
- else //if (pzErrMsg)
- {
- pzErrMsg = save_err_msg(db);
- }
-
- /* clear saved stmt handle */
- if (pArg != null)
- {
- pArg.pStmt = null;
- }
- }
- } /* end while */
-
- return rc;
- }
-
-
- /*
- ** This is a different callback routine used for dumping the database.
- ** Each row received by this callback consists of a table name,
- ** the table type ("index" or "table") and SQL to create the table.
- ** This routine should print text sufficient to recreate the table.
- */
- static int dump_callback(object pArg, sqlite3_int64 nArg, object pazArg, object pazCol)
- {
- int rc;
- string zTable;
- string zType;
- string zSql;
- string zPrepStmt = null;
- callback_data p = (callback_data)pArg;
- string[] azArg = (string[])pazArg;
- string[] azCol = (string[])pazCol;
-
- UNUSED_PARAMETER(azCol);
- if (nArg != 3)
- return 1;
- zTable = azArg[0];
- zType = azArg[1];
- zSql = azArg[2];
-
- if (zTable.Equals("sqlite_sequence", StringComparison.InvariantCultureIgnoreCase))
- {
- zPrepStmt = "DELETE FROM sqlite_sequence;\n";
- }
- else if (zTable.Equals("sqlite_stat1", StringComparison.InvariantCultureIgnoreCase))
- {
- fprintf(p.Out, "ANALYZE Sqlite3.SQLITE_master;\n");
- }
- else if (zTable.StartsWith("SQLITE_", StringComparison.InvariantCultureIgnoreCase))
- {
- return 0;
- }
- else if (zSql.StartsWith("CREATE VIRTUAL TABLE", StringComparison.InvariantCultureIgnoreCase))
- {
- string zIns;
- if (!p.writableSchema)
- {
- fprintf(p.Out, "PRAGMA writable_schema=ON;\n");
- p.writableSchema = true;
- }
- zIns = Sqlite3.sqlite3_mprintf(
- "INSERT INTO Sqlite3.SQLITE_master(type,name,tbl_name,rootpage,sql)" +
- "VALUES('table','%q','%q',0,'%q');",
- zTable, zTable, zSql);
- fprintf(p.Out, "%s\n", zIns);
- zIns = null;//Sqlite3.sqlite3_free(zIns);
- return 0;
- }
- else
- {
- fprintf(p.Out, "%s;\n", zSql);
- }
-
- if (zType.Equals("table", StringComparison.InvariantCultureIgnoreCase))
- {
- sqlite3_stmt pTableInfo = null;
- StringBuilder zSelect = new StringBuilder();
- StringBuilder zTableInfo = new StringBuilder();
- StringBuilder zTmp = new StringBuilder();
- int nRow = 0;
-
- appendText(zTableInfo, "PRAGMA table_info(", 0);
- appendText(zTableInfo, zTable, '"');
- appendText(zTableInfo, ");", 0);
-
- rc = Sqlite3.sqlite3_prepare(p.db, zTableInfo, -1, ref pTableInfo, 0);
- zTableInfo = null;//free(zTableInfo);
- if (rc != Sqlite3.SQLITE_OK || null == pTableInfo)
- {
- return 1;
- }
-
- appendText(zSelect, "SELECT 'INSERT INTO ' || ", 0);
- appendText(zTmp, zTable, '"');
- //if (zTmp!=null)
- {
- appendText(zSelect, zTmp.ToString(), '\'');
- }
- appendText(zSelect, " || ' VALUES(' || ", 0);
- rc = Sqlite3.sqlite3_step(pTableInfo);
- while (rc == Sqlite3.SQLITE_ROW)
- {
- string zText = (string)Sqlite3.sqlite3_column_text(pTableInfo, 1);
- appendText(zSelect, "quote(", 0);
- appendText(zSelect, zText, '"');
- rc = Sqlite3.sqlite3_step(pTableInfo);
- if (rc == Sqlite3.SQLITE_ROW)
- {
- appendText(zSelect, ") || ',' || ", 0);
- }
- else
- {
- appendText(zSelect, ") ", 0);
- }
- nRow++;
- }
- rc = Sqlite3.sqlite3_finalize(pTableInfo);
- if (rc != Sqlite3.SQLITE_OK || nRow == 0)
- {
- zSelect = null;//free(zSelect);
- return 1;
- }
- appendText(zSelect, "|| ')' FROM ", 0);
- appendText(zSelect, zTable, '"');
-
- rc = run_table_dump_query(p.Out, p.db, zSelect, zPrepStmt);
- if (rc == Sqlite3.SQLITE_CORRUPT)
- {
- appendText(zSelect, " ORDER BY rowid DESC", 0);
- rc = run_table_dump_query(p.Out, p.db, zSelect, "");
- }
- if (zSelect != null)
- zSelect = null;//free(zSelect);
- }
- return 0;
- }
-
- /*
- ** Run zQuery. Use dump_callback() as the callback routine so that
- ** the contents of the query are output as SQL statements.
- **
- ** If we get a Sqlite3.SQLITE_CORRUPT error, rerun the query after appending
- ** "ORDER BY rowid DESC" to the end.
- */
- static int run_schema_dump_query(
- callback_data p,
- string zQuery,
- string pzErrMsg
- )
- {
- int rc;
- rc = Sqlite3.sqlite3_exec(p.db, zQuery, dump_callback, p, ref pzErrMsg);
- if (rc == Sqlite3.SQLITE_CORRUPT)
- {
- StringBuilder zQ2;
- int len = strlen30(zQuery);
- if (pzErrMsg != null)
- pzErrMsg = null;//Sqlite3.sqlite3_free(pzErrMsg);
- zQ2 = new StringBuilder(len + 100);//zQ2 = malloc(len + 100);
- //if (zQ2 == null)
- // return rc;
- Sqlite3.sqlite3_snprintf(zQ2.Capacity, zQ2, "%s ORDER BY rowid DESC", zQuery);
- rc = Sqlite3.sqlite3_exec(p.db, zQ2.ToString(), dump_callback, p, ref pzErrMsg);
- zQ2 = null;//free(zQ2);
- }
- return rc;
- }
-
- /*
- ** Text of a help message
- */
- static string zHelp =
- ".backup ?DB? FILE Backup DB (default \"main\") to FILE\n" +
- ".bail ON|OFF Stop after hitting an error. Default OFF\n" +
- ".databases List names and files of attached databases\n" +
- ".dump ?TABLE? ... Dump the database in an SQL text format\n" +
- " If TABLE specified, only dump tables matching\n" +
- " LIKE pattern TABLE.\n" +
- ".echo ON|OFF Turn command echo on or off\n" +
- ".exit Exit this program\n" +
- ".explain ?ON|OFF? Turn output mode suitable for EXPLAIN on or off.\n" +
- " With no args, it turns EXPLAIN on.\n" +
- ".header(s) ON|OFF Turn display of headers on or off\n" +
- ".help Show this message\n" +
- ".import FILE TABLE Import data from FILE into TABLE\n" +
- ".indices ?TABLE? Show names of all indices\n" +
- " If TABLE specified, only show indices for tables\n" +
- " matching LIKE pattern TABLE.\n" +
-#if SQLITE_ENABLE_IOTRACE
-".iotrace FILE Enable I/O diagnostic logging to FILE\n" +
-#endif
-#if !SQLITE_OMIT_LOAD_EXTENSION
- ".load FILE ?ENTRY? Load an extension library\n" +
-#endif
- ".log FILE|off Turn logging on or off. FILE can be stderr/stdout\n" +
- ".mode MODE ?TABLE? Set output mode where MODE is one of:\n" +
- " csv Comma-separated values\n" +
- " column Left-aligned columns. (See .width)\n" +
- " html HTML