mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-08 14:02:16 +03:00
Merge latest trunk change into this branch.
FossilOrigin-Name: 2b3241cf67c8eea761760ac27df7a136bcca2dca10c152a36b216c5dc88cdb53
This commit is contained in:
@@ -440,7 +440,7 @@ int main(int argc, char **argv){
|
||||
fprintf(stderr, "cannot open database file '%s'\n", zDb);
|
||||
continue;
|
||||
}
|
||||
rc = sqlite3_exec(g.db, "SELECT * FROM sqlite_master", 0, 0, &zErrMsg);
|
||||
rc = sqlite3_exec(g.db, "SELECT * FROM sqlite_schema", 0, 0, &zErrMsg);
|
||||
if( rc || zErrMsg ){
|
||||
sqlite3_close(g.db);
|
||||
g.db = 0;
|
||||
@@ -454,7 +454,7 @@ int main(int argc, char **argv){
|
||||
/* Hash table content */
|
||||
if( !omitContent ){
|
||||
pStmt = db_prepare(
|
||||
"SELECT name FROM sqlite_master\n"
|
||||
"SELECT name FROM sqlite_schema\n"
|
||||
" WHERE type='table' AND sql NOT LIKE 'CREATE VIRTUAL%%'\n"
|
||||
" AND name NOT LIKE 'sqlite_%%'\n"
|
||||
" AND name LIKE '%q'\n"
|
||||
@@ -476,7 +476,7 @@ int main(int argc, char **argv){
|
||||
/* Hash the database schema */
|
||||
if( !omitSchema ){
|
||||
hash_one_query(
|
||||
"SELECT type, name, tbl_name, sql FROM sqlite_master\n"
|
||||
"SELECT type, name, tbl_name, sql FROM sqlite_schema\n"
|
||||
" WHERE tbl_name LIKE '%q'\n"
|
||||
" ORDER BY name COLLATE nocase;\n",
|
||||
zLike
|
||||
|
68
tool/enlargedb.c
Normal file
68
tool/enlargedb.c
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
** Try to enlarge an SQLite database by appending many unused pages.
|
||||
** The resulting database will fail PRAGMA integrity_check due to the
|
||||
** appended unused pages, but it should work otherwise.
|
||||
**
|
||||
** Usage:
|
||||
**
|
||||
** enlargedb DATABASE N
|
||||
**
|
||||
** Adds N blank pages onto the end of DATABASE. N can be decimal
|
||||
** or hex. The total number of pages after adding must be no greater
|
||||
** than 4294967297
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv){
|
||||
char *zEnd;
|
||||
long long int toAppend;
|
||||
long long int currentSz;
|
||||
long long int newSz;
|
||||
FILE *f;
|
||||
size_t got;
|
||||
int pgsz;
|
||||
char zero = 0;
|
||||
unsigned char buf[100];
|
||||
|
||||
if( argc!=3 ) goto usage_error;
|
||||
toAppend = strtoll(argv[2], &zEnd, 0);
|
||||
if( zEnd==argv[2] || zEnd[0] ) goto usage_error;
|
||||
if( toAppend<1 ){
|
||||
fprintf(stderr, "N must be at least 1\n");
|
||||
exit(1);
|
||||
}
|
||||
f = fopen(argv[1], "r+b");
|
||||
if( f==0 ){
|
||||
fprintf(stderr, "cannot open \"%s\" for reading and writing\n", argv[1]);
|
||||
exit(1);
|
||||
}
|
||||
got = fread(buf, 1, sizeof(buf), f);
|
||||
if( got!=sizeof(buf) ) goto not_valid_db;
|
||||
if( strcmp((char*)buf,"SQLite format 3")!=0 ) goto not_valid_db;
|
||||
pgsz = (buf[16]<<8) + buf[17];
|
||||
if( pgsz==1 ) pgsz = 65536;
|
||||
if( pgsz<512 || pgsz>65536 || (pgsz&(pgsz-1))!=0 ) goto not_valid_db;
|
||||
currentSz = (buf[28]<<24) + (buf[29]<<16) + (buf[30]<<8) + buf[31];
|
||||
newSz = currentSz + toAppend;
|
||||
if( newSz > 0xffffffff ) newSz = 0xffffffff;
|
||||
buf[28] = (newSz>>24) & 0xff;
|
||||
buf[29] = (newSz>>16) & 0xff;
|
||||
buf[30] = (newSz>>8) & 0xff;
|
||||
buf[31] = newSz & 0xff;
|
||||
fseek(f, 28, SEEK_SET);
|
||||
fwrite(&buf[28],4,1,f);
|
||||
fseek(f, (long)(newSz*pgsz - 1), SEEK_SET);
|
||||
fwrite(&zero,1,1,f);
|
||||
fclose(f);
|
||||
return 0;
|
||||
|
||||
not_valid_db:
|
||||
fprintf(stderr,"not a valid database: %s\n", argv[1]);
|
||||
exit(1);
|
||||
|
||||
usage_error:
|
||||
fprintf(stderr,"Usage: %s DATABASE N\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
@@ -150,7 +150,7 @@ int main(int argc, char **argv){
|
||||
*/
|
||||
|
||||
/* The vacuum will occur inside of a transaction. Set writable_schema
|
||||
** to ON so that we can directly update the sqlite_master table in the
|
||||
** to ON so that we can directly update the sqlite_schema table in the
|
||||
** zTempDb database.
|
||||
*/
|
||||
execSql(db, "PRAGMA writable_schema=ON");
|
||||
@@ -162,16 +162,16 @@ int main(int argc, char **argv){
|
||||
*/
|
||||
execExecSql(db,
|
||||
"SELECT 'CREATE TABLE vacuum_db.' || substr(sql,14) "
|
||||
" FROM sqlite_master WHERE type='table' AND name!='sqlite_sequence'"
|
||||
" FROM sqlite_schema WHERE type='table' AND name!='sqlite_sequence'"
|
||||
" AND rootpage>0"
|
||||
);
|
||||
execExecSql(db,
|
||||
"SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)"
|
||||
" FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %'"
|
||||
" FROM sqlite_schema WHERE sql LIKE 'CREATE INDEX %'"
|
||||
);
|
||||
execExecSql(db,
|
||||
"SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21) "
|
||||
" FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'"
|
||||
" FROM sqlite_schema WHERE sql LIKE 'CREATE UNIQUE INDEX %'"
|
||||
);
|
||||
|
||||
/* Loop through the tables in the main database. For each, do
|
||||
@@ -181,7 +181,7 @@ int main(int argc, char **argv){
|
||||
execExecSql(db,
|
||||
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
|
||||
"|| ' SELECT * FROM main.' || quote(name) "
|
||||
"FROM main.sqlite_master "
|
||||
"FROM main.sqlite_schema "
|
||||
"WHERE type = 'table' AND name!='sqlite_sequence' "
|
||||
" AND rootpage>0"
|
||||
);
|
||||
@@ -190,12 +190,12 @@ int main(int argc, char **argv){
|
||||
*/
|
||||
execExecSql(db,
|
||||
"SELECT 'DELETE FROM vacuum_db.' || quote(name) "
|
||||
"FROM vacuum_db.sqlite_master WHERE name='sqlite_sequence'"
|
||||
"FROM vacuum_db.sqlite_schema WHERE name='sqlite_sequence'"
|
||||
);
|
||||
execExecSql(db,
|
||||
"SELECT 'INSERT INTO vacuum_db.' || quote(name) "
|
||||
"|| ' SELECT * FROM main.' || quote(name) "
|
||||
"FROM vacuum_db.sqlite_master WHERE name=='sqlite_sequence'"
|
||||
"FROM vacuum_db.sqlite_schema WHERE name=='sqlite_sequence'"
|
||||
);
|
||||
|
||||
/* Copy the triggers, views, and virtual tables from the main database
|
||||
@@ -204,9 +204,9 @@ int main(int argc, char **argv){
|
||||
** from the SQLITE_MASTER table.
|
||||
*/
|
||||
execSql(db,
|
||||
"INSERT INTO vacuum_db.sqlite_master "
|
||||
"INSERT INTO vacuum_db.sqlite_schema "
|
||||
" SELECT type, name, tbl_name, rootpage, sql"
|
||||
" FROM main.sqlite_master"
|
||||
" FROM main.sqlite_schema"
|
||||
" WHERE type='view' OR type='trigger'"
|
||||
" OR (type='table' AND rootpage=0)"
|
||||
);
|
||||
|
@@ -104,7 +104,7 @@ int main(int argc, char **argv){
|
||||
printf("Cannot open \"%s\" for reading: %s\n", argv[1], sqlite3_errmsg(db));
|
||||
goto errorOut;
|
||||
}
|
||||
rc = sqlite3_prepare_v2(db, "SELECT * FROM sqlite_master", -1, &pStmt, 0);
|
||||
rc = sqlite3_prepare_v2(db, "SELECT * FROM sqlite_schema", -1, &pStmt, 0);
|
||||
if( rc ){
|
||||
printf("Cannot read the schema from \"%s\" - %s\n", argv[1],
|
||||
sqlite3_errmsg(db));
|
||||
@@ -126,7 +126,7 @@ int main(int argc, char **argv){
|
||||
}
|
||||
rc = sqlite3_exec(db,
|
||||
"INSERT INTO temp.idxu(tbl,idx,cnt)"
|
||||
" SELECT tbl_name, name, 0 FROM sqlite_master"
|
||||
" SELECT tbl_name, name, 0 FROM sqlite_schema"
|
||||
" WHERE type='index' AND sql IS NOT NULL", 0, 0, 0);
|
||||
|
||||
/* Open the LOG database */
|
||||
@@ -205,9 +205,9 @@ int main(int argc, char **argv){
|
||||
rc = sqlite3_prepare_v2(db,
|
||||
"SELECT tbl, idx, cnt, "
|
||||
" (SELECT group_concat(name,',') FROM pragma_index_info(idx))"
|
||||
" FROM temp.idxu, main.sqlite_master"
|
||||
" WHERE temp.idxu.tbl=main.sqlite_master.tbl_name"
|
||||
" AND temp.idxu.idx=main.sqlite_master.name"
|
||||
" FROM temp.idxu, main.sqlite_schema"
|
||||
" WHERE temp.idxu.tbl=main.sqlite_schema.tbl_name"
|
||||
" AND temp.idxu.idx=main.sqlite_schema.name"
|
||||
" ORDER BY cnt DESC, tbl, idx",
|
||||
-1, &pStmt, 0);
|
||||
if( rc ){
|
||||
|
143
tool/lemon.c
143
tool/lemon.c
@@ -423,6 +423,7 @@ struct lemon {
|
||||
int nlookaheadtab; /* Number of entries in yy_lookahead[] */
|
||||
int tablesize; /* Total table size of all tables in bytes */
|
||||
int basisflag; /* Print only basis configurations */
|
||||
int printPreprocessed; /* Show preprocessor output on stdout */
|
||||
int has_fallback; /* True if any %fallback is seen in the grammar */
|
||||
int nolinenosflag; /* True if #line statements should not be printed */
|
||||
char *argv0; /* Name of the program */
|
||||
@@ -1636,12 +1637,14 @@ int main(int argc, char **argv)
|
||||
static int nolinenosflag = 0;
|
||||
static int noResort = 0;
|
||||
static int sqlFlag = 0;
|
||||
static int printPP = 0;
|
||||
|
||||
static struct s_options options[] = {
|
||||
{OPT_FLAG, "b", (char*)&basisflag, "Print only the basis in report."},
|
||||
{OPT_FLAG, "c", (char*)&compress, "Don't compress the action table."},
|
||||
{OPT_FSTR, "d", (char*)&handle_d_option, "Output directory. Default '.'"},
|
||||
{OPT_FSTR, "D", (char*)handle_D_option, "Define an %ifdef macro."},
|
||||
{OPT_FLAG, "E", (char*)&printPP, "Print input file after preprocessing."},
|
||||
{OPT_FSTR, "f", 0, "Ignored. (Placeholder for -f compiler options.)"},
|
||||
{OPT_FLAG, "g", (char*)&rpflag, "Print grammar without actions."},
|
||||
{OPT_FSTR, "I", 0, "Ignored. (Placeholder for '-I' compiler options.)"},
|
||||
@@ -1686,11 +1689,12 @@ int main(int argc, char **argv)
|
||||
lem.filename = OptArg(0);
|
||||
lem.basisflag = basisflag;
|
||||
lem.nolinenosflag = nolinenosflag;
|
||||
lem.printPreprocessed = printPP;
|
||||
Symbol_new("$");
|
||||
|
||||
/* Parse the input file */
|
||||
Parse(&lem);
|
||||
if( lem.errorcnt ) exit(lem.errorcnt);
|
||||
if( lem.printPreprocessed || lem.errorcnt ) exit(lem.errorcnt);
|
||||
if( lem.nrule==0 ){
|
||||
fprintf(stderr,"Empty grammar.\n");
|
||||
exit(1);
|
||||
@@ -2779,13 +2783,108 @@ static void parseonetoken(struct pstate *psp)
|
||||
}
|
||||
}
|
||||
|
||||
/* The text in the input is part of the argument to an %ifdef or %ifndef.
|
||||
** Evaluate the text as a boolean expression. Return true or false.
|
||||
*/
|
||||
static int eval_preprocessor_boolean(char *z, int lineno){
|
||||
int neg = 0;
|
||||
int res = 0;
|
||||
int okTerm = 1;
|
||||
int i;
|
||||
for(i=0; z[i]!=0; i++){
|
||||
if( ISSPACE(z[i]) ) continue;
|
||||
if( z[i]=='!' ){
|
||||
if( !okTerm ) goto pp_syntax_error;
|
||||
neg = !neg;
|
||||
continue;
|
||||
}
|
||||
if( z[i]=='|' && z[i+1]=='|' ){
|
||||
if( okTerm ) goto pp_syntax_error;
|
||||
if( res ) return 1;
|
||||
i++;
|
||||
okTerm = 1;
|
||||
continue;
|
||||
}
|
||||
if( z[i]=='&' && z[i+1]=='&' ){
|
||||
if( okTerm ) goto pp_syntax_error;
|
||||
if( !res ) return 0;
|
||||
i++;
|
||||
okTerm = 1;
|
||||
continue;
|
||||
}
|
||||
if( z[i]=='(' ){
|
||||
int k;
|
||||
int n = 1;
|
||||
if( !okTerm ) goto pp_syntax_error;
|
||||
for(k=i+1; z[k]; k++){
|
||||
if( z[k]==')' ){
|
||||
n--;
|
||||
if( n==0 ){
|
||||
z[k] = 0;
|
||||
res = eval_preprocessor_boolean(&z[i+1], -1);
|
||||
z[k] = ')';
|
||||
if( res<0 ){
|
||||
i = i-res;
|
||||
goto pp_syntax_error;
|
||||
}
|
||||
i = k;
|
||||
break;
|
||||
}
|
||||
}else if( z[k]=='(' ){
|
||||
n++;
|
||||
}else if( z[k]==0 ){
|
||||
i = k;
|
||||
goto pp_syntax_error;
|
||||
}
|
||||
}
|
||||
if( neg ){
|
||||
res = !res;
|
||||
neg = 0;
|
||||
}
|
||||
okTerm = 0;
|
||||
continue;
|
||||
}
|
||||
if( ISALPHA(z[i]) ){
|
||||
int j, k, n;
|
||||
if( !okTerm ) goto pp_syntax_error;
|
||||
for(k=i+1; ISALNUM(z[k]) || z[k]=='_'; k++){}
|
||||
n = k - i;
|
||||
res = 0;
|
||||
for(j=0; j<nDefine; j++){
|
||||
if( strncmp(azDefine[j],&z[i],n)==0 && azDefine[j][n]==0 ){
|
||||
res = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
i = k-1;
|
||||
if( neg ){
|
||||
res = !res;
|
||||
neg = 0;
|
||||
}
|
||||
okTerm = 0;
|
||||
continue;
|
||||
}
|
||||
goto pp_syntax_error;
|
||||
}
|
||||
return res;
|
||||
|
||||
pp_syntax_error:
|
||||
if( lineno>0 ){
|
||||
fprintf(stderr, "%%if syntax error on line %d.\n", lineno);
|
||||
fprintf(stderr, " %.*s <-- syntax error here\n", i+1, z);
|
||||
exit(1);
|
||||
}else{
|
||||
return -(i+1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Run the preprocessor over the input file text. The global variables
|
||||
** azDefine[0] through azDefine[nDefine-1] contains the names of all defined
|
||||
** macros. This routine looks for "%ifdef" and "%ifndef" and "%endif" and
|
||||
** comments them out. Text in between is also commented out as appropriate.
|
||||
*/
|
||||
static void preprocess_input(char *z){
|
||||
int i, j, k, n;
|
||||
int i, j, k;
|
||||
int exclude = 0;
|
||||
int start = 0;
|
||||
int lineno = 1;
|
||||
@@ -2801,21 +2900,33 @@ static void preprocess_input(char *z){
|
||||
}
|
||||
}
|
||||
for(j=i; z[j] && z[j]!='\n'; j++) z[j] = ' ';
|
||||
}else if( (strncmp(&z[i],"%ifdef",6)==0 && ISSPACE(z[i+6]))
|
||||
|| (strncmp(&z[i],"%ifndef",7)==0 && ISSPACE(z[i+7])) ){
|
||||
}else if( strncmp(&z[i],"%else",5)==0 && ISSPACE(z[i+5]) ){
|
||||
if( exclude==1){
|
||||
exclude = 0;
|
||||
for(j=start; j<i; j++) if( z[j]!='\n' ) z[j] = ' ';
|
||||
}else if( exclude==0 ){
|
||||
exclude = 1;
|
||||
start = i;
|
||||
start_lineno = lineno;
|
||||
}
|
||||
for(j=i; z[j] && z[j]!='\n'; j++) z[j] = ' ';
|
||||
}else if( strncmp(&z[i],"%ifdef ",7)==0
|
||||
|| strncmp(&z[i],"%if ",4)==0
|
||||
|| strncmp(&z[i],"%ifndef ",8)==0 ){
|
||||
if( exclude ){
|
||||
exclude++;
|
||||
}else{
|
||||
for(j=i+7; ISSPACE(z[j]); j++){}
|
||||
for(n=0; z[j+n] && !ISSPACE(z[j+n]); n++){}
|
||||
exclude = 1;
|
||||
for(k=0; k<nDefine; k++){
|
||||
if( strncmp(azDefine[k],&z[j],n)==0 && lemonStrlen(azDefine[k])==n ){
|
||||
exclude = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if( z[i+3]=='n' ) exclude = !exclude;
|
||||
int isNot;
|
||||
int iBool;
|
||||
for(j=i; z[j] && !ISSPACE(z[j]); j++){}
|
||||
iBool = j;
|
||||
isNot = (j==i+7);
|
||||
while( z[j] && z[j]!='\n' ){ j++; }
|
||||
k = z[j];
|
||||
z[j] = 0;
|
||||
exclude = eval_preprocessor_boolean(&z[iBool], lineno);
|
||||
z[j] = k;
|
||||
if( !isNot ) exclude = !exclude;
|
||||
if( exclude ){
|
||||
start = i;
|
||||
start_lineno = lineno;
|
||||
@@ -2883,6 +2994,10 @@ void Parse(struct lemon *gp)
|
||||
|
||||
/* Make an initial pass through the file to handle %ifdef and %ifndef */
|
||||
preprocess_input(filebuf);
|
||||
if( gp->printPreprocessed ){
|
||||
printf("%s\n", filebuf);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Now scan the text of the input file */
|
||||
lineno = 1;
|
||||
|
@@ -2,8 +2,8 @@
|
||||
# This script is used to build the amalgamation autoconf package.
|
||||
# It assumes the following:
|
||||
#
|
||||
# 1. The files "sqlite3.c", "sqlite3.h" and "sqlite3ext.h"
|
||||
# are available in the current directory.
|
||||
# 1. The files "sqlite3.c", "sqlite3.h", "sqlite3ext.h", "shell.c",
|
||||
# and "sqlite3rc.h" are available in the current directory.
|
||||
#
|
||||
# 2. Variable $TOP is set to the full path of the root directory
|
||||
# of the SQLite source tree.
|
||||
@@ -49,6 +49,7 @@ cp -R $TOP/autoconf $TMPSPACE
|
||||
cp sqlite3.c $TMPSPACE
|
||||
cp sqlite3.h $TMPSPACE
|
||||
cp sqlite3ext.h $TMPSPACE
|
||||
cp sqlite3rc.h $TMPSPACE
|
||||
cp $TOP/sqlite3.1 $TMPSPACE
|
||||
cp $TOP/sqlite3.pc.in $TMPSPACE
|
||||
cp shell.c $TMPSPACE
|
||||
|
@@ -295,7 +295,7 @@ set pragma_def {
|
||||
IF: !defined(SQLITE_OMIT_FOREIGN_KEY)
|
||||
|
||||
NAME: foreign_key_check
|
||||
FLAG: NeedSchema Result0
|
||||
FLAG: NeedSchema Result0 Result1 SchemaOpt
|
||||
COLS: table rowid parent fkid
|
||||
IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
|
||||
|
||||
|
@@ -183,7 +183,7 @@ proc copy_file {filename} {
|
||||
}
|
||||
set declpattern ^$declpattern\$
|
||||
while {![eof $in]} {
|
||||
set line [gets $in]
|
||||
set line [string trimright [gets $in]]
|
||||
incr ln
|
||||
if {[regexp {^\s*#\s*include\s+["<]([^">]+)[">]} $line all hdr]} {
|
||||
if {[info exists available_hdr($hdr)]} {
|
||||
|
@@ -107,7 +107,7 @@ foreach file $filelist {
|
||||
}
|
||||
while {![eof $in]} {
|
||||
|
||||
set line [gets $in]
|
||||
set line [string trimright [gets $in]]
|
||||
|
||||
# File sqlite3rtree.h contains a line "#include <sqlite3.h>". Omit this
|
||||
# line when copying sqlite3rtree.h into sqlite3.h.
|
||||
|
@@ -75,7 +75,7 @@ static void ofstRootAndColumn(
|
||||
ofstError(p, "cannot open database file \"%s\"", zFile);
|
||||
goto rootAndColumn_exit;
|
||||
}
|
||||
zSql = sqlite3_mprintf("SELECT rootpage FROM sqlite_master WHERE name=%Q",
|
||||
zSql = sqlite3_mprintf("SELECT rootpage FROM sqlite_schema WHERE name=%Q",
|
||||
zTable);
|
||||
rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
|
||||
if( rc ) ofstError(p, "%s: [%s]", sqlite3_errmsg(db), zSql);
|
||||
|
133
tool/showdb.c
133
tool/showdb.c
@@ -20,21 +20,22 @@
|
||||
#include <assert.h>
|
||||
#include "sqlite3.h"
|
||||
|
||||
typedef unsigned char u8; /* unsigned 8-bit */
|
||||
typedef unsigned int u32; /* unsigned 32-bit */
|
||||
typedef sqlite3_int64 i64; /* signed 64-bit */
|
||||
typedef sqlite3_uint64 u64; /* unsigned 64-bit */
|
||||
|
||||
|
||||
static struct GlobalData {
|
||||
int pagesize; /* Size of a database page */
|
||||
u32 pagesize; /* Size of a database page */
|
||||
int dbfd; /* File descriptor for reading the DB */
|
||||
int mxPage; /* Last page number */
|
||||
u32 mxPage; /* Last page number */
|
||||
int perLine; /* HEX elements to print per line */
|
||||
int bRaw; /* True to access db file via OS APIs */
|
||||
sqlite3_file *pFd; /* File descriptor for non-raw mode */
|
||||
sqlite3 *pDb; /* Database handle that owns pFd */
|
||||
} g = {1024, -1, 0, 16, 0, 0, 0};
|
||||
|
||||
|
||||
typedef long long int i64; /* Datatype for 64-bit integers */
|
||||
|
||||
|
||||
/*
|
||||
** Convert the var-int format into i64. Return the number of bytes
|
||||
** in the var-int. Write the var-int value into *pVal.
|
||||
@@ -54,7 +55,7 @@ static int decodeVarint(const unsigned char *z, i64 *pVal){
|
||||
/*
|
||||
** Extract a big-endian 32-bit integer
|
||||
*/
|
||||
static unsigned int decodeInt32(const unsigned char *z){
|
||||
static u32 decodeInt32(const u8 *z){
|
||||
return (z[0]<<24) + (z[1]<<16) + (z[2]<<8) + z[3];
|
||||
}
|
||||
|
||||
@@ -141,7 +142,7 @@ static void fileClose(){
|
||||
static unsigned char *fileRead(sqlite3_int64 ofst, int nByte){
|
||||
unsigned char *aData;
|
||||
int got;
|
||||
aData = sqlite3_malloc(nByte+32);
|
||||
aData = sqlite3_malloc64(32+(i64)nByte);
|
||||
if( aData==0 ) out_of_memory();
|
||||
memset(aData, 0, nByte+32);
|
||||
if( g.bRaw==0 ){
|
||||
@@ -161,8 +162,8 @@ static unsigned char *fileRead(sqlite3_int64 ofst, int nByte){
|
||||
/*
|
||||
** Return the size of the file in byte.
|
||||
*/
|
||||
static sqlite3_int64 fileGetsize(void){
|
||||
sqlite3_int64 res = 0;
|
||||
static i64 fileGetsize(void){
|
||||
i64 res = 0;
|
||||
if( g.bRaw==0 ){
|
||||
int rc = g.pFd->pMethods->xFileSize(g.pFd, &res);
|
||||
if( rc!=SQLITE_OK ){
|
||||
@@ -185,9 +186,9 @@ static sqlite3_int64 fileGetsize(void){
|
||||
** Print a range of bytes as hex and as ascii.
|
||||
*/
|
||||
static unsigned char *print_byte_range(
|
||||
int ofst, /* First byte in the range of bytes to print */
|
||||
int nByte, /* Number of bytes to print */
|
||||
int printOfst /* Add this amount to the index on the left column */
|
||||
sqlite3_int64 ofst, /* First byte in the range of bytes to print */
|
||||
int nByte, /* Number of bytes to print */
|
||||
int printOfst /* Add this amount to the index on the left column */
|
||||
){
|
||||
unsigned char *aData;
|
||||
int i, j;
|
||||
@@ -207,6 +208,12 @@ static unsigned char *print_byte_range(
|
||||
|
||||
aData = fileRead(ofst, nByte);
|
||||
for(i=0; i<nByte; i += g.perLine){
|
||||
int go = 0;
|
||||
for(j=0; j<g.perLine; j++){
|
||||
if( i+j>nByte ){ break; }
|
||||
if( aData[i+j] ){ go = 1; break; }
|
||||
}
|
||||
if( !go && i>0 && i+g.perLine<nByte ) continue;
|
||||
fprintf(stdout, zOfstFmt, i+printOfst);
|
||||
for(j=0; j<g.perLine; j++){
|
||||
if( i+j>nByte ){
|
||||
@@ -230,18 +237,18 @@ static unsigned char *print_byte_range(
|
||||
/*
|
||||
** Print an entire page of content as hex
|
||||
*/
|
||||
static void print_page(int iPg){
|
||||
int iStart;
|
||||
static void print_page(u32 iPg){
|
||||
i64 iStart;
|
||||
unsigned char *aData;
|
||||
iStart = (iPg-1)*g.pagesize;
|
||||
fprintf(stdout, "Page %d: (offsets 0x%x..0x%x)\n",
|
||||
iStart = ((i64)(iPg-1))*g.pagesize;
|
||||
fprintf(stdout, "Page %u: (offsets 0x%llx..0x%llx)\n",
|
||||
iPg, iStart, iStart+g.pagesize-1);
|
||||
aData = print_byte_range(iStart, g.pagesize, 0);
|
||||
sqlite3_free(aData);
|
||||
}
|
||||
|
||||
|
||||
/* Print a line of decode output showing a 4-byte integer.
|
||||
/* Print a line of decoded output showing a 4-byte unsigned integer.
|
||||
*/
|
||||
static void print_decode_line(
|
||||
unsigned char *aData, /* Content being decoded */
|
||||
@@ -249,7 +256,7 @@ static void print_decode_line(
|
||||
const char *zMsg /* Message to append */
|
||||
){
|
||||
int i, j;
|
||||
int val = aData[ofst];
|
||||
u32 val = aData[ofst];
|
||||
char zBuf[100];
|
||||
sprintf(zBuf, " %03x: %02x", ofst, aData[ofst]);
|
||||
i = (int)strlen(zBuf);
|
||||
@@ -262,7 +269,7 @@ static void print_decode_line(
|
||||
}
|
||||
i += (int)strlen(&zBuf[i]);
|
||||
}
|
||||
sprintf(&zBuf[i], " %9d", val);
|
||||
sprintf(&zBuf[i], " %10u", val);
|
||||
printf("%s %s\n", zBuf, zMsg);
|
||||
}
|
||||
|
||||
@@ -296,6 +303,7 @@ static void print_db_header(void){
|
||||
print_decode_line(aData, 88, 4, "meta[12]");
|
||||
print_decode_line(aData, 92, 4, "Change counter for version number");
|
||||
print_decode_line(aData, 96, 4, "SQLite version number");
|
||||
sqlite3_free(aData);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -408,7 +416,7 @@ static i64 describeCell(
|
||||
int i;
|
||||
i64 nDesc = 0;
|
||||
int n = 0;
|
||||
int leftChild;
|
||||
u32 leftChild;
|
||||
i64 nPayload;
|
||||
i64 rowid;
|
||||
i64 nLocal;
|
||||
@@ -418,7 +426,7 @@ static i64 describeCell(
|
||||
leftChild = ((a[0]*256 + a[1])*256 + a[2])*256 + a[3];
|
||||
a += 4;
|
||||
n += 4;
|
||||
sprintf(zDesc, "lx: %d ", leftChild);
|
||||
sprintf(zDesc, "lx: %u ", leftChild);
|
||||
nDesc = strlen(zDesc);
|
||||
}
|
||||
if( cType!=5 ){
|
||||
@@ -439,10 +447,10 @@ static i64 describeCell(
|
||||
nDesc += strlen(&zDesc[nDesc]);
|
||||
}
|
||||
if( nLocal<nPayload ){
|
||||
int ovfl;
|
||||
u32 ovfl;
|
||||
unsigned char *b = &a[nLocal];
|
||||
ovfl = ((b[0]*256 + b[1])*256 + b[2])*256 + b[3];
|
||||
sprintf(&zDesc[nDesc], "ov: %d ", ovfl);
|
||||
sprintf(&zDesc[nDesc], "ov: %u ", ovfl);
|
||||
nDesc += strlen(&zDesc[nDesc]);
|
||||
n += 4;
|
||||
}
|
||||
@@ -485,7 +493,7 @@ static void decodeCell(
|
||||
int ofst /* Cell begins at a[ofst] */
|
||||
){
|
||||
int i, j = 0;
|
||||
int leftChild;
|
||||
u32 leftChild;
|
||||
i64 k;
|
||||
i64 nPayload;
|
||||
i64 rowid;
|
||||
@@ -504,7 +512,7 @@ static void decodeCell(
|
||||
if( cType<=5 ){
|
||||
leftChild = ((x[0]*256 + x[1])*256 + x[2])*256 + x[3];
|
||||
printBytes(a, x, 4);
|
||||
printf("left child page:: %d\n", leftChild);
|
||||
printf("left child page:: %u\n", leftChild);
|
||||
x += 4;
|
||||
}
|
||||
if( cType!=5 ){
|
||||
@@ -622,7 +630,7 @@ static void decodeCell(
|
||||
}
|
||||
if( nLocal<nPayload ){
|
||||
printBytes(a, x+nLocal, 4);
|
||||
printf("overflow-page: %d\n", decodeInt32(x+nLocal));
|
||||
printf("overflow-page: %u\n", decodeInt32(x+nLocal));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -729,11 +737,12 @@ static void decode_btree_page(
|
||||
** Decode a freelist trunk page.
|
||||
*/
|
||||
static void decode_trunk_page(
|
||||
int pgno, /* The page number */
|
||||
u32 pgno, /* The page number */
|
||||
int detail, /* Show leaf pages if true */
|
||||
int recursive /* Follow the trunk change if true */
|
||||
){
|
||||
int n, i;
|
||||
u32 i;
|
||||
u32 n;
|
||||
unsigned char *a;
|
||||
while( pgno>0 ){
|
||||
a = fileRead((pgno-1)*g.pagesize, g.pagesize);
|
||||
@@ -741,9 +750,9 @@ static void decode_trunk_page(
|
||||
print_decode_line(a, 0, 4, "Next freelist trunk page");
|
||||
print_decode_line(a, 4, 4, "Number of entries on this page");
|
||||
if( detail ){
|
||||
n = (int)decodeInt32(&a[4]);
|
||||
for(i=0; i<n; i++){
|
||||
unsigned int x = decodeInt32(&a[8+4*i]);
|
||||
n = decodeInt32(&a[4]);
|
||||
for(i=0; i<n && i<g.pagesize/4; i++){
|
||||
u32 x = decodeInt32(&a[8+4*i]);
|
||||
char zIdx[10];
|
||||
sprintf(zIdx, "[%d]", i);
|
||||
printf(" %5s %7u", zIdx, x);
|
||||
@@ -754,7 +763,7 @@ static void decode_trunk_page(
|
||||
if( !recursive ){
|
||||
pgno = 0;
|
||||
}else{
|
||||
pgno = (int)decodeInt32(&a[0]);
|
||||
pgno = decodeInt32(&a[0]);
|
||||
}
|
||||
sqlite3_free(a);
|
||||
}
|
||||
@@ -768,7 +777,7 @@ static char **zPageUse;
|
||||
/*
|
||||
** Add a comment on the use of a page.
|
||||
*/
|
||||
static void page_usage_msg(int pgno, const char *zFormat, ...){
|
||||
static void page_usage_msg(u32 pgno, const char *zFormat, ...){
|
||||
va_list ap;
|
||||
char *zMsg;
|
||||
|
||||
@@ -776,7 +785,7 @@ static void page_usage_msg(int pgno, const char *zFormat, ...){
|
||||
zMsg = sqlite3_vmprintf(zFormat, ap);
|
||||
va_end(ap);
|
||||
if( pgno<=0 || pgno>g.mxPage ){
|
||||
printf("ERROR: page %d out of range 1..%d: %s\n",
|
||||
printf("ERROR: page %d out of range 1..%u: %s\n",
|
||||
pgno, g.mxPage, zMsg);
|
||||
sqlite3_free(zMsg);
|
||||
return;
|
||||
@@ -796,7 +805,7 @@ static void page_usage_msg(int pgno, const char *zFormat, ...){
|
||||
static void page_usage_cell(
|
||||
unsigned char cType, /* Page type */
|
||||
unsigned char *a, /* Cell content */
|
||||
int pgno, /* page containing the cell */
|
||||
u32 pgno, /* page containing the cell */
|
||||
int cellno /* Index of the cell on the page */
|
||||
){
|
||||
int i;
|
||||
@@ -823,10 +832,10 @@ static void page_usage_cell(
|
||||
n += i;
|
||||
}
|
||||
if( nLocal<nPayload ){
|
||||
int ovfl = decodeInt32(a+nLocal);
|
||||
int cnt = 0;
|
||||
u32 ovfl = decodeInt32(a+nLocal);
|
||||
u32 cnt = 0;
|
||||
while( ovfl && (cnt++)<g.mxPage ){
|
||||
page_usage_msg(ovfl, "overflow %d from cell %d of page %d",
|
||||
page_usage_msg(ovfl, "overflow %d from cell %d of page %u",
|
||||
cnt, cellno, pgno);
|
||||
a = fileRead((ovfl-1)*(sqlite3_int64)g.pagesize, 4);
|
||||
ovfl = decodeInt32(a);
|
||||
@@ -851,8 +860,8 @@ static int allZero(unsigned char *a, int n){
|
||||
** this is an orphan page.
|
||||
*/
|
||||
static void page_usage_btree(
|
||||
int pgno, /* Page to describe */
|
||||
int parent, /* Parent of this page. 0 for root pages */
|
||||
u32 pgno, /* Page to describe */
|
||||
u32 parent, /* Parent of this page. 0 for root pages */
|
||||
int idx, /* Which child of the parent */
|
||||
const char *zName /* Name of the table */
|
||||
){
|
||||
@@ -901,9 +910,9 @@ static void page_usage_btree(
|
||||
}
|
||||
if( a[hdr]==2 || a[hdr]==5 ){
|
||||
int cellstart = hdr+12;
|
||||
unsigned int child;
|
||||
u32 child;
|
||||
for(i=0; i<nCell; i++){
|
||||
int ofst;
|
||||
u32 ofst;
|
||||
|
||||
ofst = cellstart + i*2;
|
||||
ofst = a[ofst]*256 + a[ofst+1];
|
||||
@@ -928,7 +937,7 @@ static void page_usage_btree(
|
||||
/*
|
||||
** Determine page usage by the freelist
|
||||
*/
|
||||
static void page_usage_freelist(int pgno){
|
||||
static void page_usage_freelist(u32 pgno){
|
||||
unsigned char *a;
|
||||
int cnt = 0;
|
||||
int i;
|
||||
@@ -955,13 +964,13 @@ static void page_usage_freelist(int pgno){
|
||||
/*
|
||||
** Determine pages used as PTRMAP pages
|
||||
*/
|
||||
static void page_usage_ptrmap(unsigned char *a){
|
||||
static void page_usage_ptrmap(u8 *a){
|
||||
if( decodeInt32(a+52) ){
|
||||
int usable = g.pagesize - a[20];
|
||||
int pgno = 2;
|
||||
u64 pgno = 2;
|
||||
int perPage = usable/5;
|
||||
while( pgno<=g.mxPage ){
|
||||
page_usage_msg(pgno, "PTRMAP page covering %d..%d",
|
||||
page_usage_msg((u32)pgno, "PTRMAP page covering %llu..%llu",
|
||||
pgno+1, pgno+perPage);
|
||||
pgno += perPage + 1;
|
||||
}
|
||||
@@ -972,7 +981,7 @@ static void page_usage_ptrmap(unsigned char *a){
|
||||
** Try to figure out how every page in the database file is being used.
|
||||
*/
|
||||
static void page_usage_report(const char *zPrg, const char *zDbName){
|
||||
int i, j;
|
||||
u32 i, j;
|
||||
int rc;
|
||||
sqlite3 *db;
|
||||
sqlite3_stmt *pStmt;
|
||||
@@ -990,7 +999,7 @@ static void page_usage_report(const char *zPrg, const char *zDbName){
|
||||
|
||||
/* Set up global variables zPageUse[] and g.mxPage to record page
|
||||
** usages */
|
||||
zPageUse = sqlite3_malloc( sizeof(zPageUse[0])*(g.mxPage+1) );
|
||||
zPageUse = sqlite3_malloc64( sizeof(zPageUse[0])*(g.mxPage+1) );
|
||||
if( zPageUse==0 ) out_of_memory();
|
||||
memset(zPageUse, 0, sizeof(zPageUse[0])*(g.mxPage+1));
|
||||
|
||||
@@ -999,7 +1008,7 @@ static void page_usage_report(const char *zPrg, const char *zDbName){
|
||||
page_usage_freelist(decodeInt32(a+32));
|
||||
page_usage_ptrmap(a);
|
||||
sqlite3_free(a);
|
||||
page_usage_btree(1, 0, 0, "sqlite_master");
|
||||
page_usage_btree(1, 0, 0, "sqlite_schema");
|
||||
sqlite3_exec(db, "PRAGMA writable_schema=ON", 0, 0, 0);
|
||||
for(j=0; j<2; j++){
|
||||
sqlite3_snprintf(sizeof(zQuery), zQuery,
|
||||
@@ -1008,7 +1017,7 @@ static void page_usage_report(const char *zPrg, const char *zDbName){
|
||||
rc = sqlite3_prepare_v2(db, zQuery, -1, &pStmt, 0);
|
||||
if( rc==SQLITE_OK ){
|
||||
while( sqlite3_step(pStmt)==SQLITE_ROW ){
|
||||
int pgno = sqlite3_column_int(pStmt, 2);
|
||||
u32 pgno = (u32)sqlite3_column_int64(pStmt, 2);
|
||||
page_usage_btree(pgno, 0, 0, (const char*)sqlite3_column_text(pStmt,1));
|
||||
}
|
||||
}else{
|
||||
@@ -1022,7 +1031,7 @@ static void page_usage_report(const char *zPrg, const char *zDbName){
|
||||
/* Print the report and free memory used */
|
||||
for(i=1; i<=g.mxPage; i++){
|
||||
if( zPageUse[i]==0 ) page_usage_btree(i, -1, 0, 0);
|
||||
printf("%5d: %s\n", i, zPageUse[i] ? zPageUse[i] : "???");
|
||||
printf("%5u: %s\n", i, zPageUse[i] ? zPageUse[i] : "???");
|
||||
sqlite3_free(zPageUse[i]);
|
||||
}
|
||||
sqlite3_free(zPageUse);
|
||||
@@ -1033,7 +1042,7 @@ static void page_usage_report(const char *zPrg, const char *zDbName){
|
||||
** Try to figure out how every page in the database file is being used.
|
||||
*/
|
||||
static void ptrmap_coverage_report(const char *zDbName){
|
||||
int pgno;
|
||||
u64 pgno;
|
||||
unsigned char *aHdr;
|
||||
unsigned char *a;
|
||||
int usable;
|
||||
@@ -1055,14 +1064,14 @@ static void ptrmap_coverage_report(const char *zDbName){
|
||||
usable = g.pagesize - aHdr[20];
|
||||
perPage = usable/5;
|
||||
sqlite3_free(aHdr);
|
||||
printf("%5d: root of sqlite_master\n", 1);
|
||||
printf("%5d: root of sqlite_schema\n", 1);
|
||||
for(pgno=2; pgno<=g.mxPage; pgno += perPage+1){
|
||||
printf("%5d: PTRMAP page covering %d..%d\n", pgno,
|
||||
printf("%5llu: PTRMAP page covering %llu..%llu\n", pgno,
|
||||
pgno+1, pgno+perPage);
|
||||
a = fileRead((pgno-1)*g.pagesize, usable);
|
||||
for(i=0; i+5<=usable && pgno+1+i/5<=g.mxPage; i+=5){
|
||||
const char *zType = "???";
|
||||
unsigned int iFrom = decodeInt32(&a[i+1]);
|
||||
u32 iFrom = decodeInt32(&a[i+1]);
|
||||
switch( a[i] ){
|
||||
case 1: zType = "b-tree root page"; break;
|
||||
case 2: zType = "freelist page"; break;
|
||||
@@ -1070,7 +1079,7 @@ static void ptrmap_coverage_report(const char *zDbName){
|
||||
case 4: zType = "later page of overflow"; break;
|
||||
case 5: zType = "b-tree non-root page"; break;
|
||||
}
|
||||
printf("%5d: %s, parent=%u\n", pgno+1+i/5, zType, iFrom);
|
||||
printf("%5llu: %s, parent=%u\n", pgno+1+i/5, zType, iFrom);
|
||||
}
|
||||
sqlite3_free(a);
|
||||
}
|
||||
@@ -1132,16 +1141,16 @@ int main(int argc, char **argv){
|
||||
sqlite3_free(zPgSz);
|
||||
|
||||
printf("Pagesize: %d\n", g.pagesize);
|
||||
g.mxPage = (int)((szFile+g.pagesize-1)/g.pagesize);
|
||||
g.mxPage = (u32)((szFile+g.pagesize-1)/g.pagesize);
|
||||
|
||||
printf("Available pages: 1..%d\n", g.mxPage);
|
||||
printf("Available pages: 1..%u\n", g.mxPage);
|
||||
if( nArg==2 ){
|
||||
int i;
|
||||
u32 i;
|
||||
for(i=1; i<=g.mxPage; i++) print_page(i);
|
||||
}else{
|
||||
int i;
|
||||
for(i=2; i<nArg; i++){
|
||||
int iStart, iEnd;
|
||||
u32 iStart, iEnd;
|
||||
char *zLeft;
|
||||
if( strcmp(azArg[i], "dbheader")==0 ){
|
||||
print_db_header();
|
||||
@@ -1163,7 +1172,7 @@ int main(int argc, char **argv){
|
||||
fprintf(stderr, "%s: unknown option: [%s]\n", zPrg, azArg[i]);
|
||||
continue;
|
||||
}
|
||||
iStart = strtol(azArg[i], &zLeft, 0);
|
||||
iStart = strtoul(azArg[i], &zLeft, 0);
|
||||
if( zLeft && strcmp(zLeft,"..end")==0 ){
|
||||
iEnd = g.mxPage;
|
||||
}else if( zLeft && zLeft[0]=='.' && zLeft[1]=='.' ){
|
||||
|
@@ -24,23 +24,58 @@
|
||||
static int showLocksInRange(int fd, off_t lwr, off_t upr){
|
||||
int cnt = 0;
|
||||
struct flock x;
|
||||
struct lockRange {
|
||||
off_t lwr;
|
||||
off_t upr;
|
||||
} *aPending = 0;
|
||||
int nAlloc = 1;
|
||||
int nPending = 0;
|
||||
int nDone = 0;
|
||||
|
||||
x.l_type = F_WRLCK;
|
||||
x.l_whence = SEEK_SET;
|
||||
x.l_start = lwr;
|
||||
x.l_len = upr-lwr;
|
||||
fcntl(fd, F_GETLK, &x);
|
||||
if( x.l_type==F_UNLCK ) return 0;
|
||||
printf("start: %-12d len: %-5d pid: %-5d type: %s\n",
|
||||
(int)x.l_start, (int)x.l_len,
|
||||
x.l_pid, x.l_type==F_WRLCK ? "WRLCK" : "RDLCK");
|
||||
cnt++;
|
||||
if( x.l_start>lwr ){
|
||||
cnt += showLocksInRange(fd, lwr, x.l_start-1);
|
||||
nPending = 1;
|
||||
aPending = malloc( sizeof(aPending[0]) );
|
||||
if( aPending==0 ){
|
||||
fprintf(stderr, "out of memory\n");
|
||||
exit(1);
|
||||
}
|
||||
if( x.l_start+x.l_len<upr ){
|
||||
cnt += showLocksInRange(fd, x.l_start+x.l_len+1, upr);
|
||||
aPending[0].lwr = lwr;
|
||||
aPending[0].upr = upr;
|
||||
|
||||
for(nDone=0; nDone<nPending; nDone++){
|
||||
lwr = aPending[nDone].lwr;
|
||||
upr = aPending[nDone].upr;
|
||||
if( lwr>=upr ) continue;
|
||||
x.l_type = F_WRLCK;
|
||||
x.l_whence = SEEK_SET;
|
||||
x.l_start = lwr;
|
||||
x.l_len = upr - lwr;
|
||||
fcntl(fd, F_GETLK, &x);
|
||||
if( x.l_type==F_UNLCK ) continue;
|
||||
printf("start: %-12d len: %-5d pid: %-5d type: %s\n",
|
||||
(int)x.l_start, (int)x.l_len,
|
||||
x.l_pid, x.l_type==F_WRLCK ? "WRLCK" : "RDLCK");
|
||||
cnt++;
|
||||
if( nPending+2 > nAlloc ){
|
||||
nAlloc = nAlloc*2 + 2;
|
||||
aPending = realloc(aPending, sizeof(aPending[0])*nAlloc );
|
||||
}
|
||||
if( aPending==0 ){
|
||||
fprintf(stderr, "unable to realloc for %d bytes\n",
|
||||
(int)sizeof(aPending[0])*(nPending+2));
|
||||
exit(1);
|
||||
}
|
||||
if( lwr<x.l_start ){
|
||||
aPending[nPending].lwr = lwr;
|
||||
aPending[nPending].upr = x.l_start;
|
||||
nPending++;
|
||||
}
|
||||
if( x.l_start+x.l_len<=upr ){
|
||||
aPending[nPending].lwr = x.l_start + x.l_len;
|
||||
aPending[nPending].upr = upr;
|
||||
nPending++;
|
||||
}
|
||||
}
|
||||
free(aPending);
|
||||
return cnt;
|
||||
}
|
||||
|
||||
|
@@ -16,7 +16,7 @@ proc is_without_rowid {tname} {
|
||||
db eval "PRAGMA index_list = '$t'" o {
|
||||
if {$o(origin) == "pk"} {
|
||||
set n $o(name)
|
||||
if {0==[db one { SELECT count(*) FROM sqlite_master WHERE name=$n }]} {
|
||||
if {0==[db one { SELECT count(*) FROM sqlite_schema WHERE name=$n }]} {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
@@ -160,7 +160,7 @@ if {![db exists {SELECT 1 FROM pragma_compile_options
|
||||
exit 1
|
||||
}
|
||||
|
||||
db eval {SELECT count(*) FROM sqlite_master}
|
||||
db eval {SELECT count(*) FROM sqlite_schema}
|
||||
set pageSize [expr {wide([db one {PRAGMA page_size}])}]
|
||||
|
||||
if {$flags(-pageinfo)} {
|
||||
@@ -245,8 +245,8 @@ db eval {DROP TABLE temp.stat}
|
||||
set isCompressed 0
|
||||
set compressOverhead 0
|
||||
set depth 0
|
||||
set sql { SELECT name, tbl_name FROM sqlite_master WHERE rootpage>0 }
|
||||
foreach {name tblname} [concat sqlite_master sqlite_master [db eval $sql]] {
|
||||
set sql { SELECT name, tbl_name FROM sqlite_schema WHERE rootpage>0 }
|
||||
foreach {name tblname} [concat sqlite_schema sqlite_schema [db eval $sql]] {
|
||||
|
||||
set is_index [expr {$name!=$tblname}]
|
||||
set is_without_rowid [is_without_rowid $name]
|
||||
@@ -560,7 +560,7 @@ proc autovacuum_overhead {filePages pageSize} {
|
||||
# nautoindex: Number of indices created automatically.
|
||||
# nmanindex: Number of indices created manually.
|
||||
# user_payload: Number of bytes of payload in table btrees
|
||||
# (not including sqlite_master)
|
||||
# (not including sqlite_schema)
|
||||
# user_percent: $user_payload as a percentage of total file size.
|
||||
|
||||
### The following, setting $file_bytes based on the actual size of the file
|
||||
@@ -590,15 +590,15 @@ set file_pgcnt2 [expr {$inuse_pgcnt+$free_pgcnt2+$av_pgcnt}]
|
||||
# Account for the lockbyte page
|
||||
if {$file_pgcnt2*$pageSize>1073742335} {incr file_pgcnt2}
|
||||
|
||||
set ntable [db eval {SELECT count(*)+1 FROM sqlite_master WHERE type='table'}]
|
||||
set nindex [db eval {SELECT count(*) FROM sqlite_master WHERE type='index'}]
|
||||
set sql {SELECT count(*) FROM sqlite_master WHERE name LIKE 'sqlite_autoindex%'}
|
||||
set ntable [db eval {SELECT count(*)+1 FROM sqlite_schema WHERE type='table'}]
|
||||
set nindex [db eval {SELECT count(*) FROM sqlite_schema WHERE type='index'}]
|
||||
set sql {SELECT count(*) FROM sqlite_schema WHERE name LIKE 'sqlite_autoindex%'}
|
||||
set nautoindex [db eval $sql]
|
||||
set nmanindex [expr {$nindex-$nautoindex}]
|
||||
|
||||
# set total_payload [mem eval "SELECT sum(payload) FROM space_used"]
|
||||
set user_payload [mem one {SELECT int(sum(payload)) FROM space_used
|
||||
WHERE NOT is_index AND name NOT LIKE 'sqlite_master'}]
|
||||
WHERE NOT is_index AND name NOT LIKE 'sqlite_schema'}]
|
||||
set user_percent [percent $user_payload $file_bytes]
|
||||
|
||||
# Output the summary statistics calculated above.
|
||||
|
@@ -79,6 +79,10 @@ while test "$1" != ""; do
|
||||
;;
|
||||
--legacy)
|
||||
doWal=0
|
||||
CC_OPTS="$CC_OPTS -DSPEEDTEST_OMIT_HASH"
|
||||
;;
|
||||
--verify)
|
||||
SPEEDTEST_OPTS="$SPEEDTEST_OPTS --verify"
|
||||
;;
|
||||
--wal)
|
||||
doWal=1
|
||||
|
@@ -416,7 +416,7 @@ static void dump_table(const char *zTab, FILE *out){
|
||||
const char *zSep; /* Separator string */
|
||||
Str ins; /* Beginning of the INSERT statement */
|
||||
|
||||
pStmt = db_prepare("SELECT sql FROM aux.sqlite_master WHERE name=%Q", zTab);
|
||||
pStmt = db_prepare("SELECT sql FROM aux.sqlite_schema WHERE name=%Q", zTab);
|
||||
if( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
fprintf(out, "%s;\n", sqlite3_column_text(pStmt,0));
|
||||
}
|
||||
@@ -466,7 +466,7 @@ static void dump_table(const char *zTab, FILE *out){
|
||||
sqlite3_finalize(pStmt);
|
||||
strFree(&ins);
|
||||
} /* endif !g.bSchemaOnly */
|
||||
pStmt = db_prepare("SELECT sql FROM aux.sqlite_master"
|
||||
pStmt = db_prepare("SELECT sql FROM aux.sqlite_schema"
|
||||
" WHERE type='index' AND tbl_name=%Q AND sql IS NOT NULL",
|
||||
zTab);
|
||||
while( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
@@ -639,10 +639,10 @@ static void diff_one_table(const char *zTab, FILE *out){
|
||||
|
||||
/* Drop indexes that are missing in the destination */
|
||||
pStmt = db_prepare(
|
||||
"SELECT name FROM main.sqlite_master"
|
||||
"SELECT name FROM main.sqlite_schema"
|
||||
" WHERE type='index' AND tbl_name=%Q"
|
||||
" AND sql IS NOT NULL"
|
||||
" AND sql NOT IN (SELECT sql FROM aux.sqlite_master"
|
||||
" AND sql NOT IN (SELECT sql FROM aux.sqlite_schema"
|
||||
" WHERE type='index' AND tbl_name=%Q"
|
||||
" AND sql IS NOT NULL)",
|
||||
zTab, zTab);
|
||||
@@ -700,10 +700,10 @@ static void diff_one_table(const char *zTab, FILE *out){
|
||||
|
||||
/* Create indexes that are missing in the source */
|
||||
pStmt = db_prepare(
|
||||
"SELECT sql FROM aux.sqlite_master"
|
||||
"SELECT sql FROM aux.sqlite_schema"
|
||||
" WHERE type='index' AND tbl_name=%Q"
|
||||
" AND sql IS NOT NULL"
|
||||
" AND sql NOT IN (SELECT sql FROM main.sqlite_master"
|
||||
" AND sql NOT IN (SELECT sql FROM main.sqlite_schema"
|
||||
" WHERE type='index' AND tbl_name=%Q"
|
||||
" AND sql IS NOT NULL)",
|
||||
zTab, zTab);
|
||||
@@ -728,7 +728,7 @@ end_diff_one_table:
|
||||
*/
|
||||
static void checkSchemasMatch(const char *zTab){
|
||||
sqlite3_stmt *pStmt = db_prepare(
|
||||
"SELECT A.sql=B.sql FROM main.sqlite_master A, aux.sqlite_master B"
|
||||
"SELECT A.sql=B.sql FROM main.sqlite_schema A, aux.sqlite_schema B"
|
||||
" WHERE A.name=%Q AND B.name=%Q", zTab, zTab
|
||||
);
|
||||
if( SQLITE_ROW==sqlite3_step(pStmt) ){
|
||||
@@ -1757,7 +1757,7 @@ const char *gobble_token(const char *zIn, char *zBuf, int nBuf){
|
||||
** module_name(SQL)
|
||||
**
|
||||
** The only argument should be an SQL statement of the type that may appear
|
||||
** in the sqlite_master table. If the statement is a "CREATE VIRTUAL TABLE"
|
||||
** in the sqlite_schema table. If the statement is a "CREATE VIRTUAL TABLE"
|
||||
** statement, then the value returned is the name of the module that it
|
||||
** uses. Otherwise, if the statement is not a CVT, NULL is returned.
|
||||
*/
|
||||
@@ -1816,32 +1816,32 @@ const char *all_tables_sql(){
|
||||
assert( rc==SQLITE_OK );
|
||||
|
||||
return
|
||||
"SELECT name FROM main.sqlite_master\n"
|
||||
"SELECT name FROM main.sqlite_schema\n"
|
||||
" WHERE type='table' AND (\n"
|
||||
" module_name(sql) IS NULL OR \n"
|
||||
" module_name(sql) IN (SELECT module FROM temp.tblmap)\n"
|
||||
" ) AND name NOT IN (\n"
|
||||
" SELECT a.name || b.postfix \n"
|
||||
"FROM main.sqlite_master AS a, temp.tblmap AS b \n"
|
||||
"FROM main.sqlite_schema AS a, temp.tblmap AS b \n"
|
||||
"WHERE module_name(a.sql) = b.module\n"
|
||||
" )\n"
|
||||
"UNION \n"
|
||||
"SELECT name FROM aux.sqlite_master\n"
|
||||
"SELECT name FROM aux.sqlite_schema\n"
|
||||
" WHERE type='table' AND (\n"
|
||||
" module_name(sql) IS NULL OR \n"
|
||||
" module_name(sql) IN (SELECT module FROM temp.tblmap)\n"
|
||||
" ) AND name NOT IN (\n"
|
||||
" SELECT a.name || b.postfix \n"
|
||||
"FROM aux.sqlite_master AS a, temp.tblmap AS b \n"
|
||||
"FROM aux.sqlite_schema AS a, temp.tblmap AS b \n"
|
||||
"WHERE module_name(a.sql) = b.module\n"
|
||||
" )\n"
|
||||
" ORDER BY name";
|
||||
}else{
|
||||
return
|
||||
"SELECT name FROM main.sqlite_master\n"
|
||||
"SELECT name FROM main.sqlite_schema\n"
|
||||
" WHERE type='table' AND sql NOT LIKE 'CREATE VIRTUAL%%'\n"
|
||||
" UNION\n"
|
||||
"SELECT name FROM aux.sqlite_master\n"
|
||||
"SELECT name FROM aux.sqlite_schema\n"
|
||||
" WHERE type='table' AND sql NOT LIKE 'CREATE VIRTUAL%%'\n"
|
||||
" ORDER BY name";
|
||||
}
|
||||
@@ -1955,7 +1955,7 @@ int main(int argc, char **argv){
|
||||
if( rc ){
|
||||
cmdlineError("cannot open database file \"%s\"", zDb1);
|
||||
}
|
||||
rc = sqlite3_exec(g.db, "SELECT * FROM sqlite_master", 0, 0, &zErrMsg);
|
||||
rc = sqlite3_exec(g.db, "SELECT * FROM sqlite_schema", 0, 0, &zErrMsg);
|
||||
if( rc || zErrMsg ){
|
||||
cmdlineError("\"%s\" does not appear to be a valid SQLite database", zDb1);
|
||||
}
|
||||
@@ -1974,7 +1974,7 @@ int main(int argc, char **argv){
|
||||
if( rc || zErrMsg ){
|
||||
cmdlineError("cannot attach database \"%s\"", zDb2);
|
||||
}
|
||||
rc = sqlite3_exec(g.db, "SELECT * FROM aux.sqlite_master", 0, 0, &zErrMsg);
|
||||
rc = sqlite3_exec(g.db, "SELECT * FROM aux.sqlite_schema", 0, 0, &zErrMsg);
|
||||
if( rc || zErrMsg ){
|
||||
cmdlineError("\"%s\" does not appear to be a valid SQLite database", zDb2);
|
||||
}
|
||||
|
Reference in New Issue
Block a user