From: larrybr Date: Fri, 9 Jun 2023 06:04:32 +0000 (+0000) Subject: More .parameter improvements, a WIP for ".parameter set ..." X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ccf446a5696e40babc30c7720db9383c05fdc02e;p=thirdparty%2Fsqlite.git More .parameter improvements, a WIP for ".parameter set ..." FossilOrigin-Name: 2b51dcdad8fdace33daefdf8ad00fc2f3ab069d5832a1ecf2ac95f580556685d --- diff --git a/manifest b/manifest index d8b7c4768f..9da2c36031 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Sync\sw/trunk.\sFix\sspelling\snits.\sAdd\s".parameter\sedit\s..."\simprovements. -D 2023-06-09T01:11:02.227 +C More\s.parameter\simprovements,\sa\sWIP\sfor\s".parameter\sset\s\s..." +D 2023-06-09T06:04:32.582 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -643,7 +643,7 @@ F src/resmanage.h eb801fdd1d49ed6c44bb103d6e077a2835d7592cf0c20af6b2f0d8eaeb42b3 F src/resolve.c c1457b920aeb33ed106bf478fad31b7473a8950a755ea898980c428928f3a514 F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97 F src/select.c 1ddfe4450101c3d4890ecb2d6b97ab80b78764d5a3e7022b171721df1620c419 -F src/shell.c.in 9e8c6f1e9544344c6b044b7fa9e8de833522069734f38829d9866619ea7ab0fe +F src/shell.c.in 31eaceccba858c6660cb7a6f1bba6839ac1530434b1552ff127da16f32cb6da5 F src/shext_linkage.h 4a686427844d5d2b71f2095cb032280fb262490795f0710487ebbedb3732f1cb F src/sqlite.h.in 3076d78836b6dac53b3ab0875fc8fd15bca8077aad4d33c85336e05af6aef8c7 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -2051,8 +2051,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 4fd4240f14a696a26bce637eaa94121f64edff0894f8c1f341c2f426a74c8fe0 106ec745766ac59131f975d5ab5487c8a24b9c3be1766411c018b42c6ae4672a -R db0bc4d326eca68487db473f548f06c5 +P d73f065b939eaf7f468c43efe21d66dd20109d8b0ffc8b7ffa4bd491072a50dc +R e4aca1b14e2956bf46044ec12581c3c6 U larrybr -Z 0cf690be5324a34450598790618def66 +Z 94503d1135e22616d7387ca3011166ce # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index 92c831c94f..4d244e8869 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d73f065b939eaf7f468c43efe21d66dd20109d8b0ffc8b7ffa4bd491072a50dc \ No newline at end of file +2b51dcdad8fdace33daefdf8ad00fc2f3ab069d5832a1ecf2ac95f580556685d \ No newline at end of file diff --git a/src/shell.c.in b/src/shell.c.in index d6bdd14b05..e18e952bed 100644 --- a/src/shell.c.in +++ b/src/shell.c.in @@ -4525,7 +4525,7 @@ static int ensure_shvars_table(sqlite3 *dbs){ ** ** If noteUses is non-zero, binding attempts and success are recorded in the ** sqlite_parameters table with uses = PTU_Binding. Failed attempts get value -** 0 and successful findings get value 1. +** 0 and successful bindings get value 1. */ static void bind_prepared_stmt(sqlite3 *db, sqlite3_stmt *pStmt, u8 noteUses){ int nVar = sqlite3_bind_parameter_count(pStmt); @@ -11728,7 +11728,6 @@ static int kv_find_callback(void *pData, int nc, char **pV, char **pC){ assert(nc>=1); assert(cli_strcmp(pC[0],"value")==0); struct keyval_row *pParam = (struct keyval_row *)pData; - assert(pParam->value==0); /* key values are supposedly unique. */ if( pParam->value!=0 ) sqlite3_free( pParam->value ); pParam->value = smprintf("%s", pV[0]); /* source owned by statement */ if( nc>1 ) pParam->uses = (int)integerValue(pV[1]); @@ -11958,6 +11957,7 @@ static int edit_one_kvalue(sqlite3 *db, char *name, int eval, const char *zTab = 0; char * zSql = 0; const char *zFmt; + char * zEntrySql = 0; sstr_ptr_holder(&zVal); /* +1 */ switch( uses ){ @@ -11965,25 +11965,31 @@ static int edit_one_kvalue(sqlite3 *db, char *name, int eval, case PTU_Binding: zTab = PARAM_TABLE_SNAME; break; default: assert(0); } - zSql = smprintf("SELECT value, uses FROM %s " - "WHERE key=%Q AND uses=%d", zTab, name, uses); + if( eval ){ + zSql = smprintf("SELECT value, uses FROM %s WHERE key=%Q" + " AND uses IN (%d, "SPTU_Entry") ORDER BY uses", + zTab, name, uses); + }else{ + zSql = smprintf("SELECT value, uses FROM %s " + "WHERE key=%Q AND uses=%d", zTab, name, uses); + } shell_check_ooms(zSql); sstr_ptr_holder(&kvRow.value); /* +2 */ sstr_holder(zSql); /* +3 */ s3_exec_noom(db, zSql, kv_find_callback, &kvRow, 0); release_holder(); /* zSql =2 */ - assert(kvRow.hits<2); - if( kvRow.hits==1 && kvRow.uses==uses){ + assert(kvRow.hits<3); + if( kvRow.hits>=1 ){ /* Editing an existing value of same kind. */ - release_holder(); /* kvRow.value =1 */ - zSql = smprintf("SELECT edit('-- %s\n'||value, %Q) FROM %s " - "WHERE key=%Q AND uses=%d", name, zEd, zTab, name, uses); + zVal = kvRow.value; + drop_holder(); /* kvRow.value =1 */ + zSql = smprintf("SELECT edit('-- %s\n'||%Q, %Q)", name, zVal, zEd); shell_check_ooms(zSql); sstr_holder(zSql); zVal = db_text(db, zSql, 0); release_holder(); /* zSql =1 */ remove_name_tag(&zVal, name); - zFmt = (!eval)? "UPDATE %s SET value=%Q) WHERE key=%Q AND uses=%d" + zFmt = (!eval)? "UPDATE %s SET value=%Q WHERE key=%Q AND uses=%d" : "UPDATE %s SET value=(SELECT %s) WHERE key=%Q AND uses=%d"; zSql = smprintf(zFmt, zTab, zVal, name, uses); }else{ @@ -12002,6 +12008,17 @@ static int edit_one_kvalue(sqlite3 *db, char *name, int eval, } shell_check_ooms(zSql); sstr_holder(zSql); /* +2 */ + if( eval ){ + zEntrySql = smprintf("INSERT OR REPLACE INTO %s(key,value,uses)" + " VALUES(%Q,%Q,"SPTU_Entry")", zTab, name,zVal); + }else{ + zEntrySql = smprintf("DELETE FROM %s WHERE key=%Q AND uses="SPTU_Entry, + zTab, name); + } + if( zEntrySql ){ + sqlite3_exec(db, zEntrySql, 0, 0, 0); + sqlite3_free(zEntrySql); + } rc = sqlite3_exec(db, zSql, 0, 0, 0); if( rc!=SQLITE_OK && pzErr!=0 ){ if( eval ){ @@ -12033,15 +12050,18 @@ static struct ParamSetOpts { const char cCast; const char *zTypename; int evalKind; + const char *zRegEx; /* if 0, anything goes */ } param_set_opts[] = { - /* { 'q', 0, 2 }, */ - /* { 'x', 0, 1 }, */ - { 'i', "INT", 1 }, - { 'r', "REAL", 1 }, - { 'b', "BLOB", 1 }, - { 't', "TEXT", 0 }, - { 'n', "NUMERIC", 1 } +#define INT_RE "(\\d+)|(0[xX][0-9a-fA-F]+)" +#define REAL_RE "(\\d+(\\.\\d+)?([eE][-+]?\\d{1,4})?)|(\\.\\d+)" + { 'i', "INT", 1, "^[-+]?" INT_RE "$" }, + { 'r', "REAL", 1, "^[-+]?" REAL_RE"$" }, + { 'b', "BLOB", 1, "^(0[xX][0-9a-fA-F]+)|([xX]'([0-9a-fA-F][0-9a-fA-F])+')$" }, + { 't', "TEXT", 0, 0 }, + { 'n', "NUMERIC", 1, "^[-+]?(" INT_RE ")|(" REAL_RE ")$" } }; +#undef INT_RE +#undef REAL_RE /* Return an option character if it is single and prefixed by - or --, * else return 0. @@ -12280,7 +12300,7 @@ COLLECT_HELP_TEXT[ #ifndef SQLITE_NOHAVE_SYSTEM " edit ?OPT? ?NAME? ... Use edit() to create or alter parameter(s)", " OPT may be -t to use edited value(s) as text or -e to evaluate it,", - " or -r or -m to edit referenced or missing parameters from last query.", + " or -m or -r to edit missing or referenced parameters from last query.", #endif " init Initialize TEMP table for bindings and scripts", " list ?PATTERNS? List current DB parameters table binding values", @@ -12289,10 +12309,11 @@ COLLECT_HELP_TEXT[ " If FILE missing, empty or '~', it defaults to ~/sqlite_params.sdb", " save ?FILE? ?NAMES? Save some or all named parameters into FILE", " If FILE missing, empty or '~', it defaults to ~/sqlite_params.sdb", - " set ?TOPT? NAME VALUE Give SQL parameter NAME a value of VALUE", + " set ?OPT? NAME VALUE Give SQL parameter NAME a value of VALUE", " NAME must begin with one of $,:,@,? for bindings, VALUE is the space-", - " joined argument list. TOPT may be one of {-b -i -n -r -t} to cast the", - " effective value to BLOB, INT, NUMERIC, REAL or TEXT respectively.", + " joined argument list. OPT may be one of {-b -i -n -r -t} to cast the", + " effective value to BLOB, INT, NUMERIC, REAL or TEXT respectively,", + " and -e may be used to evaluate VALUE as a SQL expression.", " unset ?NAMES? Remove named parameter(s) from parameters table", ]; DISPATCHABLE_COMMAND( parameter 2 2 0 ){