1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Back out the --memory option to ".parameter init" in the CLI, as the

capability is no longer needed for testing due to the new "$int_N" and
"$text_T" automatic bindings, and the "init --memory" is hence just
added complication.

FossilOrigin-Name: 3b1b0c141993eb0f8749f54ea40d6014f9bdccbe0fdb3ccccad971a0baea8d3c
This commit is contained in:
drh
2024-08-08 12:14:07 +00:00
parent 6e7a0c2d86
commit 35c6f58dce
3 changed files with 74 additions and 128 deletions

View File

@ -1,5 +1,5 @@
C In\sthe\sCLI,\srecognize\smagic\sparameter\snames\s"$int_NNN"\sand\s"$text_TTT"\sand\nbind\sthem\swith\sinteger\svalue\sNNN\sand\stext\svalue\sTTT\srespectively.\s\sIntended\nfor\stesting\sand\sdebugging\suse\sonly.
D 2024-08-08T12:08:36.854
C Back\sout\sthe\s--memory\soption\sto\s".parameter\sinit"\sin\sthe\sCLI,\sas\sthe\ncapability\sis\sno\slonger\sneeded\sfor\stesting\sdue\sto\sthe\snew\s"$int_N"\sand\n"$text_T"\sautomatic\sbindings,\sand\sthe\s"init\s--memory"\sis\shence\sjust\nadded\scomplication.
D 2024-08-08T12:14:07.897
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -760,7 +760,7 @@ F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c 7e8d23ce7cdbfedf351a47e759f2722e8182ca10fd7580be43f4ce1f1a228145
F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
F src/select.c 6a95a2bffa6c09584dea99db5a7ae10c813305c09c92920ffc54f6eae2ba399e
F src/shell.c.in 1dfa62d27d77aa8c436d0dfc62920e2e2a2294548ffd078aee0f87b7ab95cc28
F src/shell.c.in 94571558b0fb28c37a5cf6dbd6ea27285341023a28a8cb5795cd2768fab67704
F src/sqlite.h.in 1ad9110150773c38ebababbad11b5cb361bcd3997676dec1c91ac5e0416a7b86
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h 3f046c04ea3595d6bfda99b781926b17e672fd6d27da2ba6d8d8fc39981dcb54
@ -2203,8 +2203,9 @@ F vsixtest/vsixtest.tcl 6195aba1f12a5e10efc2b8c0009532167be5e301abe5b31385638080
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P daa25fb35fd7bdd482d51214439f38b0b9a7df93f689a2b3d30a113daa9f2a1a
R 659621e574300f0e8637eafa75ce3615
P a929cdb00ff74d77cdf55087d32abf53578f7127b36276f89b64ccbef1d4a9a4
Q -4e69dce2093b75b7db4fbdca4953b664b907be15d991ed352ea1d87c64fbf9d2
R 80ba63bff6bb194482fa92e681f77bdc
U drh
Z 38571f620a01d4193af4068fe3fcd87f
Z 15b4994c5694541199c17b609b4ae0e5
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
a929cdb00ff74d77cdf55087d32abf53578f7127b36276f89b64ccbef1d4a9a4
3b1b0c141993eb0f8749f54ea40d6014f9bdccbe0fdb3ccccad971a0baea8d3c

View File

