| | @@ -22123,23 +22123,44 @@ |
| 22123 | 22123 | int rc = sqlite3_finalize(pStmt); |
| 22124 | 22124 | if( rc!=SQLITE_OK && p->errCode==SQLITE_OK ){ |
| 22125 | 22125 | recoverDbError(p, db); |
| 22126 | 22126 | } |
| 22127 | 22127 | } |
| 22128 | + |
| 22129 | +/* |
| 22130 | +** Run a single SQL statement in zSql. If zSql contains two or more |
| 22131 | +** SQL statements separated by ';', only the first is run. |
| 22132 | +** |
| 22133 | +** Return the sqlite3_finalizer() or sqlite3_prepare() result code |
| 22134 | +** from running the zSql statement. |
| 22135 | +*/ |
| 22136 | +static int recoverOneStmt(sqlite3 *db, const char *zSql){ |
| 22137 | + sqlite3_stmt *pStmt = 0; |
| 22138 | + int rc; |
| 22139 | + if( zSql==0 ) return SQLITE_OK; |
| 22140 | + rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); |
| 22141 | + if( rc ){ |
| 22142 | + sqlite3_finalize(pStmt); |
| 22143 | + return rc; |
| 22144 | + } |
| 22145 | + while( SQLITE_ROW==sqlite3_step(pStmt) ){} |
| 22146 | + return sqlite3_finalize(pStmt); |
| 22147 | +} |
| 22128 | 22148 | |
| 22129 | 22149 | /* |
| 22130 | 22150 | ** This function is a no-op if recover handle p already contains an error |
| 22131 | 22151 | ** (if p->errCode!=SQLITE_OK). A copy of p->errCode is returned in this |
| 22132 | 22152 | ** case. |
| 22133 | 22153 | ** |
| 22134 | | -** Otherwise, execute SQL script zSql. If successful, return SQLITE_OK. |
| 22135 | | -** Or, if an error occurs, leave an error code and message in the recover |
| 22136 | | -** handle and return a copy of the error code. |
| 22154 | +** Otherwise, execute a single SQL statment in zSql. Even if zSql contains |
| 22155 | +** two or more SQL statements separated by ';', only execute the first one. |
| 22156 | +** If successful, return SQLITE_OK. Or, if an error occurs, leave an error |
| 22157 | +** code and message in the recover handle and return a copy of the error code. |
| 22137 | 22158 | */ |
| 22138 | 22159 | static int recoverExec(sqlite3_recover *p, sqlite3 *db, const char *zSql){ |
| 22139 | 22160 | if( p->errCode==SQLITE_OK ){ |
| 22140 | | - int rc = sqlite3_exec(db, zSql, 0, 0, 0); |
| 22161 | + int rc = recoverOneStmt(db, zSql); |
| 22141 | 22162 | if( rc ){ |
| 22142 | 22163 | recoverDbError(p, db); |
| 22143 | 22164 | } |
| 22144 | 22165 | } |
| 22145 | 22166 | return p->errCode; |
| | @@ -22535,11 +22556,12 @@ |
| 22535 | 22556 | recoverError(p, SQLITE_NOMEM, 0); |
| 22536 | 22557 | } |
| 22537 | 22558 | } |
| 22538 | 22559 | recoverFinalize(p, p1); |
| 22539 | 22560 | } |
| 22540 | | - recoverExec(p, db2, "CREATE TABLE t1(a); DROP TABLE t1;"); |
| 22561 | + recoverExec(p, db2, "CREATE TABLE t1(a)"); |
| 22562 | + recoverExec(p, db2, "DROP TABLE t1"); |
| 22541 | 22563 | |
| 22542 | 22564 | if( p->errCode==SQLITE_OK ){ |
| 22543 | 22565 | sqlite3 *db = p->dbOut; |
| 22544 | 22566 | sqlite3_backup *pBackup = sqlite3_backup_init(db, "main", db2, "main"); |
| 22545 | 22567 | if( pBackup ){ |
| | @@ -22617,16 +22639,16 @@ |
| 22617 | 22639 | ** discarded. |
| 22618 | 22640 | */ |
| 22619 | 22641 | static void recoverOpenRecovery(sqlite3_recover *p){ |
| 22620 | 22642 | char *zSql = recoverMPrintf(p, "ATTACH %Q AS recovery;", p->zStateDb); |
| 22621 | 22643 | recoverExec(p, p->dbOut, zSql); |
| 22644 | + sqlite3_free(zSql); |
| 22645 | + recoverExec(p, p->dbOut, "PRAGMA writable_schema = 1"); |
| 22646 | + recoverExec(p, p->dbOut, |
| 22647 | + "CREATE TABLE recovery.map(pgno INTEGER PRIMARY KEY, parent INT)"); |
| 22622 | 22648 | recoverExec(p, p->dbOut, |
| 22623 | | - "PRAGMA writable_schema = 1;" |
| 22624 | | - "CREATE TABLE recovery.map(pgno INTEGER PRIMARY KEY, parent INT);" |
| 22625 | | - "CREATE TABLE recovery.schema(type, name, tbl_name, rootpage, sql);" |
| 22626 | | - ); |
| 22627 | | - sqlite3_free(zSql); |
| 22649 | + "CREATE TABLE recovery.schema(type, name, tbl_name, rootpage, sql)"); |
| 22628 | 22650 | } |
| 22629 | 22651 | |
| 22630 | 22652 | |
| 22631 | 22653 | /* |
| 22632 | 22654 | ** This function is a no-op if recover handle p already contains an error |
| | @@ -22762,11 +22784,11 @@ |
| 22762 | 22784 | " (type='index' AND (sql LIKE '%unique%' OR ?1))" |
| 22763 | 22785 | " FROM recovery.schema" |
| 22764 | 22786 | ")" |
| 22765 | 22787 | "SELECT rootpage, tbl, isVirtual, name, sql" |
| 22766 | 22788 | " FROM dbschema " |
| 22767 | | - " WHERE tbl OR isIndex" |
| 22789 | + " WHERE (tbl OR isIndex) AND sql GLOB 'CREATE *'" |
| 22768 | 22790 | " ORDER BY tbl DESC, name=='sqlite_sequence' DESC" |
| 22769 | 22791 | ); |
| 22770 | 22792 | |
| 22771 | 22793 | pTblname = recoverPrepare(p, p->dbOut, |
| 22772 | 22794 | "SELECT name FROM sqlite_schema " |
| | @@ -22788,11 +22810,11 @@ |
| 22788 | 22810 | zSql = (const char*)(zFree = recoverMPrintf(p, |
| 22789 | 22811 | "INSERT INTO sqlite_schema VALUES('table', %Q, %Q, 0, %Q)", |
| 22790 | 22812 | zName, zName, zSql |
| 22791 | 22813 | )); |
| 22792 | 22814 | } |
| 22793 | | - rc = sqlite3_exec(p->dbOut, zSql, 0, 0, 0); |
| 22815 | + rc = recoverOneStmt(p->dbOut, zSql); |
| 22794 | 22816 | if( rc==SQLITE_OK ){ |
| 22795 | 22817 | recoverSqlCallback(p, zSql); |
| 22796 | 22818 | if( bTable && !bVirtual ){ |
| 22797 | 22819 | if( SQLITE_ROW==sqlite3_step(pTblname) ){ |
| 22798 | 22820 | const char *zTbl = (const char*)sqlite3_column_text(pTblname, 0); |
| | @@ -22830,19 +22852,21 @@ |
| 22830 | 22852 | |
| 22831 | 22853 | pSelect = recoverPrepare(p, p->dbOut, |
| 22832 | 22854 | p->bSlowIndexes ? |
| 22833 | 22855 | "SELECT rootpage, sql FROM recovery.schema " |
| 22834 | 22856 | " WHERE type!='table' AND type!='index'" |
| 22857 | + " AND sql GLOB 'CREATE *'" |
| 22835 | 22858 | : |
| 22836 | 22859 | "SELECT rootpage, sql FROM recovery.schema " |
| 22837 | 22860 | " WHERE type!='table' AND (type!='index' OR sql NOT LIKE '%unique%')" |
| 22861 | + " AND sql GLOB 'CREATE *'" |
| 22838 | 22862 | ); |
| 22839 | 22863 | |
| 22840 | 22864 | if( pSelect ){ |
| 22841 | 22865 | while( sqlite3_step(pSelect)==SQLITE_ROW ){ |
| 22842 | 22866 | const char *zSql = (const char*)sqlite3_column_text(pSelect, 1); |
| 22843 | | - int rc = sqlite3_exec(p->dbOut, zSql, 0, 0, 0); |
| 22867 | + int rc = recoverOneStmt(p->dbOut, zSql); |
| 22844 | 22868 | if( rc==SQLITE_OK ){ |
| 22845 | 22869 | recoverSqlCallback(p, zSql); |
| 22846 | 22870 | }else if( rc!=SQLITE_ERROR ){ |
| 22847 | 22871 | recoverDbError(p, p->dbOut); |
| 22848 | 22872 | } |
| | @@ -24216,11 +24240,11 @@ |
| 24216 | 24240 | recoverCacheSchema(p); |
| 24217 | 24241 | |
| 24218 | 24242 | if( bUseWrapper ) recoverUninstallWrapper(p); |
| 24219 | 24243 | }while( p->errCode==SQLITE_NOTADB |
| 24220 | 24244 | && (bUseWrapper--) |
| 24221 | | - && SQLITE_OK==sqlite3_exec(p->dbIn, "ROLLBACK", 0, 0, 0) |
| 24245 | + && SQLITE_OK==recoverOneStmt(p->dbIn, "ROLLBACK") |
| 24222 | 24246 | ); |
| 24223 | 24247 | } |
| 24224 | 24248 | |
| 24225 | 24249 | recoverLeaveMutex(); |
| 24226 | 24250 | recoverExec(p, p->dbOut, "BEGIN"); |
| | @@ -24281,11 +24305,11 @@ |
| 24281 | 24305 | |
| 24282 | 24306 | /* If no error has occurred, commit the write transaction on the output |
| 24283 | 24307 | ** database. Regardless of whether or not an error has occurred, make |
| 24284 | 24308 | ** an attempt to end the read transaction on the input database. */ |
| 24285 | 24309 | recoverExec(p, p->dbOut, "COMMIT"); |
| 24286 | | - rc = sqlite3_exec(p->dbIn, "END", 0, 0, 0); |
| 24310 | + rc = recoverOneStmt(p->dbIn, "END"); |
| 24287 | 24311 | if( p->errCode==SQLITE_OK ) p->errCode = rc; |
| 24288 | 24312 | |
| 24289 | 24313 | recoverSqlCallback(p, "PRAGMA writable_schema = off"); |
| 24290 | 24314 | recoverSqlCallback(p, "COMMIT"); |
| 24291 | 24315 | p->eState = RECOVER_STATE_DONE; |
| | @@ -24477,11 +24501,11 @@ |
| 24477 | 24501 | if( p==0 ){ |
| 24478 | 24502 | rc = SQLITE_NOMEM; |
| 24479 | 24503 | }else{ |
| 24480 | 24504 | recoverFinalCleanup(p); |
| 24481 | 24505 | if( p->bCloseTransaction && sqlite3_get_autocommit(p->dbIn)==0 ){ |
| 24482 | | - rc = sqlite3_exec(p->dbIn, "END", 0, 0, 0); |
| 24506 | + rc = recoverOneStmt(p->dbIn, "END"); |
| 24483 | 24507 | if( p->errCode==SQLITE_OK ) p->errCode = rc; |
| 24484 | 24508 | } |
| 24485 | 24509 | rc = p->errCode; |
| 24486 | 24510 | sqlite3_free(p->zErrMsg); |
| 24487 | 24511 | sqlite3_free(p->zStateDb); |
| | @@ -24564,10 +24588,11 @@ |
| 24564 | 24588 | unsigned statsOn; /* True to display memory stats before each finalize */ |
| 24565 | 24589 | unsigned mEqpLines; /* Mask of vertical lines in the EQP output graph */ |
| 24566 | 24590 | u8 nPopOutput; /* Revert .output settings when reaching zero */ |
| 24567 | 24591 | u8 nPopMode; /* Revert .mode settings when reaching zero */ |
| 24568 | 24592 | u8 enableTimer; /* Enable the timer. 2: permanently 1: only once */ |
| 24593 | + u8 bDelimitNonprint; /* Add \001...\002 around non-printing in prompts */ |
| 24569 | 24594 | int inputNesting; /* Track nesting level of .read and other redirects */ |
| 24570 | 24595 | double prevTimer; /* Last reported timer value */ |
| 24571 | 24596 | double tmProgress; /* --timeout option for .progress */ |
| 24572 | 24597 | i64 lineno; /* Line number of last line read from in */ |
| 24573 | 24598 | const char *zInFile; /* Name of the input file */ |
| | @@ -25107,10 +25132,22 @@ |
| 25107 | 25132 | break; |
| 25108 | 25133 | } |
| 25109 | 25134 | } |
| 25110 | 25135 | return zLine; |
| 25111 | 25136 | } |
| 25137 | + |
| 25138 | +/* |
| 25139 | +** Return true if either the SQLITE_NO_COLOR compile-time option is used |
| 25140 | +** or if the NO_COLOR environment variable exists |
| 25141 | +*/ |
| 25142 | +static int shellNoColor(void){ |
| 25143 | +#ifdef SQLITE_NO_COLOR |
| 25144 | + return 1; |
| 25145 | +#else |
| 25146 | + return getenv("NO_COLOR")!=0; |
| 25147 | +#endif |
| 25148 | +} |
| 25112 | 25149 | |
| 25113 | 25150 | /* |
| 25114 | 25151 | ** The SQLITE_PS_APPDEF macro should be set to the name of a function |
| 25115 | 25152 | ** that accepts a single "int" argument and returns a "const char *" |
| 25116 | 25153 | ** that is guaranteed to be non-NULL. The value returned depends on the |
| | @@ -25133,24 +25170,28 @@ |
| 25133 | 25170 | switch( c ){ |
| 25134 | 25171 | /* The default main prompt string */ |
| 25135 | 25172 | case 1: |
| 25136 | 25173 | #if defined(SQLITE_PS1) |
| 25137 | 25174 | return SQLITE_PS1; |
| 25138 | | -#elif defined(SQLITE_PS_NOANSI) |
| 25139 | | - return "/A-/v /~> "; |
| 25140 | 25175 | #else |
| 25141 | | - return "/e[1;32m/A-/v /e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m-> "; |
| 25176 | + if( shellNoColor() ){ |
| 25177 | + return "/A-/v /~> "; |
| 25178 | + }else{ |
| 25179 | + return "/e[1;32m/A-/v /e[1;/x33/:36/;m/m/e[3m/;/f/;/e[0m-> "; |
| 25180 | + } |
| 25142 | 25181 | #endif |
| 25143 | 25182 | |
| 25144 | 25183 | /* The default continuation prompt string */ |
| 25145 | 25184 | case 2: |
| 25146 | 25185 | #if defined(SQLITE_PS2) |
| 25147 | 25186 | return SQLITE_PS2; |
| 25148 | | -#elif defined(SQLITE_PS_NOANSI) |
| 25149 | | - return "/B/C> "; |
| 25150 | 25187 | #else |
| 25151 | | - return "/B/e[1;/x33/:36/;m/C/e[0m-> "; |
| 25188 | + if( shellNoColor() ){ |
| 25189 | + return "/B/C> "; |
| 25190 | + }else{ |
| 25191 | + return "/B/e[1;/x33/:36/;m/C/e[0m-> "; |
| 25192 | + } |
| 25152 | 25193 | #endif |
| 25153 | 25194 | |
| 25154 | 25195 | /* Name of environment variables that override the prompt strings |
| 25155 | 25196 | ** of cases 1 and 2 */ |
| 25156 | 25197 | case 3: return "SQLITE_PS1"; |
| | @@ -25218,13 +25259,13 @@ |
| 25218 | 25259 | }else if( p->db && (pFN = sqlite3_db_filename(p->db,0))!=0 ){ |
| 25219 | 25260 | zFN = sqlite3_filename_database(pFN); |
| 25220 | 25261 | } |
| 25221 | 25262 | if( zFN==0 || zFN[0]==0 ){ |
| 25222 | 25263 | zFN = p->pAuxDb->zDbFilename; |
| 25223 | | - if( zFN==0 || zFN[0]==0 || cli_strcmp(zFN,":memory:")==0 ){ |
| 25224 | | - zFN = zMemoryName; |
| 25225 | | - } |
| 25264 | + } |
| 25265 | + if( zFN==0 || zFN[0]==0 || cli_strcmp(zFN,":memory:")==0 ){ |
| 25266 | + zFN = zMemoryName; |
| 25226 | 25267 | } |
| 25227 | 25268 | return zFN; |
| 25228 | 25269 | } |
| 25229 | 25270 | |
| 25230 | 25271 | /* |
| | @@ -25263,10 +25304,26 @@ |
| 25263 | 25304 | if( z==0 || z[0]==0 ) z = getenv("LOGNAME"); |
| 25264 | 25305 | if( z==0 || z[0]==0 ) z = "?"; |
| 25265 | 25306 | #endif |
| 25266 | 25307 | return z; |
| 25267 | 25308 | } |
| 25309 | + |
| 25310 | +/* If z[] begins with one or more ANSI X3.64 (VT100) escape sequences |
| 25311 | +** return the number of bytes in all such escape sequences. Return |
| 25312 | +** zero if there are no valid escape sequences. |
| 25313 | +*/ |
| 25314 | +static int nAnsiEscape(const char *z){ |
| 25315 | + int i = 0; |
| 25316 | + while( z[i]=='\033' && z[i+1]=='[' ){ |
| 25317 | + int k = i+2; |
| 25318 | + while( z[k]>=0x30 && z[k]<=0x3f ){ k++; } |
| 25319 | + while( z[k]>=0x20 && z[k]<=0x2f ){ k++; } |
| 25320 | + if( z[k]<0x40 || z[k]>0x7e ) break; |
| 25321 | + i = k+1; |
| 25322 | + } |
| 25323 | + return i; |
| 25324 | +} |
| 25268 | 25325 | |
| 25269 | 25326 | /* |
| 25270 | 25327 | ** Expand escapes in the given input prompt string. Return the |
| 25271 | 25328 | ** expanded prompt in memory obtained from sqlite3_malloc(). The |
| 25272 | 25329 | ** caller is responsible for freeing the memory. |
| | @@ -25311,10 +25368,11 @@ |
| 25311 | 25368 | continue; |
| 25312 | 25369 | } |
| 25313 | 25370 | if( c>='0' && c<='7' ){ |
| 25314 | 25371 | /* /nnn becomes a single byte given by octal nnn */ |
| 25315 | 25372 | int v = c - '0'; |
| 25373 | + i++; |
| 25316 | 25374 | while( i<=2 && zPrompt[i+1]>='0' && zPrompt[i+1]<='7' ){ |
| 25317 | 25375 | v = v*8 + zPrompt[++i] - '0'; |
| 25318 | 25376 | } |
| 25319 | 25377 | if( !mOff ) sqlite3_str_appendchar(pOut, 1, v); |
| 25320 | 25378 | zPrompt += i+1; |
| | @@ -25533,15 +25591,36 @@ |
| 25533 | 25591 | memmove(z+idxSpace+nNew, z+idxSpace, len-nNew-idxSpace); |
| 25534 | 25592 | memset(z+idxSpace, ' ', nNew); |
| 25535 | 25593 | } |
| 25536 | 25594 | } |
| 25537 | 25595 | } |
| 25538 | | - |
| 25539 | 25596 | if( 0==sqlite3_str_length(pOut) ){ |
| 25540 | 25597 | /* Avoid a bogus OOM */ |
| 25541 | 25598 | sqlite3_str_appendchar(pOut, 1, '\0'); |
| 25542 | 25599 | } |
| 25600 | + |
| 25601 | + /* Editline does not recognize ANSI X3.64 escape sequences. So we have |
| 25602 | + ** to find them all and enclose them inside '\001'...'\002' delimiters. |
| 25603 | + ** Some versions of readline also require this, but others do not. |
| 25604 | + */ |
| 25605 | + if( p->bDelimitNonprint && strstr(sqlite3_str_value(pOut),"\033[")!=0 ){ |
| 25606 | + char *zOrig = sqlite3_str_finish(pOut); |
| 25607 | + int n; |
| 25608 | + pOut = sqlite3_str_new(0); |
| 25609 | + for(i=0; zOrig[i]; i++){ |
| 25610 | + if( zOrig[i]=='\033' && (n = nAnsiEscape(zOrig+i))>0 ){ |
| 25611 | + sqlite3_str_appendchar(pOut, 1, 1); |
| 25612 | + sqlite3_str_append(pOut, &zOrig[i], n); |
| 25613 | + sqlite3_str_appendchar(pOut, 1, 2); |
| 25614 | + i += n-1; |
| 25615 | + }else{ |
| 25616 | + sqlite3_str_appendchar(pOut, 1, zOrig[i]); |
| 25617 | + } |
| 25618 | + } |
| 25619 | + sqlite3_free(zOrig); |
| 25620 | + } |
| 25621 | + |
| 25543 | 25622 | return sqlite3_str_finish(pOut); |
| 25544 | 25623 | } |
| 25545 | 25624 | |
| 25546 | 25625 | /* |
| 25547 | 25626 | ** Retrieve a single line of input text. |
| | @@ -25912,21 +25991,27 @@ |
| 25912 | 25991 | } |
| 25913 | 25992 | sqlite3_result_value(pCtx, apVal[0]); |
| 25914 | 25993 | } |
| 25915 | 25994 | |
| 25916 | 25995 | /* |
| 25917 | | -** SQL function: shell_prompt_test(PROMPT) |
| 25918 | | -** shell_prompt_test(PROMPT,PRIOR) |
| 25919 | | -** shell_prompt_test(PROMPT,PRIOR,FILENAME) |
| 25996 | +** SQL function: shell_prompt_test(PROMPT,PRIOR,FILENAME,FLAGS) |
| 25920 | 25997 | ** |
| 25921 | 25998 | ** Return the shell prompt, with escapes expanded, for testing purposes. |
| 25922 | 25999 | ** The first argument is the raw (unexpanded) prompt string. Or if the |
| 25923 | 26000 | ** first argument is NULL, then use whatever prompt string is currently |
| 25924 | 26001 | ** configured. If the second argument exists and is not NULL, then the |
| 25925 | 26002 | ** second argument is understood to be prior incomplete text and a |
| 25926 | 26003 | ** continuation prompt is generated. If a third argument is provided, |
| 25927 | | -** it is assumed to be the full pathname of the database file. |
| 26004 | +** it is assumed to be the full pathname of the database file. The |
| 26005 | +** fourth argument, if provided, is an integer of flags: |
| 26006 | +** |
| 26007 | +** 0x0001 Always insert \001..\002 delimiters around ANSI escapes |
| 26008 | +** 0x0002 Never insert \001..\002 delimiters |
| 26009 | +** |
| 26010 | +** This function is for testing purposes only. The interface may change. |
| 26011 | +** The function itself might be renamed or removed in future releases. Do |
| 26012 | +** not use this function in applications. |
| 25928 | 26013 | */ |
| 25929 | 26014 | static void shellExpandPrompt( |
| 25930 | 26015 | sqlite3_context *pCtx, |
| 25931 | 26016 | int nVal, |
| 25932 | 26017 | sqlite3_value **apVal |
| | @@ -25936,11 +26021,14 @@ |
| 25936 | 26021 | const char *zPrior; |
| 25937 | 26022 | const char *zSavedDbFile; |
| 25938 | 26023 | int mSavedFlgs; |
| 25939 | 26024 | const char *zFName; |
| 25940 | 26025 | char *zRes; |
| 26026 | + int mFlags; |
| 26027 | + char bSavedDelimit = p->bDelimitNonprint; |
| 25941 | 26028 | |
| 26029 | + if( nVal<1 ) return; |
| 25942 | 26030 | if( nVal<2 |
| 25943 | 26031 | || (zPrior = (const char*)sqlite3_value_text(apVal[1]))==0 |
| 25944 | 26032 | || zPrior[0]==0 |
| 25945 | 26033 | ){ |
| 25946 | 26034 | zPrior = 0; |
| | @@ -25952,12 +26040,19 @@ |
| 25952 | 26040 | zSavedDbFile = p->pAuxDb->zDbFilename; |
| 25953 | 26041 | mSavedFlgs = p->pAuxDb->mFlgs; |
| 25954 | 26042 | if( nVal>=3 && (zFName = (const char*)sqlite3_value_text(apVal[2]))!=0 ){ |
| 25955 | 26043 | p->pAuxDb->zDbFilename = zFName; |
| 25956 | 26044 | p->pAuxDb->mFlgs |= 0x001; |
| 26045 | + } |
| 26046 | + mFlags = nVal>=4 ? sqlite3_value_int(apVal[3]) : 0; |
| 26047 | + if( mFlags & 0x0001 ){ |
| 26048 | + p->bDelimitNonprint = 1; |
| 26049 | + }else if( mFlags & 0x0002 ){ |
| 26050 | + p->bDelimitNonprint = 0; |
| 25957 | 26051 | } |
| 25958 | 26052 | zRes = expand_prompt(p, zPrior, zPrompt); |
| 26053 | + p->bDelimitNonprint = bSavedDelimit; |
| 25959 | 26054 | p->pAuxDb->zDbFilename = zSavedDbFile; |
| 25960 | 26055 | p->pAuxDb->mFlgs = mSavedFlgs; |
| 25961 | 26056 | sqlite3_result_text(pCtx, zRes, -1, SQLITE_TRANSIENT); |
| 25962 | 26057 | sqlite3_free(zRes); |
| 25963 | 26058 | } |
| | @@ -29406,15 +29501,11 @@ |
| 29406 | 29501 | sqlite3_create_function(p->db, "edit", 1, SQLITE_UTF8, 0, |
| 29407 | 29502 | editFunc, 0, 0); |
| 29408 | 29503 | sqlite3_create_function(p->db, "edit", 2, SQLITE_UTF8, 0, |
| 29409 | 29504 | editFunc, 0, 0); |
| 29410 | 29505 | #endif |
| 29411 | | - sqlite3_create_function(p->db, "shell_prompt_test", 1, SQLITE_UTF8, |
| 29412 | | - p, shellExpandPrompt, 0, 0); |
| 29413 | | - sqlite3_create_function(p->db, "shell_prompt_test", 2, SQLITE_UTF8, |
| 29414 | | - p, shellExpandPrompt, 0, 0); |
| 29415 | | - sqlite3_create_function(p->db, "shell_prompt_test", 3, SQLITE_UTF8, |
| 29506 | + sqlite3_create_function(p->db, "shell_prompt_test", -1, SQLITE_UTF8, |
| 29416 | 29507 | p, shellExpandPrompt, 0, 0); |
| 29417 | 29508 | sqlite3_create_function(p->db, "shell_temp_filename", 1, SQLITE_UTF8, |
| 29418 | 29509 | p, shellTempFilenameFunc, 0, 0); |
| 29419 | 29510 | |
| 29420 | 29511 | |
| | @@ -37724,31 +37815,32 @@ |
| 37724 | 37815 | verify_uninitialized(); |
| 37725 | 37816 | #endif |
| 37726 | 37817 | sqlite3_config(SQLITE_CONFIG_URI, 1); |
| 37727 | 37818 | sqlite3_config(SQLITE_CONFIG_MULTITHREAD); |
| 37728 | 37819 | globalShellState = p; |
| 37820 | +#if HAVE_EDITLINE || HAVE_READLINE |
| 37821 | + /* Editline requires \001...\002 delimiters around ANSI x3.64 escapes in |
| 37822 | + ** prompt strings. Readline does sometimes, depending on how it is |
| 37823 | + ** compiled and installed. */ |
| 37824 | + p->bDelimitNonprint = 1; |
| 37825 | +#else |
| 37826 | + /* No \001...\002 escapes required for linenoise or when not using a |
| 37827 | + ** command-line editing library */ |
| 37828 | + p->bDelimitNonprint = 0; |
| 37829 | +#endif |
| 37729 | 37830 | } |
| 37730 | 37831 | |
| 37731 | 37832 | /* |
| 37732 | 37833 | ** Output text to the console in a font that attracts extra attention. |
| 37733 | 37834 | */ |
| 37734 | | -#if 0 /* Windows now handles ANSI escape codes */ |
| 37735 | | -static void printBold(const char *zText){ |
| 37736 | | - HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE); |
| 37737 | | - CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo; |
| 37738 | | - GetConsoleScreenBufferInfo(out, &defaultScreenInfo); |
| 37739 | | - SetConsoleTextAttribute(out, |
| 37740 | | - FOREGROUND_RED|FOREGROUND_INTENSITY |
| 37741 | | - ); |
| 37742 | | - sputz(stdout, zText); |
| 37743 | | - SetConsoleTextAttribute(out, defaultScreenInfo.wAttributes); |
| 37744 | | -} |
| 37745 | | -#else |
| 37746 | | -static void printBold(const char *zText){ |
| 37747 | | - cli_printf(stdout, "\033[1;36m\033[3m%s\033[0m", zText); |
| 37748 | | -} |
| 37749 | | -#endif |
| 37835 | +static void printBold(const char *zText){ |
| 37836 | + if( shellNoColor() ){ |
| 37837 | + cli_printf(stdout, "%s", zText); |
| 37838 | + }else{ |
| 37839 | + cli_printf(stdout, "\033[1;36m\033[3m%s\033[0m", zText); |
| 37840 | + } |
| 37841 | +} |
| 37750 | 37842 | |
| 37751 | 37843 | /* |
| 37752 | 37844 | ** Get the argument to an --option. Throw an error and die if no argument |
| 37753 | 37845 | ** is available. |
| 37754 | 37846 | */ |
| 37755 | 37847 | |