** language. The code for the "sqlite3" command-line shell is also in a
** separate file. This file contains only code for the core SQLite library.
*/
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wcast-function-type"
+#pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
+#pragma GCC diagnostic ignored "-Wunused-parameter"
+
#define SQLITE_CORE 1
#define SQLITE_AMALGAMATION 1
#ifndef SQLITE_PRIVATE
/*
** Name of table that holds the database schema.
*/
-#define DFLT_SCHEMA_TABLE "sqlite_master"
-#define DFLT_TEMP_SCHEMA_TABLE "sqlite_temp_master"
+#define DFLT_SCHEMA_TABLE "sqlcipher_master"
+#define DFLT_TEMP_SCHEMA_TABLE "sqlcipher_temp_master"
#define ALT_SCHEMA_TABLE "sqlite_schema"
#define ALT_TEMP_SCHEMA_TABLE "sqlite_temp_schema"
*/
zSql = sqlite3_mprintf(
"SELECT sql "
- " FROM %s.sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
+ " FROM %s.sqlcipher_master WHERE type='table' AND name!='sqlcipher_sequence'"
" AND rootpage>0"
, sourceDb);
rc = (zSql == NULL) ? SQLITE_NOMEM : sqlcipher_execExecSql(db, &pzErrMsg, zSql);
zSql = sqlite3_mprintf(
"SELECT sql "
- " FROM %s.sqlite_master WHERE sql LIKE 'CREATE INDEX %%' "
+ " FROM %s.sqlcipher_master WHERE sql LIKE 'CREATE INDEX %%' "
, sourceDb);
rc = (zSql == NULL) ? SQLITE_NOMEM : sqlcipher_execExecSql(db, &pzErrMsg, zSql);
if( rc!=SQLITE_OK ) goto end_of_export;
zSql = sqlite3_mprintf(
"SELECT sql "
- " FROM %s.sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %%'"
+ " FROM %s.sqlcipher_master WHERE sql LIKE 'CREATE UNIQUE INDEX %%'"
, sourceDb);
rc = (zSql == NULL) ? SQLITE_NOMEM : sqlcipher_execExecSql(db, &pzErrMsg, zSql);
if( rc!=SQLITE_OK ) goto end_of_export;
zSql = sqlite3_mprintf(
"SELECT 'INSERT INTO %s.' || quote(name) "
"|| ' SELECT * FROM %s.' || quote(name) || ';'"
- "FROM %s.sqlite_master "
- "WHERE type = 'table' AND name!='sqlite_sequence' "
+ "FROM %s.sqlcipher_master "
+ "WHERE type = 'table' AND name!='sqlcipher_sequence' "
" AND rootpage>0"
, targetDb, sourceDb, sourceDb);
rc = (zSql == NULL) ? SQLITE_NOMEM : sqlcipher_execExecSql(db, &pzErrMsg, zSql);
zSql = sqlite3_mprintf(
"SELECT 'INSERT INTO %s.' || quote(name) "
"|| ' SELECT * FROM %s.' || quote(name) || ';' "
- "FROM %s.sqlite_master WHERE name=='sqlite_sequence';"
+ "FROM %s.sqlcipher_master WHERE name=='sqlcipher_sequence';"
, targetDb, sourceDb, targetDb);
rc = (zSql == NULL) ? SQLITE_NOMEM : sqlcipher_execExecSql(db, &pzErrMsg, zSql);
if( rc!=SQLITE_OK ) goto end_of_export;
** from the SQLITE_MASTER table.
*/
zSql = sqlite3_mprintf(
- "INSERT INTO %s.sqlite_master "
+ "INSERT INTO %s.sqlcipher_master "
" SELECT type, name, tbl_name, rootpage, sql"
- " FROM %s.sqlite_master"
+ " FROM %s.sqlcipher_master"
" WHERE type='view' OR type='trigger'"
" OR (type='table' AND rootpage=0)"
, targetDb, sourceDb);
CODEC2(pPg->pPager, pPg->pData, pPg->pgno, 6, return 0, aData);
return aData;
}
-
-/*
-** Return the current pager state
-*/
-SQLITE_PRIVATE int sqlite3PagerState(Pager *pPager){
- return pPager->eState;
-}
#endif /* SQLITE_HAS_CODEC */
/* END SQLCIPHER */
"WHEN type='table' THEN %Q "
"WHEN name LIKE 'sqliteX_autoindex%%' ESCAPE 'X' "
" AND type='index' THEN "
- "'sqlite_autoindex_' || %Q || substr(name,%d+18) "
+ "'sqlcipher_autoindex_' || %Q || substr(name,%d+18) "
"ELSE name END "
"WHERE tbl_name=%Q COLLATE nocase AND "
"(type='table' OR type='index' OR type='trigger');",
/* If the sqlite_sequence table exists in this database, then update
** it with the new table name.
*/
- if( sqlite3FindTable(db, "sqlite_sequence", zDb) ){
+ if( sqlite3FindTable(db, "sqlcipher_sequence", zDb) ){
sqlite3NestedParse(pParse,
- "UPDATE \"%w\".sqlite_sequence set name = %Q WHERE name = %Q",
+ "UPDATE \"%w\".sqlcipher_sequence set name = %Q WHERE name = %Q",
zDb, zName, pTab->zName);
}
#endif
** as required. */
if( iDb!=1 ){
sqlite3NestedParse(pParse,
- "UPDATE sqlite_temp_schema SET "
+ "UPDATE sqlcipher_temp_master SET "
"sql = sqlite_rename_table(%Q, type, name, sql, %Q, %Q, 1), "
"tbl_name = "
"CASE WHEN tbl_name=%Q COLLATE nocase AND "
const char *zName;
const char *zCols;
} aTable[] = {
- { "sqlite_stat1", "tbl,idx,stat" },
+ { "sqlcipher_stat1", "tbl,idx,stat" },
#if defined(SQLITE_ENABLE_STAT4)
- { "sqlite_stat4", "tbl,idx,neq,nlt,ndlt,sample" },
+ { "sqlcipher_stat4", "tbl,idx,neq,nlt,ndlt,sample" },
#else
- { "sqlite_stat4", 0 },
+ { "sqlcipher_stat4", 0 },
#endif
- { "sqlite_stat3", 0 },
+ { "sqlcipher_stat3", 0 },
};
int i;
sqlite3 *db = pParse->db;
pStat1 = (Table*)sqlite3DbMallocZero(db, sizeof(Table) + 13);
if( pStat1==0 ) return;
pStat1->zName = (char*)&pStat1[1];
- memcpy(pStat1->zName, "sqlite_stat1", 13);
+ memcpy(pStat1->zName, "sqlcipher_stat1", 16);
pStat1->nCol = 3;
pStat1->iPKey = -1;
sqlite3VdbeAddOp4(pParse->pVdbe, OP_Noop, 0, 0, 0,(char*)pStat1,P4_DYNBLOB);
int rc = SQLITE_OK; /* Result codes from subroutines */
assert( db->lookaside.bDisable );
- if( sqlite3FindTable(db, "sqlite_stat4", zDb) ){
+ if( sqlite3FindTable(db, "sqlcipher_stat4", zDb) ){
rc = loadStatTbl(db,
- "SELECT idx,count(*) FROM %Q.sqlite_stat4 GROUP BY idx",
- "SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlite_stat4",
+ "SELECT idx,count(*) FROM %Q.sqlcipher_stat4 GROUP BY idx",
+ "SELECT idx,neq,nlt,ndlt,sample FROM %Q.sqlcipher_stat4",
zDb
);
}
/* Load new statistics out of the sqlite_stat1 table */
sInfo.db = db;
sInfo.zDatabase = db->aDb[iDb].zDbSName;
- if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)!=0 ){
+ if( sqlite3FindTable(db, "sqlcipher_stat1", sInfo.zDatabase)!=0 ){
zSql = sqlite3MPrintf(db,
- "SELECT tbl,idx,stat FROM %Q.sqlite_stat1", sInfo.zDatabase);
+ "SELECT tbl,idx,stat FROM %Q.sqlcipher_stat1", sInfo.zDatabase);
if( zSql==0 ){
rc = SQLITE_NOMEM_BKPT;
}else{
** so that INSERT can find the table easily.
*/
#ifndef SQLITE_OMIT_AUTOINCREMENT
- if( !pParse->nested && strcmp(zName, "sqlite_sequence")==0 ){
+ if( !pParse->nested && strcmp(zName, "sqlcipher_sequence")==0 ){
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
pTable->pSchema->pSeqTab = pTable;
}
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
if( pDb->pSchema->pSeqTab==0 ){
sqlite3NestedParse(pParse,
- "CREATE TABLE %Q.sqlite_sequence(name,seq)",
+ "CREATE TABLE %Q.sqlcipher_sequence(name,seq)",
pDb->zDbSName
);
}
const char *zDbName = pParse->db->aDb[iDb].zDbSName;
for(i=1; i<=4; i++){
char zTab[24];
- sqlite3_snprintf(sizeof(zTab),zTab,"sqlite_stat%d",i);
+ sqlite3_snprintf(sizeof(zTab),zTab,"sqlcipher_stat%d",i);
if( sqlite3FindTable(pParse->db, zTab, zDbName) ){
sqlite3NestedParse(pParse,
"DELETE FROM %Q.%s WHERE %s=%Q",
*/
if( pTab->tabFlags & TF_Autoincrement ){
sqlite3NestedParse(pParse,
- "DELETE FROM %Q.sqlite_sequence WHERE name=%Q",
+ "DELETE FROM %Q.sqlcipher_sequence WHERE name=%Q",
pDb->zDbSName, pTab->zName
);
}
int n;
Index *pLoop;
for(pLoop=pTab->pIndex, n=1; pLoop; pLoop=pLoop->pNext, n++){}
- zName = sqlite3MPrintf(db, "sqlite_autoindex_%s_%d", pTab->zName, n);
+ zName = sqlite3MPrintf(db, "sqlcipher_autoindex_%s_%d", pTab->zName, n);
if( zName==0 ){
goto exit_create_index;
}
u8 p5 = 0;
sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek);
sqlite3VdbeAddOp2(v, OP_Delete, iDataCur, (count?OPFLAG_NCHANGE:0));
- if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlite_stat1") ){
+ if( pParse->nested==0 || 0==sqlite3_stricmp(pTab->zName, "sqlcipher_stat1") ){
sqlite3VdbeAppendP4(v, (char*)pTab, P4_TABLE);
}
if( eMode!=ONEPASS_OFF ){
if( pPragma->iArg==2 || pPragma->iArg==3 ){
u8 iByte;
int i;
- for(i=0, iByte=0; i<sizeof(zBuf)*2 && sqlite3Isxdigit(zRight[i]); i++){
+ for(i=0, iByte=0; i<(int)(sizeof(zBuf)*2) && sqlite3Isxdigit(zRight[i]); i++){
iByte = (iByte<<4) + sqlite3HexToInt(zRight[i]);
if( (i&1)!=0 ) zBuf[i/2] = iByte;
}
*/
db->init.iDb = nDb; /* force new CREATE statements into vacuum_db */
rc = execSqlF(db, pzErrMsg,
- "SELECT sql FROM \"%w\".sqlite_schema"
- " WHERE type='table'AND name<>'sqlite_sequence'"
+ "SELECT sql FROM \"%w\".sqlcipher_master"
+ " WHERE type='table'AND name<>'sqlcipher_sequence'"
" AND coalesce(rootpage,1)>0",
zDbMain
);
if( rc!=SQLITE_OK ) goto end_of_vacuum;
rc = execSqlF(db, pzErrMsg,
- "SELECT sql FROM \"%w\".sqlite_schema"
+ "SELECT sql FROM \"%w\".sqlcipher_master"
" WHERE type='index'",
zDbMain
);
rc = execSqlF(db, pzErrMsg,
"SELECT'INSERT INTO vacuum_db.'||quote(name)"
"||' SELECT*FROM\"%w\".'||quote(name)"
- "FROM vacuum_db.sqlite_schema "
+ "FROM vacuum_db.sqlcipher_master "
"WHERE type='table'AND coalesce(rootpage,1)>0",
zDbMain
);
** from the schema table.
*/
rc = execSqlF(db, pzErrMsg,
- "INSERT INTO vacuum_db.sqlite_schema"
- " SELECT*FROM \"%w\".sqlite_schema"
+ "INSERT INTO vacuum_db.sqlcipher_master"
+ " SELECT*FROM \"%w\".sqlcipher_master"
" WHERE type IN('view','trigger')"
" OR(type='table'AND rootpage=0)",
zDbMain
if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){
const char *zName;
if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){
- if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
+ if( strncmp(zName, "sqlcipher_autoindex_", 20)==0 ){
int i = sqlite3Strlen30(zName) - 1;
while( zName[i]!='_' ) i--;
zName += i;
u8 iByte;
int i;
char zDecoded[40];
- for(i=0, iByte=0; i<sizeof(zDecoded)*2 && sqlite3Isxdigit(zKey[i]); i++){
+ for(i=0, iByte=0; i<(int)(sizeof(zDecoded)*2) && sqlite3Isxdigit(zKey[i]); i++){
iByte = (iByte<<4) + sqlite3HexToInt(zKey[i]);
if( (i&1)!=0 ) zDecoded[i/2] = iByte;
}
** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
*/
static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
- const char *zFmt = "SELECT stat FROM %Q.sqlite_stat1 WHERE tbl = '%q_rowid'";
+ const char *zFmt = "SELECT stat FROM %Q.sqlcipher_stat1 WHERE tbl = '%q_rowid'";
char *zSql;
sqlite3_stmt *p;
int rc;
i64 nRow = 0;
rc = sqlite3_table_column_metadata(
- db, pRtree->zDb, "sqlite_stat1",0,0,0,0,0,0
+ db, pRtree->zDb, "sqlcipher_stat1",0,0,0,0,0,0
);
if( rc!=SQLITE_OK ){
pRtree->nRowEst = RTREE_DEFAULT_ROWEST;
rc = prepareFreeAndCollectError(p->dbRbu, &pIter->pTblIter, &p->zErrmsg,
sqlite3_mprintf(
"SELECT rbu_target_name(name, type='view') AS target, name "
- "FROM sqlite_schema "
+ "FROM sqlcipher_master "
"WHERE type IN ('table', 'view') AND target IS NOT NULL "
" %s "
"ORDER BY name"
if( rc==SQLITE_OK ){
rc = prepareAndCollectError(p->dbMain, &pIter->pIdxIter, &p->zErrmsg,
"SELECT name, rootpage, sql IS NULL OR substr(8, 6)=='UNIQUE' "
- " FROM main.sqlite_schema "
+ " FROM main.sqlcipher_master "
" WHERE type='index' AND tbl_name = ?"
);
}
p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[0], &p->zErrmsg,
sqlite3_mprintf(
"SELECT (sql LIKE 'create virtual%%'), rootpage"
- " FROM sqlite_schema"
+ " FROM sqlcipher_master"
" WHERE name=%Q", zTab
));
if( p->rc!=SQLITE_OK || sqlite3_step(aStmt[0])!=SQLITE_ROW ){
if( zOrig && zIdx && zOrig[0]=='p' ){
p->rc = prepareFreeAndCollectError(p->dbMain, &aStmt[2], &p->zErrmsg,
sqlite3_mprintf(
- "SELECT rootpage FROM sqlite_schema WHERE name = %Q", zIdx
+ "SELECT rootpage FROM sqlcipher_master WHERE name = %Q", zIdx
));
if( p->rc==SQLITE_OK ){
if( sqlite3_step(aStmt[2])==SQLITE_ROW ){
** This is needed for the argument to "PRAGMA index_xinfo". Set
** zIdx to point to a nul-terminated string containing this name. */
p->rc = prepareAndCollectError(p->dbMain, &pQuery, &p->zErrmsg,
- "SELECT name FROM sqlite_schema WHERE rootpage = ?"
+ "SELECT name FROM sqlcipher_master WHERE rootpage = ?"
);
if( p->rc==SQLITE_OK ){
sqlite3_bind_int(pQuery, 1, tnum);
if( rc==SQLITE_OK ){
rc = prepareAndCollectError(p->dbMain, &pStmt, &p->zErrmsg,
- "SELECT trim(sql) FROM sqlite_schema WHERE type='index' AND name=?"
+ "SELECT trim(sql) FROM sqlcipher_master WHERE type='index' AND name=?"
);
}
if( rc==SQLITE_OK ){
int bOk = 0;
sqlite3_stmt *pCnt = 0;
p->rc = prepareAndCollectError(p->dbRbu, &pCnt, &p->zErrmsg,
- "SELECT count(*) FROM stat.sqlite_schema"
+ "SELECT count(*) FROM stat.sqlcipher_master"
);
if( p->rc==SQLITE_OK
&& sqlite3_step(pCnt)==SQLITE_ROW
if( p->rc==SQLITE_OK ){
p->rc = sqlite3_file_control(p->dbMain, "main", SQLITE_FCNTL_RBU, (void*)p);
}
- rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlite_schema");
+ rbuMPrintfExec(p, p->dbMain, "SELECT * FROM sqlcipher_master");
/* Mark the database file just opened as an RBU target database. If
** this call returns SQLITE_NOTFOUND, then the RBU vfs is not in use.
if( pState==0 ){
p->eStage = 0;
if( p->rc==SQLITE_OK ){
- p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlite_schema", 0, 0, 0);
+ p->rc = sqlite3_exec(p->dbMain, "SELECT * FROM sqlcipher_master", 0, 0, 0);
}
}
p->rc = sqlite3_exec(p->dbMain, "PRAGMA writable_schema=1", 0,0, &p->zErrmsg);
if( p->rc==SQLITE_OK ){
p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
- "SELECT sql FROM sqlite_schema WHERE sql!='' AND rootpage!=0"
- " AND name!='sqlite_sequence' "
+ "SELECT sql FROM sqlcipher_master WHERE sql!='' AND rootpage!=0"
+ " AND name!='sqlcipher_sequence' "
" ORDER BY type DESC"
);
}
if( p->rc==SQLITE_OK ){
p->rc = prepareAndCollectError(p->dbRbu, &pSql, &p->zErrmsg,
- "SELECT * FROM sqlite_schema WHERE rootpage=0 OR rootpage IS NULL"
+ "SELECT * FROM sqlcipher_master WHERE rootpage=0 OR rootpage IS NULL"
);
}
if( p->rc==SQLITE_OK ){
p->rc = prepareAndCollectError(p->dbMain, &pInsert, &p->zErrmsg,
- "INSERT INTO sqlite_schema VALUES(?,?,?,?,?)"
+ "INSERT INTO sqlcipher_master VALUES(?,?,?,?,?)"
);
}
assert( nVal==1 );
rc = prepareFreeAndCollectError(db, &pStmt, &zErrmsg,
- sqlite3_mprintf("SELECT count(*) FROM sqlite_schema "
+ sqlite3_mprintf("SELECT count(*) FROM sqlcipher_master "
"WHERE type='index' AND tbl_name = %Q", sqlite3_value_text(apVal[0]))
);
if( rc!=SQLITE_OK ){
** occurs, nPhaseOneStep will be left set to -1. */
if( p->rc==SQLITE_OK ){
p->rc = prepareAndCollectError(p->dbRbu, &pStmt, &p->zErrmsg,
- "SELECT 1 FROM sqlite_schema WHERE tbl_name = 'rbu_count'"
+ "SELECT 1 FROM sqlcipher_master WHERE tbl_name = 'rbu_count'"
);
}
if( p->rc==SQLITE_OK ){
pSql = sqlite3_str_new(pTab->db);
sqlite3_str_appendf(pSql,
"SELECT * FROM ("
- "SELECT 'sqlite_schema' AS name,1 AS rootpage,'table' AS type"
+ "SELECT 'sqlcipher_master' AS name,1 AS rootpage,'table' AS type"
" UNION ALL "
"SELECT name,rootpage,type"
- " FROM \"%w\".sqlite_schema WHERE rootpage!=0)",
+ " FROM \"%w\".sqlcipher_master WHERE rootpage!=0)",
pTab->db->aDb[pCsr->iDb].zDbSName);
if( zName ){
sqlite3_str_appendf(pSql, "WHERE name=%Q", zName);
assert( pazCol && pabPK );
nThis = sqlite3Strlen30(zThis);
- if( nThis==12 && 0==sqlite3_stricmp("sqlite_stat1", zThis) ){
+ if( nThis==12 && 0==sqlite3_stricmp("sqlcipher_stat1", zThis) ){
rc = sqlite3_table_column_metadata(db, zDb, zThis, 0, 0, 0, 0, 0, 0);
if( rc==SQLITE_OK ){
/* For sqlite_stat1, pretend that (tbl,idx) is the PRIMARY KEY. */
break;
}
}
- if( 0==sqlite3_stricmp("sqlite_stat1", pTab->zName) ){
+ if( 0==sqlite3_stricmp("sqlcipher_stat1", pTab->zName) ){
pTab->bStat1 = 1;
}
}
if( 0==sqlite3_stricmp("sqlite_stat1", zTab) ){
zSql = sqlite3_mprintf(
- "SELECT tbl, ?2, stat FROM %Q.sqlite_stat1 WHERE tbl IS ?1 AND "
+ "SELECT tbl, ?2, stat FROM %Q.sqlcipher_stat1 WHERE tbl IS ?1 AND "
"idx IS (CASE WHEN ?2=X'' THEN NULL ELSE ?2 END)", zDb
);
if( zSql==0 ) rc = SQLITE_NOMEM;
** other tables.
*/
static int sessionStat1Sql(sqlite3 *db, SessionApplyCtx *p){
- int rc = sessionSelectRow(db, "sqlite_stat1", p);
+ int rc = sessionSelectRow(db, "sqlcipher_stat1", p);
if( rc==SQLITE_OK ){
rc = sessionPrepare(db, &p->pInsert,
- "INSERT INTO main.sqlite_stat1 VALUES(?1, "
+ "INSERT INTO main.sqlcipher_stat1 VALUES(?1, "
"CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END, "
"?3)"
);
}
if( rc==SQLITE_OK ){
rc = sessionPrepare(db, &p->pUpdate,
- "UPDATE main.sqlite_stat1 SET "
+ "UPDATE main.sqlcipher_stat1 SET "
"tbl = CASE WHEN ?2 THEN ?3 ELSE tbl END, "
"idx = CASE WHEN ?5 THEN ?6 ELSE idx END, "
"stat = CASE WHEN ?8 THEN ?9 ELSE stat END "
}
if( rc==SQLITE_OK ){
rc = sessionPrepare(db, &p->pDelete,
- "DELETE FROM main.sqlite_stat1 WHERE tbl=?1 AND idx IS "
+ "DELETE FROM main.sqlcipher_stat1 WHERE tbl=?1 AND idx IS "
"CASE WHEN length(?2)=0 AND typeof(?2)='blob' THEN NULL ELSE ?2 END "
"AND (?4 OR stat IS ?3)"
);
}
else{
sApply.nCol = nCol;
- if( 0==sqlite3_stricmp(zTab, "sqlite_stat1") ){
+ if( 0==sqlite3_stricmp(zTab, "sqlcipher_stat1") ){
if( (rc = sessionStat1Sql(db, &sApply) ) ){
break;
}
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
/************************** End of sqlite3.c ******************************/
+#pragma GCC diagnostic pop
/************** Begin file dbdump.c ********************************************/
/*
** 2016-03-13
** of the database file, the schema, and optionally the table, forming the
** first three arguments of a single call to the library routine.
*/
-#include "sqlite3.h"
-#include <stdarg.h>
-#include <string.h>
#include <ctype.h>
/*
** If the third argument, quote, is not '\0', then it is used as a
** quote character for zAppend.
*/
-static void appendText(DText *p, char const *zAppend, char quote){
+static void appendDText(DText *p, char const *zAppend, char quote){
int len;
int i;
int nAppend = (int)(strlen(zAppend) & 0x3fffffff);
nPK++;
if( nPK==1
&& sqlite3_stricmp((const char*)sqlite3_column_text(pStmt,2),
- "INTEGER")==0
+ "INTEGER")==0
){
isIPK = 1;
}else{
zType = azArg[1];
zSql = azArg[2];
- if( strcmp(zTable, "sqlite_sequence")==0 ){
+ if( strcmp(zTable, "sqlcipher_sequence")==0 ){
p->xCallback("DELETE FROM sqlite_sequence;\n", p->pArg);
- }else if( sqlite3_strglob("sqlite_stat?", zTable)==0 ){
+ }else if( sqlite3_strglob("sqlcipher_stat?", zTable)==0 ){
p->xCallback("ANALYZE sqlite_schema;\n", p->pArg);
- }else if( strncmp(zTable, "sqlite_", 7)==0 ){
+ }else if( strncmp(zTable, "sqlcipher_", 10)==0 ){
return 0;
}else if( strncmp(zSql, "CREATE VIRTUAL TABLE", 20)==0 ){
if( !p->writableSchema ){
if( azTCol==0 ) return 0;
initText(&sTable);
- appendText(&sTable, "INSERT INTO ", 0);
+ appendDText(&sTable, "INSERT INTO ", 0);
/* Always quote the table name, even if it appears to be pure ascii,
** in case it is a keyword. Ex: INSERT INTO "table" ... */
- appendText(&sTable, zTable, quoteChar(zTable));
+ if (strncmp(zTable, "sqlcipher_", sizeof "sqlcipher"))
+ appendDText(&sTable, zTable, quoteChar(zTable));
+ else {
+ appendDText(&sTable, "sqlite_", 0);
+ appendDText(&sTable, zTable + sizeof "sqlcipher", 0);
+ }
/* If preserving the rowid, add a column list after the table name.
** In other words: "INSERT INTO tab(rowid,a,b,c,...) VALUES(...)"
** instead of the usual "INSERT INTO tab VALUES(...)".
*/
if( azTCol[0] ){
- appendText(&sTable, "(", 0);
- appendText(&sTable, azTCol[0], 0);
+ appendDText(&sTable, "(", 0);
+ appendDText(&sTable, azTCol[0], 0);
for(i=1; azTCol[i]; i++){
- appendText(&sTable, ",", 0);
- appendText(&sTable, azTCol[i], quoteChar(azTCol[i]));
+ appendDText(&sTable, ",", 0);
+ appendDText(&sTable, azTCol[i], quoteChar(azTCol[i]));
}
- appendText(&sTable, ")", 0);
+ appendDText(&sTable, ")", 0);
}
- appendText(&sTable, " VALUES(", 0);
+ appendDText(&sTable, " VALUES(", 0);
/* Build an appropriate SELECT statement */
initText(&sSelect);
- appendText(&sSelect, "SELECT ", 0);
+ appendDText(&sSelect, "SELECT ", 0);
if( azTCol[0] ){
- appendText(&sSelect, azTCol[0], 0);
- appendText(&sSelect, ",", 0);
+ appendDText(&sSelect, azTCol[0], 0);
+ appendDText(&sSelect, ",", 0);
}
for(i=1; azTCol[i]; i++){
- appendText(&sSelect, azTCol[i], quoteChar(azTCol[i]));
+ appendDText(&sSelect, azTCol[i], quoteChar(azTCol[i]));
if( azTCol[i+1] ){
- appendText(&sSelect, ",", 0);
+ appendDText(&sSelect, ",", 0);
}
}
nCol = i;
if( azTCol[0]==0 ) nCol--;
freeColumnList(azTCol);
- appendText(&sSelect, " FROM ", 0);
- appendText(&sSelect, zTable, quoteChar(zTable));
+ appendDText(&sSelect, " FROM ", 0);
+ appendDText(&sSelect, zTable, quoteChar(zTable));
rc = sqlite3_prepare_v2(p->db, sSelect.z, -1, &pStmt, 0);
if( rc!=SQLITE_OK ){
break;
}
case SQLITE_TEXT: {
- output_quoted_escaped_string(p,
+ output_quoted_escaped_string(p,
(const char*)sqlite3_column_text(pStmt,i));
break;
}
va_list ap;
va_start(ap, zQuery);
z = sqlite3_vmprintf(zQuery, ap);
- va_end(ap);
+ va_end(ap);
sqlite3_exec(p->db, z, dump_callback, p, &zErr);
sqlite3_free(z);
if( zErr ){
*/
int sqlite3_db_dump(
sqlite3 *db, /* The database connection */
- const char *zSchema, /* Which schema to dump. Usually "main". */
- const char *zTable, /* Which table to dump. NULL means everything. */
int (*xCallback)(const char*,void*), /* Output sent to this callback */
void *pArg /* Second argument of the callback */
){
x.xCallback = xCallback;
x.pArg = pArg;
xCallback("PRAGMA foreign_keys=OFF;\nBEGIN TRANSACTION;\n", pArg);
- if( zTable==0 ){
- run_schema_dump_query(&x,
- "SELECT name, type, sql FROM \"%w\".sqlite_schema "
- "WHERE sql NOT NULL AND type=='table' AND name!='sqlite_sequence'",
- zSchema
- );
- run_schema_dump_query(&x,
- "SELECT name, type, sql FROM \"%w\".sqlite_schema "
- "WHERE name=='sqlite_sequence'", zSchema
- );
- output_sql_from_query(&x,
- "SELECT sql FROM sqlite_schema "
- "WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0
- );
- }else{
- run_schema_dump_query(&x,
- "SELECT name, type, sql FROM \"%w\".sqlite_schema "
- "WHERE tbl_name=%Q COLLATE nocase AND type=='table'"
- " AND sql NOT NULL",
- zSchema, zTable
- );
- output_sql_from_query(&x,
- "SELECT sql FROM \"%w\".sqlite_schema "
- "WHERE sql NOT NULL"
- " AND type IN ('index','trigger','view')"
- " AND tbl_name=%Q COLLATE nocase",
- zSchema, zTable
- );
- }
+ run_schema_dump_query(&x,
+ "SELECT name, type, sql FROM sqlcipher_master "
+ "WHERE sql NOT NULL AND type=='table' AND name!='sqlcipher_sequence'"
+ );
+ run_schema_dump_query(&x,
+ "SELECT name, type, sql FROM sqlcipher_master "
+ "WHERE name=='sqlcipher_sequence'"
+ );
+ output_sql_from_query(&x,
+ "SELECT sql FROM sqlcipher_master "
+ "WHERE sql NOT NULL AND type IN ('index','trigger','view')", 0
+ );
if( x.writableSchema ){
xCallback("PRAGMA writable_schema=OFF;\n", pArg);
}
xCallback(x.nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n", pArg);
sqlite3_exec(db, "COMMIT", 0, 0, 0);
- return x.rc;
+ return x.rc ?: x.nErr ? SQLITE_ERROR : SQLITE_OK;
}
/************** End of dbdump.c ************************************************/