Fossil SCM

Update the built-in SQLite to fix a potential (unreleased) corruption bug.

drh 2016-12-26 14:00 trunk
Commit 88d581dc5e1d94683d57d1b3657a983af2eebebe
3 files changed +30 -60 +2 -2 +1 -1
+30 -60
--- src/shell.c
+++ src/shell.c
@@ -4088,56 +4088,10 @@
40884088
sqlite3_free(sCtx.z);
40894089
sqlite3_finalize(pStmt);
40904090
if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
40914091
}else
40924092
4093
- if( c=='i' && (strncmp(azArg[0], "indices", n)==0
4094
- || strncmp(azArg[0], "indexes", n)==0) ){
4095
- ShellState data;
4096
- char *zErrMsg = 0;
4097
- open_db(p, 0);
4098
- memcpy(&data, p, sizeof(data));
4099
- data.showHeader = 0;
4100
- data.cMode = data.mode = MODE_List;
4101
- if( nArg==1 ){
4102
- rc = sqlite3_exec(p->db,
4103
- "SELECT name FROM sqlite_master "
4104
- "WHERE type='index' AND name NOT LIKE 'sqlite_%' "
4105
- "UNION ALL "
4106
- "SELECT name FROM sqlite_temp_master "
4107
- "WHERE type='index' "
4108
- "ORDER BY 1",
4109
- callback, &data, &zErrMsg
4110
- );
4111
- }else if( nArg==2 ){
4112
- zShellStatic = azArg[1];
4113
- rc = sqlite3_exec(p->db,
4114
- "SELECT name FROM sqlite_master "
4115
- "WHERE type='index' AND tbl_name LIKE shellstatic() "
4116
- "UNION ALL "
4117
- "SELECT name FROM sqlite_temp_master "
4118
- "WHERE type='index' AND tbl_name LIKE shellstatic() "
4119
- "ORDER BY 1",
4120
- callback, &data, &zErrMsg
4121
- );
4122
- zShellStatic = 0;
4123
- }else{
4124
- raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n");
4125
- rc = 1;
4126
- goto meta_command_exit;
4127
- }
4128
- if( zErrMsg ){
4129
- utf8_printf(stderr,"Error: %s\n", zErrMsg);
4130
- sqlite3_free(zErrMsg);
4131
- rc = 1;
4132
- }else if( rc != SQLITE_OK ){
4133
- raw_printf(stderr,
4134
- "Error: querying sqlite_master and sqlite_temp_master\n");
4135
- rc = 1;
4136
- }
4137
- }else
4138
-
41394093
#ifndef SQLITE_UNTESTABLE
41404094
if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
41414095
char *zSql;
41424096
char *zCollist = 0;
41434097
sqlite3_stmt *pStmt;
@@ -4957,11 +4911,14 @@
49574911
raw_printf(stderr, "Usage: .stats ?on|off?\n");
49584912
rc = 1;
49594913
}
49604914
}else
49614915
4962
- if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 ){
4916
+ if( (c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0)
4917
+ || (c=='i' && (strncmp(azArg[0], "indices", n)==0
4918
+ || strncmp(azArg[0], "indexes", n)==0) )
4919
+ ){
49634920
sqlite3_stmt *pStmt;
49644921
char **azResult;
49654922
int nRow, nAlloc;
49664923
char *zSql = 0;
49674924
int ii;
@@ -4970,32 +4927,45 @@
49704927
if( rc ) return shellDatabaseError(p->db);
49714928
49724929
/* Create an SQL statement to query for the list of tables in the
49734930
** main and all attached databases where the table name matches the
49744931
** LIKE pattern bound to variable "?1". */
4975
- zSql = sqlite3_mprintf(
4976
- "SELECT name FROM sqlite_master"
4977
- " WHERE type IN ('table','view')"
4978
- " AND name NOT LIKE 'sqlite_%%'"
4979
- " AND name LIKE ?1");
4932
+ if( c=='t' ){
4933
+ zSql = sqlite3_mprintf(
4934
+ "SELECT name FROM sqlite_master"
4935
+ " WHERE type IN ('table','view')"
4936
+ " AND name NOT LIKE 'sqlite_%%'"
4937
+ " AND name LIKE ?1");
4938
+ }else if( nArg>2 ){
4939
+ /* It is an historical accident that the .indexes command shows an error
4940
+ ** when called with the wrong number of arguments whereas the .tables
4941
+ ** command does not. */
4942
+ raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n");
4943
+ rc = 1;
4944
+ goto meta_command_exit;
4945
+ }else{
4946
+ zSql = sqlite3_mprintf(
4947
+ "SELECT name FROM sqlite_master"
4948
+ " WHERE type='index'"
4949
+ " AND tbl_name LIKE ?1");
4950
+ }
49804951
for(ii=0; zSql && sqlite3_step(pStmt)==SQLITE_ROW; ii++){
49814952
const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
49824953
if( zDbName==0 || ii==0 ) continue;
4983
- if( strcmp(zDbName,"temp")==0 ){
4984
- zSql = sqlite3_mprintf(
4985
- "%z UNION ALL "
4986
- "SELECT 'temp.' || name FROM sqlite_temp_master"
4987
- " WHERE type IN ('table','view')"
4988
- " AND name NOT LIKE 'sqlite_%%'"
4989
- " AND name LIKE ?1", zSql);
4990
- }else{
4954
+ if( c=='t' ){
49914955
zSql = sqlite3_mprintf(
49924956
"%z UNION ALL "
49934957
"SELECT '%q.' || name FROM \"%w\".sqlite_master"
49944958
" WHERE type IN ('table','view')"
49954959
" AND name NOT LIKE 'sqlite_%%'"
49964960
" AND name LIKE ?1", zSql, zDbName, zDbName);
4961
+ }else{
4962
+ zSql = sqlite3_mprintf(
4963
+ "%z UNION ALL "
4964
+ "SELECT '%q.' || name FROM \"%w\".sqlite_master"
4965
+ " WHERE type='index'"
4966
+ " AND tbl_name LIKE ?1", zSql, zDbName, zDbName);
49974967
}
49984968
}
49994969
rc = sqlite3_finalize(pStmt);
50004970
if( zSql && rc==SQLITE_OK ){
50014971
zSql = sqlite3_mprintf("%z ORDER BY 1", zSql);
50024972
--- src/shell.c
+++ src/shell.c
@@ -4088,56 +4088,10 @@
4088 sqlite3_free(sCtx.z);
4089 sqlite3_finalize(pStmt);
4090 if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
4091 }else
4092
4093 if( c=='i' && (strncmp(azArg[0], "indices", n)==0
4094 || strncmp(azArg[0], "indexes", n)==0) ){
4095 ShellState data;
4096 char *zErrMsg = 0;
4097 open_db(p, 0);
4098 memcpy(&data, p, sizeof(data));
4099 data.showHeader = 0;
4100 data.cMode = data.mode = MODE_List;
4101 if( nArg==1 ){
4102 rc = sqlite3_exec(p->db,
4103 "SELECT name FROM sqlite_master "
4104 "WHERE type='index' AND name NOT LIKE 'sqlite_%' "
4105 "UNION ALL "
4106 "SELECT name FROM sqlite_temp_master "
4107 "WHERE type='index' "
4108 "ORDER BY 1",
4109 callback, &data, &zErrMsg
4110 );
4111 }else if( nArg==2 ){
4112 zShellStatic = azArg[1];
4113 rc = sqlite3_exec(p->db,
4114 "SELECT name FROM sqlite_master "
4115 "WHERE type='index' AND tbl_name LIKE shellstatic() "
4116 "UNION ALL "
4117 "SELECT name FROM sqlite_temp_master "
4118 "WHERE type='index' AND tbl_name LIKE shellstatic() "
4119 "ORDER BY 1",
4120 callback, &data, &zErrMsg
4121 );
4122 zShellStatic = 0;
4123 }else{
4124 raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n");
4125 rc = 1;
4126 goto meta_command_exit;
4127 }
4128 if( zErrMsg ){
4129 utf8_printf(stderr,"Error: %s\n", zErrMsg);
4130 sqlite3_free(zErrMsg);
4131 rc = 1;
4132 }else if( rc != SQLITE_OK ){
4133 raw_printf(stderr,
4134 "Error: querying sqlite_master and sqlite_temp_master\n");
4135 rc = 1;
4136 }
4137 }else
4138
4139 #ifndef SQLITE_UNTESTABLE
4140 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
4141 char *zSql;
4142 char *zCollist = 0;
4143 sqlite3_stmt *pStmt;
@@ -4957,11 +4911,14 @@
4957 raw_printf(stderr, "Usage: .stats ?on|off?\n");
4958 rc = 1;
4959 }
4960 }else
4961
4962 if( c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0 ){
 
 
 
4963 sqlite3_stmt *pStmt;
4964 char **azResult;
4965 int nRow, nAlloc;
4966 char *zSql = 0;
4967 int ii;
@@ -4970,32 +4927,45 @@
4970 if( rc ) return shellDatabaseError(p->db);
4971
4972 /* Create an SQL statement to query for the list of tables in the
4973 ** main and all attached databases where the table name matches the
4974 ** LIKE pattern bound to variable "?1". */
4975 zSql = sqlite3_mprintf(
4976 "SELECT name FROM sqlite_master"
4977 " WHERE type IN ('table','view')"
4978 " AND name NOT LIKE 'sqlite_%%'"
4979 " AND name LIKE ?1");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4980 for(ii=0; zSql && sqlite3_step(pStmt)==SQLITE_ROW; ii++){
4981 const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
4982 if( zDbName==0 || ii==0 ) continue;
4983 if( strcmp(zDbName,"temp")==0 ){
4984 zSql = sqlite3_mprintf(
4985 "%z UNION ALL "
4986 "SELECT 'temp.' || name FROM sqlite_temp_master"
4987 " WHERE type IN ('table','view')"
4988 " AND name NOT LIKE 'sqlite_%%'"
4989 " AND name LIKE ?1", zSql);
4990 }else{
4991 zSql = sqlite3_mprintf(
4992 "%z UNION ALL "
4993 "SELECT '%q.' || name FROM \"%w\".sqlite_master"
4994 " WHERE type IN ('table','view')"
4995 " AND name NOT LIKE 'sqlite_%%'"
4996 " AND name LIKE ?1", zSql, zDbName, zDbName);
 
 
 
 
 
 
4997 }
4998 }
4999 rc = sqlite3_finalize(pStmt);
5000 if( zSql && rc==SQLITE_OK ){
5001 zSql = sqlite3_mprintf("%z ORDER BY 1", zSql);
5002
--- src/shell.c
+++ src/shell.c
@@ -4088,56 +4088,10 @@
4088 sqlite3_free(sCtx.z);
4089 sqlite3_finalize(pStmt);
4090 if( needCommit ) sqlite3_exec(p->db, "COMMIT", 0, 0, 0);
4091 }else
4092
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4093 #ifndef SQLITE_UNTESTABLE
4094 if( c=='i' && strncmp(azArg[0], "imposter", n)==0 ){
4095 char *zSql;
4096 char *zCollist = 0;
4097 sqlite3_stmt *pStmt;
@@ -4957,11 +4911,14 @@
4911 raw_printf(stderr, "Usage: .stats ?on|off?\n");
4912 rc = 1;
4913 }
4914 }else
4915
4916 if( (c=='t' && n>1 && strncmp(azArg[0], "tables", n)==0)
4917 || (c=='i' && (strncmp(azArg[0], "indices", n)==0
4918 || strncmp(azArg[0], "indexes", n)==0) )
4919 ){
4920 sqlite3_stmt *pStmt;
4921 char **azResult;
4922 int nRow, nAlloc;
4923 char *zSql = 0;
4924 int ii;
@@ -4970,32 +4927,45 @@
4927 if( rc ) return shellDatabaseError(p->db);
4928
4929 /* Create an SQL statement to query for the list of tables in the
4930 ** main and all attached databases where the table name matches the
4931 ** LIKE pattern bound to variable "?1". */
4932 if( c=='t' ){
4933 zSql = sqlite3_mprintf(
4934 "SELECT name FROM sqlite_master"
4935 " WHERE type IN ('table','view')"
4936 " AND name NOT LIKE 'sqlite_%%'"
4937 " AND name LIKE ?1");
4938 }else if( nArg>2 ){
4939 /* It is an historical accident that the .indexes command shows an error
4940 ** when called with the wrong number of arguments whereas the .tables
4941 ** command does not. */
4942 raw_printf(stderr, "Usage: .indexes ?LIKE-PATTERN?\n");
4943 rc = 1;
4944 goto meta_command_exit;
4945 }else{
4946 zSql = sqlite3_mprintf(
4947 "SELECT name FROM sqlite_master"
4948 " WHERE type='index'"
4949 " AND tbl_name LIKE ?1");
4950 }
4951 for(ii=0; zSql && sqlite3_step(pStmt)==SQLITE_ROW; ii++){
4952 const char *zDbName = (const char*)sqlite3_column_text(pStmt, 1);
4953 if( zDbName==0 || ii==0 ) continue;
4954 if( c=='t' ){
 
 
 
 
 
 
 
4955 zSql = sqlite3_mprintf(
4956 "%z UNION ALL "
4957 "SELECT '%q.' || name FROM \"%w\".sqlite_master"
4958 " WHERE type IN ('table','view')"
4959 " AND name NOT LIKE 'sqlite_%%'"
4960 " AND name LIKE ?1", zSql, zDbName, zDbName);
4961 }else{
4962 zSql = sqlite3_mprintf(
4963 "%z UNION ALL "
4964 "SELECT '%q.' || name FROM \"%w\".sqlite_master"
4965 " WHERE type='index'"
4966 " AND tbl_name LIKE ?1", zSql, zDbName, zDbName);
4967 }
4968 }
4969 rc = sqlite3_finalize(pStmt);
4970 if( zSql && rc==SQLITE_OK ){
4971 zSql = sqlite3_mprintf("%z ORDER BY 1", zSql);
4972
+2 -2
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -381,11 +381,11 @@
381381
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382382
** [sqlite_version()] and [sqlite_source_id()].
383383
*/
384384
#define SQLITE_VERSION "3.16.0"
385385
#define SQLITE_VERSION_NUMBER 3016000
386
-#define SQLITE_SOURCE_ID "2016-12-24 19:37:16 2f481b854f04bec546eb172d1b6dbc88067d3fda"
386
+#define SQLITE_SOURCE_ID "2016-12-26 12:25:19 edc9db41f3ee200ba44579a46ed8331bbbbf539e"
387387
388388
/*
389389
** CAPI3REF: Run-Time Library Version Numbers
390390
** KEYWORDS: sqlite3_version sqlite3_sourceid
391391
**
@@ -65801,11 +65801,11 @@
6580165801
goto balance_cleanup;
6580265802
}
6580365803
nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
6580465804
if( (i--)==0 ) break;
6580565805
65806
- if( pParent->nOverflow && ALWAYS(i+nxDiv==pParent->aiOvfl[0]) ){
65806
+ if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
6580765807
apDiv[i] = pParent->apOvfl[0];
6580865808
pgno = get4byte(apDiv[i]);
6580965809
szNew[i] = pParent->xCellSize(pParent, apDiv[i]);
6581065810
pParent->nOverflow = 0;
6581165811
}else{
6581265812
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -381,11 +381,11 @@
381 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382 ** [sqlite_version()] and [sqlite_source_id()].
383 */
384 #define SQLITE_VERSION "3.16.0"
385 #define SQLITE_VERSION_NUMBER 3016000
386 #define SQLITE_SOURCE_ID "2016-12-24 19:37:16 2f481b854f04bec546eb172d1b6dbc88067d3fda"
387
388 /*
389 ** CAPI3REF: Run-Time Library Version Numbers
390 ** KEYWORDS: sqlite3_version sqlite3_sourceid
391 **
@@ -65801,11 +65801,11 @@
65801 goto balance_cleanup;
65802 }
65803 nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
65804 if( (i--)==0 ) break;
65805
65806 if( pParent->nOverflow && ALWAYS(i+nxDiv==pParent->aiOvfl[0]) ){
65807 apDiv[i] = pParent->apOvfl[0];
65808 pgno = get4byte(apDiv[i]);
65809 szNew[i] = pParent->xCellSize(pParent, apDiv[i]);
65810 pParent->nOverflow = 0;
65811 }else{
65812
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -381,11 +381,11 @@
381 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
382 ** [sqlite_version()] and [sqlite_source_id()].
383 */
384 #define SQLITE_VERSION "3.16.0"
385 #define SQLITE_VERSION_NUMBER 3016000
386 #define SQLITE_SOURCE_ID "2016-12-26 12:25:19 edc9db41f3ee200ba44579a46ed8331bbbbf539e"
387
388 /*
389 ** CAPI3REF: Run-Time Library Version Numbers
390 ** KEYWORDS: sqlite3_version sqlite3_sourceid
391 **
@@ -65801,11 +65801,11 @@
65801 goto balance_cleanup;
65802 }
65803 nMaxCells += 1+apOld[i]->nCell+apOld[i]->nOverflow;
65804 if( (i--)==0 ) break;
65805
65806 if( pParent->nOverflow && i+nxDiv==pParent->aiOvfl[0] ){
65807 apDiv[i] = pParent->apOvfl[0];
65808 pgno = get4byte(apDiv[i]);
65809 szNew[i] = pParent->xCellSize(pParent, apDiv[i]);
65810 pParent->nOverflow = 0;
65811 }else{
65812
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,11 +121,11 @@
121121
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122122
** [sqlite_version()] and [sqlite_source_id()].
123123
*/
124124
#define SQLITE_VERSION "3.16.0"
125125
#define SQLITE_VERSION_NUMBER 3016000
126
-#define SQLITE_SOURCE_ID "2016-12-24 19:37:16 2f481b854f04bec546eb172d1b6dbc88067d3fda"
126
+#define SQLITE_SOURCE_ID "2016-12-26 12:25:19 edc9db41f3ee200ba44579a46ed8331bbbbf539e"
127127
128128
/*
129129
** CAPI3REF: Run-Time Library Version Numbers
130130
** KEYWORDS: sqlite3_version sqlite3_sourceid
131131
**
132132
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,11 +121,11 @@
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.16.0"
125 #define SQLITE_VERSION_NUMBER 3016000
126 #define SQLITE_SOURCE_ID "2016-12-24 19:37:16 2f481b854f04bec546eb172d1b6dbc88067d3fda"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
132
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -121,11 +121,11 @@
121 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
122 ** [sqlite_version()] and [sqlite_source_id()].
123 */
124 #define SQLITE_VERSION "3.16.0"
125 #define SQLITE_VERSION_NUMBER 3016000
126 #define SQLITE_SOURCE_ID "2016-12-26 12:25:19 edc9db41f3ee200ba44579a46ed8331bbbbf539e"
127
128 /*
129 ** CAPI3REF: Run-Time Library Version Numbers
130 ** KEYWORDS: sqlite3_version sqlite3_sourceid
131 **
132

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button