@ -1356,8 +1356,6 @@ struct ShellState {
#endif
} aAuxDb[5], /* Array of all database connections */
*pAuxDb; /* Currently active database connection */
sqlite3 *dbParam; /* Database to use for query parameters. Often the
** same as "db", but might be different. */
int *aiIndent; /* Array of indents used in MODE_Explain */
int nIndent; /* Size of array aiIndent[] */
int iIndent; /* Index of current op in aiIndent[] */
@ -3482,44 +3480,22 @@ static void restore_debug_trace_modes(void){
sqlite3_test_control(SQLITE_TESTCTRL_TRACEFLAGS, 3, &savedWhereTrace);
}
/* Create the TEMP table used to store parameter bindings.
**
** If bInMemory is true, create a separate in-memory database for
** the parameter binding table.
**
** The database that stores the sqlite_parameter table will be
** p->dbParam. This might be a copy of p->db. Or it might be a
** completely separate database (if bInMemory is true, because of
** the ".param init --memory" command).
*/
static void bind_table_init(ShellState *p, int bInMemory){
/* Create the TEMP table used to store parameter bindings */
static void bind_table_init(ShellState *p){
int wrSchema = 0;
int defensiveMode = 0;
sqlite3 *dbx;
if( p->dbParam ) return;
if( sqlite3_table_column_metadata(p->db, "TEMP", "sqlite_parameters",
"key", 0, 0, 0, 0, 0)==SQLITE_OK ){
return;
}
if( bInMemory && p->dbParam==0 ){
sqlite3_open(":memory:", &p->dbParam);
}else{
p->dbParam = p->db;
}
dbx = p->dbParam;
sqlite3_db_config(dbx, SQLITE_DBCONFIG_DEFENSIVE, -1, &defensiveMode);
sqlite3_db_config(dbx, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
sqlite3_db_config(dbx, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
sqlite3_db_config(dbx, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
sqlite3_exec(dbx,
sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, -1, &defensiveMode);
sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, 0, 0);
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, -1, &wrSchema);
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, 1, 0);
sqlite3_exec(p->db,
"CREATE TABLE IF NOT EXISTS temp.sqlite_parameters(\n"
" key TEXT PRIMARY KEY,\n"
" value\n"
") WITHOUT ROWID;",
0, 0, 0);
sqlite3_db_config(dbx, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
sqlite3_db_config(dbx, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0);
sqlite3_db_config(p->db, SQLITE_DBCONFIG_WRITABLE_SCHEMA, wrSchema, 0);
sqlite3_db_config(p->db, SQLITE_DBCONFIG_DEFENSIVE, defensiveMode, 0);
}
/*
@ -3542,14 +3518,12 @@ static void bind_prepared_stmt(ShellState *pArg, sqlite3_stmt *pStmt){
nVar = sqlite3_bind_parameter_count(pStmt);
if( nVar==0 ) return; /* Nothing to do */
if( pArg->dbParam==0
|| sqlite3_table_column_metadata(pArg->dbParam, "TEMP", "sqlite_parameters",
"key", 0, 0, 0, 0, 0)!=SQLITE_OK
){
if( sqlite3_table_column_metadata(pArg->db, "TEMP", "sqlite_parameters",
"key", 0, 0, 0, 0, 0)!=SQLITE_OK ){
rc = SQLITE_NOTFOUND;
pQ = 0;
}else{
rc = sqlite3_prepare_v2(pArg->dbParam,
rc = sqlite3_prepare_v2(pArg->db,
"SELECT value FROM temp.sqlite_parameters"
" WHERE key=?1", -1, &pQ, 0);
}
@ -4863,7 +4837,7 @@ static const char *(azHelp[]) = {
#endif
".parameter CMD ... Manage SQL parameter bindings",
" clear Erase all bindings",
" init ?--memory? Initialize the TEMP table that holds bindings",
" init Initialize the TEMP table that holds bindings",
" list List the current parameter bindings",
" set PARAMETER VALUE Given SQL parameter PARAMETER a value of VALUE",
" PARAMETER should start with one of: $ : @ ?",
@ -5519,17 +5493,9 @@ static void open_db(ShellState *p, int openFlags){
/*
** Attempt to close the database connection. Report errors.
**
** If dbParam is not NULL and is different from db, then close it
** too. No error checking is done on the close of dbParam, as it
** should be a :memory: database which cannot really fail on close.
*/
void close_db(sqlite3 *db, sqlite3 *dbParam){
int rc;
if( dbParam && dbParam!=db ){
sqlite3_close(dbParam);
}
rc = sqlite3_close(db);
void close_db(sqlite3 *db){
int rc = sqlite3_close(db);
if( rc ){
eputf("Error: sqlite3_close() returns %d: %s\n", rc, sqlite3_errmsg(db));
}
@ -6188,7 +6154,7 @@ static void tryToClone(ShellState *p, const char *zNewDb){
sqlite3_exec(newDb, "COMMIT;", 0, 0, 0);
sqlite3_exec(p->db, "PRAGMA writable_schema=OFF;", 0, 0, 0);
}
close_db(newDb, 0);
close_db(newDb);
}
#ifndef SQLITE_SHELL_FIDDLE
@ -7623,7 +7589,7 @@ static int arDotCommand(
}
end_ar_command:
if( cmd.db!=pState->db ){
close_db(cmd.db, 0);
close_db(cmd.db);
}
sqlite3_free(cmd.zSrcTable);
@ -8148,7 +8114,7 @@ static int do_meta_command(char *zLine, ShellState *p){
SQLITE_OPEN_READWRITE|SQLITE_OPEN_CREATE, zVfs);
if( rc!=SQLITE_OK ){
eputf("Error: cannot open \"%s\"\n", zDestFile);
close_db(pDest, 0);
close_db(pDest);
return 1;
}
if( bAsync ){
@ -8159,7 +8125,7 @@ static int do_meta_command(char *zLine, ShellState *p){
pBackup = sqlite3_backup_init(pDest, "main", p->db, zDb);
if( pBackup==0 ){
eputf("Error: %s\n", sqlite3_errmsg(pDest));
close_db(pDest, 0);
close_db(pDest);
return 1;
}
while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK ){}
@ -8170,7 +8136,7 @@ static int do_meta_command(char *zLine, ShellState *p){
eputf("Error: %s\n", sqlite3_errmsg(pDest));
rc = 1;
}
close_db(pDest, 0);
close_db(pDest);
}else
#endif /* !defined(SQLITE_SHELL_FIDDLE) */
@ -8310,7 +8276,7 @@ static int do_meta_command(char *zLine, ShellState *p){
rc = 1;
}else if( p->aAuxDb[i].db ){
session_close_all(p, i);
close_db(p->aAuxDb[i].db, 0);
close_db(p->aAuxDb[i].db);
p->aAuxDb[i].db = 0;
}
}else{
@ -9600,8 +9566,8 @@ static int do_meta_command(char *zLine, ShellState *p){
/* Close the existing database */
session_close_all(p, -1);
close_db(p->db, p->dbParam);
p->db = p->dbParam = 0;
close_db(p->db);
p->db = 0;
p->pAuxDb->zDbFilename = 0;
sqlite3_free(p->pAuxDb->zFreeOnClose);
p->pAuxDb->zFreeOnClose = 0;
@ -9767,15 +9733,8 @@ static int do_meta_command(char *zLine, ShellState *p){
** Clear all bind parameters by dropping the TEMP table that holds them.
*/
if( nArg==2 && cli_strcmp(azArg[1],"clear")==0 ){
if( p->dbParam==0 ){
/* no-op */
}else if( p->dbParam==p->db ){
sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.sqlite_parameters;",
0, 0, 0);
}else{
sqlite3_close(p->dbParam);
}
p->dbParam = 0;
sqlite3_exec(p->db, "DROP TABLE IF EXISTS temp.sqlite_parameters;",
0, 0, 0);
}else
/* .parameter list
@ -9785,45 +9744,33 @@ static int do_meta_command(char *zLine, ShellState *p){
sqlite3_stmt *pStmt = 0;
int rx;
int len = 0;
if( p->dbParam ){
rx = sqlite3_prepare_v2(p->dbParam,
"SELECT max(length(key)) "
"FROM temp.sqlite_parameters;", -1, &pStmt, 0);
if( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
len = sqlite3_column_int(pStmt, 0);
if( len>40 ) len = 40;
rx = sqlite3_prepare_v2(p->db,
"SELECT max(length(key)) "
"FROM temp.sqlite_parameters;", -1, &pStmt, 0);
if( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
len = sqlite3_column_int(pStmt, 0);
if( len>40 ) len = 40;
}
sqlite3_finalize(pStmt);
pStmt = 0;
if( len ){
rx = sqlite3_prepare_v2(p->db,
"SELECT key, quote(value) "
"FROM temp.sqlite_parameters;", -1, &pStmt, 0);
while( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
oputf("%-*s %s\n", len, sqlite3_column_text(pStmt,0),
sqlite3_column_text(pStmt,1));
}
sqlite3_finalize(pStmt);
pStmt = 0;
if( len ){
rx = sqlite3_prepare_v2(p->db,
"SELECT key, quote(value) "
"FROM temp.sqlite_parameters;", -1, &pStmt, 0);
while( rx==SQLITE_OK && sqlite3_step(pStmt)==SQLITE_ROW ){
oputf("%-*s %s\n", len, sqlite3_column_text(pStmt,0),
sqlite3_column_text(pStmt,1));
}
sqlite3_finalize(pStmt);
}
}
}else
/* .parameter init ?--memory?
/* .parameter init
** Make sure the TEMP table used to hold bind parameters exists.
** Create it if necessary.
**
** If the --memory option is specified, the sqlite_parameters table
** is held in a separate database so that parameter binding queries
** do not show up in debugging output from .treetrace, .wheretrace,
** PRAGMA vdbe_addoptrace=on, and similar.
*/
if( nArg==2 && cli_strcmp(azArg[1],"init")==0 ){
bind_table_init(p, 0);
}else
if( nArg==3 && cli_strcmp(azArg[1],"init")==0
&& cli_strcmp(azArg[2],"--memory")==0
){
bind_table_init(p, 1);
bind_table_init(p);
}else
/* .parameter set NAME VALUE
@ -9838,30 +9785,28 @@ static int do_meta_command(char *zLine, ShellState *p){
sqlite3_stmt *pStmt;
const char *zKey = azArg[2];
const char *zValue = azArg[3];
bind_table_init(p, 0);
if( p->dbParam ){
zSql = sqlite3_mprintf(
"REPLACE INTO temp.sqlite_parameters(key,value)"
"VALUES(%Q,%s);", zKey, zValue);
shell_check_oom(zSql);
bind_table_init(p);
zSql = sqlite3_mprintf(
"REPLACE INTO temp.sqlite_parameters(key,value)"
"VALUES(%Q,%s);", zKey, zValue);
shell_check_oom(zSql);
pStmt = 0;
rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
sqlite3_free(zSql);
if( rx!=SQLITE_OK ){
sqlite3_finalize(pStmt);
pStmt = 0;
rx = sqlite3_prepare_v2(p->dbParam, zSql, -1, &pStmt, 0);
zSql = sqlite3_mprintf(
"REPLACE INTO temp.sqlite_parameters(key,value)"
"VALUES(%Q,%Q);", zKey, zValue);
shell_check_oom(zSql);
rx = sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
sqlite3_free(zSql);
if( rx!=SQLITE_OK ){
oputf("Error: %s\n", sqlite3_errmsg(p->db));
sqlite3_finalize(pStmt);
pStmt = 0;
zSql = sqlite3_mprintf(
"REPLACE INTO temp.sqlite_parameters(key,value)"
"VALUES(%Q,%Q);", zKey, zValue);
shell_check_oom(zSql);
rx = sqlite3_prepare_v2(p->dbParam, zSql, -1, &pStmt, 0);
sqlite3_free(zSql);
if( rx!=SQLITE_OK ){
oputf("Error: %s\n", sqlite3_errmsg(p->db));
sqlite3_finalize(pStmt);
pStmt = 0;
rc = 1;
}
rc = 1;
}
}
sqlite3_step(pStmt);
@ -9876,7 +9821,7 @@ static int do_meta_command(char *zLine, ShellState *p){
char *zSql = sqlite3_mprintf(
"DELETE FROM temp.sqlite_parameters WHERE key=%Q", azArg[2]);
shell_check_oom(zSql);
if( p->dbParam ) sqlite3_exec(p->dbParam, zSql, 0, 0, 0);
sqlite3_exec(p->db, zSql, 0, 0, 0);
sqlite3_free(zSql);
}else
/* If no command name matches, show a syntax error */
@ -10014,14 +9959,14 @@ static int do_meta_command(char *zLine, ShellState *p){
rc = sqlite3_open(zSrcFile, &pSrc);
if( rc!=SQLITE_OK ){
eputf("Error: cannot open \"%s\"\n", zSrcFile);
close_db(pSrc, 0);
close_db(pSrc);
return 1;
}
open_db(p, 0);
pBackup = sqlite3_backup_init(p->db, zDb, pSrc, "main");
if( pBackup==0 ){
eputf("Error: %s\n", sqlite3_errmsg(p->db));
close_db(pSrc, 0);
close_db(pSrc);
return 1;
}
while( (rc = sqlite3_backup_step(pBackup,100))==SQLITE_OK
@ -10041,7 +9986,7 @@ static int do_meta_command(char *zLine, ShellState *p){
eputf("Error: %s\n", sqlite3_errmsg(p->db));
rc = 1;
}
close_db(pSrc, 0);
close_db(pSrc);
}else
#endif /* !defined(SQLITE_SHELL_FIDDLE) */
@ -12908,13 +12853,13 @@ int SQLITE_CDECL wmain(int argc, wchar_t **wargv){
set_table_name(&data, 0);
if( data.db ){
session_close_all(&data, -1);
close_db(data.db, data.dbParam);
close_db(data.db);
}
for(i=0; i<ArraySize(data.aAuxDb); i++){
sqlite3_free(data.aAuxDb[i].zFreeOnClose);
if( data.aAuxDb[i].db ){
session_close_all(&data, i);
close_db(data.aAuxDb[i].db, 0);
close_db(data.aAuxDb[i].db);
}
}
find_home_dir(1);