| | @@ -79,10 +79,14 @@ |
| 79 | 79 | ** should only be used when building the "fiddle" web application, as |
| 80 | 80 | ** the browser-mode build has much different user input requirements |
| 81 | 81 | ** and this build mode rewires the user input subsystem to account for |
| 82 | 82 | ** that. |
| 83 | 83 | */ |
| 84 | +#if defined(SQLITE_SHELL_FIDDLE) |
| 85 | +# undef SQLITE_OMIT_LOAD_EXTENSION |
| 86 | +# define SQLITE_OMIT_LOAD_EXTENSION 1 |
| 87 | +#endif |
| 84 | 88 | |
| 85 | 89 | /* |
| 86 | 90 | ** Warning pragmas copied from msvc.h in the core. |
| 87 | 91 | */ |
| 88 | 92 | #if defined(_MSC_VER) |
| | @@ -995,10 +999,19 @@ |
| 995 | 999 | */ |
| 996 | 1000 | static void qrfOom(Qrf *p){ |
| 997 | 1001 | qrfError(p, SQLITE_NOMEM, "out of memory"); |
| 998 | 1002 | } |
| 999 | 1003 | |
| 1004 | +/* |
| 1005 | +** Transfer any error in pStr over into p. |
| 1006 | +*/ |
| 1007 | +static void qrfStrErr(Qrf *p, sqlite3_str *pStr){ |
| 1008 | + int rc = pStr ? sqlite3_str_errcode(pStr) : 0; |
| 1009 | + if( rc ){ |
| 1010 | + qrfError(p, rc, sqlite3_errstr(rc)); |
| 1011 | + } |
| 1012 | +} |
| 1000 | 1013 | |
| 1001 | 1014 | |
| 1002 | 1015 | /* |
| 1003 | 1016 | ** Add a new entry to the EXPLAIN QUERY PLAN data |
| 1004 | 1017 | */ |
| | @@ -1217,11 +1230,13 @@ |
| 1217 | 1230 | sqlite3_str_reset(pLine); |
| 1218 | 1231 | }else{ |
| 1219 | 1232 | qrfEqpAppend(p, iId, iPid, zo); |
| 1220 | 1233 | } |
| 1221 | 1234 | } |
| 1235 | + qrfStrErr(p, pLine); |
| 1222 | 1236 | sqlite3_free(sqlite3_str_finish(pLine)); |
| 1237 | + qrfStrErr(p, pStats); |
| 1223 | 1238 | sqlite3_free(sqlite3_str_finish(pStats)); |
| 1224 | 1239 | #endif |
| 1225 | 1240 | } |
| 1226 | 1241 | |
| 1227 | 1242 | |
| | @@ -2731,10 +2746,11 @@ |
| 2731 | 2746 | int nNL = 0; |
| 2732 | 2747 | int n, w; |
| 2733 | 2748 | pStr = sqlite3_str_new(p->db); |
| 2734 | 2749 | qrfEncodeText(p, pStr, z ? z : ""); |
| 2735 | 2750 | n = sqlite3_str_length(pStr); |
| 2751 | + qrfStrErr(p, pStr); |
| 2736 | 2752 | z = data.az[data.n] = sqlite3_str_finish(pStr); |
| 2737 | 2753 | if( p->spec.nTitleLimit ){ |
| 2738 | 2754 | nNL = 0; |
| 2739 | 2755 | data.aiWth[data.n] = w = qrfTitleLimit(data.az[data.n], |
| 2740 | 2756 | p->spec.nTitleLimit ); |
| | @@ -2758,10 +2774,11 @@ |
| 2758 | 2774 | int n, w; |
| 2759 | 2775 | int eType = sqlite3_column_type(p->pStmt,i); |
| 2760 | 2776 | pStr = sqlite3_str_new(p->db); |
| 2761 | 2777 | qrfRenderValue(p, pStr, i); |
| 2762 | 2778 | n = sqlite3_str_length(pStr); |
| 2779 | + qrfStrErr(p, pStr); |
| 2763 | 2780 | z = data.az[data.n] = sqlite3_str_finish(pStr); |
| 2764 | 2781 | data.abNum[data.n] = eType==SQLITE_INTEGER || eType==SQLITE_FLOAT; |
| 2765 | 2782 | data.aiWth[data.n] = w = qrfDisplayWidth(z, n, &nNL); |
| 2766 | 2783 | data.n++; |
| 2767 | 2784 | if( w>data.a[i].mxW ) data.a[i].mxW = w; |
| | @@ -2912,11 +2929,11 @@ |
| 2912 | 2929 | ){ |
| 2913 | 2930 | bRTrim = 1; |
| 2914 | 2931 | }else{ |
| 2915 | 2932 | bRTrim = 0; |
| 2916 | 2933 | } |
| 2917 | | - for(i=0; i<data.n; i+=nColumn){ |
| 2934 | + for(i=0; i<data.n && sqlite3_str_errcode(p->pOut)==SQLITE_OK; i+=nColumn){ |
| 2918 | 2935 | int bMore; |
| 2919 | 2936 | int nRow = 0; |
| 2920 | 2937 | |
| 2921 | 2938 | /* Draw a single row of the table. This might be the title line |
| 2922 | 2939 | ** (if there is a title line) or a row in the body of the table. |
| | @@ -3099,11 +3116,11 @@ |
| 3099 | 3116 | assert( 0==sqlite3_stricmp( sqlite3_column_name(p->pStmt, 0), "addr" ) ); |
| 3100 | 3117 | assert( 0==sqlite3_stricmp( sqlite3_column_name(p->pStmt, 1), "opcode" ) ); |
| 3101 | 3118 | assert( 0==sqlite3_stricmp( sqlite3_column_name(p->pStmt, 2), "p1" ) ); |
| 3102 | 3119 | assert( 0==sqlite3_stricmp( sqlite3_column_name(p->pStmt, 3), "p2" ) ); |
| 3103 | 3120 | |
| 3104 | | - for(iOp=0; SQLITE_ROW==sqlite3_step(p->pStmt); iOp++){ |
| 3121 | + for(iOp=0; SQLITE_ROW==sqlite3_step(p->pStmt) && !p->iErr; iOp++){ |
| 3105 | 3122 | int iAddr = sqlite3_column_int(p->pStmt, 0); |
| 3106 | 3123 | const char *zOp = (const char*)sqlite3_column_text(p->pStmt, 1); |
| 3107 | 3124 | int p1 = sqlite3_column_int(p->pStmt, 2); |
| 3108 | 3125 | int p2 = sqlite3_column_int(p->pStmt, 3); |
| 3109 | 3126 | |
| | @@ -3156,11 +3173,11 @@ |
| 3156 | 3173 | nWidth = sizeof(aScanExpWidth)/sizeof(int); |
| 3157 | 3174 | iIndent = 3; |
| 3158 | 3175 | } |
| 3159 | 3176 | if( nArg>nWidth ) nArg = nWidth; |
| 3160 | 3177 | |
| 3161 | | - for(iOp=0; sqlite3_step(p->pStmt)==SQLITE_ROW; iOp++){ |
| 3178 | + for(iOp=0; sqlite3_step(p->pStmt)==SQLITE_ROW && !p->iErr; iOp++){ |
| 3162 | 3179 | /* If this is the first row seen, print out the headers */ |
| 3163 | 3180 | if( iOp==0 ){ |
| 3164 | 3181 | for(i=0; i<nArg; i++){ |
| 3165 | 3182 | const char *zCol = sqlite3_column_name(p->pStmt, aMap[i]); |
| 3166 | 3183 | qrfWidthPrint(p,p->pOut, aWidth[i], zCol); |
| | @@ -3412,10 +3429,11 @@ |
| 3412 | 3429 | sqlite3_str_append(p->pOut, "\n", 1); |
| 3413 | 3430 | zVal += iNext; |
| 3414 | 3431 | }while( zVal[0] ); |
| 3415 | 3432 | sqlite3_str_reset(pVal); |
| 3416 | 3433 | } |
| 3434 | + qrfStrErr(p, pVal); |
| 3417 | 3435 | sqlite3_free(sqlite3_str_finish(pVal)); |
| 3418 | 3436 | qrfWrite(p); |
| 3419 | 3437 | break; |
| 3420 | 3438 | } |
| 3421 | 3439 | case QRF_STYLE_Eqp: { |
| | @@ -3475,11 +3493,11 @@ |
| 3475 | 3493 | p->pOut = sqlite3_str_new(p->db); |
| 3476 | 3494 | if( p->pOut==0 ){ |
| 3477 | 3495 | qrfOom(p); |
| 3478 | 3496 | return; |
| 3479 | 3497 | } |
| 3480 | | - p->iErr = 0; |
| 3498 | + p->iErr = SQLITE_OK; |
| 3481 | 3499 | p->nCol = sqlite3_column_count(p->pStmt); |
| 3482 | 3500 | p->nRow = 0; |
| 3483 | 3501 | sz = sizeof(sqlite3_qrf_spec); |
| 3484 | 3502 | memcpy(&p->spec, pSpec, sz); |
| 3485 | 3503 | if( p->spec.zNull==0 ) p->spec.zNull = ""; |
| | @@ -3653,10 +3671,11 @@ |
| 3653 | 3671 | qrfEqpRender(p, 0); |
| 3654 | 3672 | qrfWrite(p); |
| 3655 | 3673 | break; |
| 3656 | 3674 | } |
| 3657 | 3675 | } |
| 3676 | + qrfStrErr(p, p->pOut); |
| 3658 | 3677 | if( p->spec.pzOutput ){ |
| 3659 | 3678 | if( p->spec.pzOutput[0] ){ |
| 3660 | 3679 | sqlite3_int64 n, sz; |
| 3661 | 3680 | char *zCombined; |
| 3662 | 3681 | sz = strlen(p->spec.pzOutput[0]); |
| | @@ -9475,11 +9494,11 @@ |
| 9475 | 9494 | ** (X) match X |
| 9476 | 9495 | ** X|Y X or Y |
| 9477 | 9496 | ** ^X X occurring at the beginning of the string |
| 9478 | 9497 | ** X$ X occurring at the end of the string |
| 9479 | 9498 | ** . Match any single character |
| 9480 | | -** \c Character c where c is one of \{}()[]|*+?. |
| 9499 | +** \c Character c where c is one of \{}()[]|*+?-. |
| 9481 | 9500 | ** \c C-language escapes for c in afnrtv. ex: \t or \n |
| 9482 | 9501 | ** \uXXXX Where XXXX is exactly 4 hex digits, unicode value XXXX |
| 9483 | 9502 | ** \xXX Where XX is exactly 2 hex digits, unicode value XX |
| 9484 | 9503 | ** [abc] Any single character from the set abc |
| 9485 | 9504 | ** [^abc] Any single character not in the set abc |
| | @@ -9860,11 +9879,11 @@ |
| 9860 | 9879 | |
| 9861 | 9880 | /* A backslash character has been seen, read the next character and |
| 9862 | 9881 | ** return its interpretation. |
| 9863 | 9882 | */ |
| 9864 | 9883 | static unsigned re_esc_char(ReCompiled *p){ |
| 9865 | | - static const char zEsc[] = "afnrtv\\()*.+?[$^{|}]"; |
| 9884 | + static const char zEsc[] = "afnrtv\\()*.+?[$^{|}]-"; |
| 9866 | 9885 | static const char zTrans[] = "\a\f\n\r\t\v"; |
| 9867 | 9886 | int i, v = 0; |
| 9868 | 9887 | char c; |
| 9869 | 9888 | if( p->sIn.i>=p->sIn.mx ) return 0; |
| 9870 | 9889 | c = p->sIn.z[p->sIn.i]; |
| | @@ -33530,17 +33549,19 @@ |
| 33530 | 33549 | || sqlite3_strlike(zName, "sqlite_schema", '\\')==0 |
| 33531 | 33550 | || sqlite3_strlike(zName,"sqlite_temp_master", '\\')==0 |
| 33532 | 33551 | || sqlite3_strlike(zName,"sqlite_temp_schema", '\\')==0; |
| 33533 | 33552 | if( isSchema ){ |
| 33534 | 33553 | cli_printf(p->out, |
| 33535 | | - "CREATE TABLE %s (\n" |
| 33554 | + "CREATE TABLE %ssqlite_schema (\n" |
| 33536 | 33555 | " type text,\n" |
| 33537 | 33556 | " name text,\n" |
| 33538 | 33557 | " tbl_name text,\n" |
| 33539 | 33558 | " rootpage integer,\n" |
| 33540 | 33559 | " sql text\n" |
| 33541 | | - ");\n", zName); |
| 33560 | + ");\n", |
| 33561 | + sqlite3_strlike("sqlite_t%",zName,0)==0 ? "temp." : "" |
| 33562 | + ); |
| 33542 | 33563 | } |
| 33543 | 33564 | } |
| 33544 | 33565 | rc = sqlite3_prepare_v2(p->db, "PRAGMA database_list", -1, &pStmt, 0); |
| 33545 | 33566 | if( rc ){ |
| 33546 | 33567 | shellDatabaseError(p->db); |
| | @@ -33596,11 +33617,11 @@ |
| 33596 | 33617 | }else{ |
| 33597 | 33618 | sqlite3_str_appendf(pSql, " LIKE %Q ESCAPE '\\' AND ", zName); |
| 33598 | 33619 | } |
| 33599 | 33620 | } |
| 33600 | 33621 | if( bNoSystemTabs ){ |
| 33601 | | - sqlite3_str_appendf(pSql, " name NOT LIKE 'sqlite__%%' ESCALE '_' AND "); |
| 33622 | + sqlite3_str_appendf(pSql, " name NOT LIKE 'sqlite__%%' ESCAPE '_' AND "); |
| 33602 | 33623 | } |
| 33603 | 33624 | sqlite3_str_appendf(pSql, "sql IS NOT NULL ORDER BY snum, rowid"); |
| 33604 | 33625 | if( bDebug ){ |
| 33605 | 33626 | cli_printf(p->out, "SQL: %s;\n", sqlite3_str_value(pSql)); |
| 33606 | 33627 | }else{ |
| | @@ -36140,11 +36161,30 @@ |
| 36140 | 36161 | |
| 36141 | 36162 | if( zVfs ){ |
| 36142 | 36163 | sqlite3_vfs *pVfs = sqlite3_vfs_find(zVfs); |
| 36143 | 36164 | if( pVfs ){ |
| 36144 | 36165 | sqlite3_vfs_register(pVfs, 1); |
| 36145 | | - }else{ |
| 36166 | + } |
| 36167 | +#if !defined(SQLITE_OMIT_LOAD_EXTENSION) |
| 36168 | + else if( access(zVfs,0)==0 ){ |
| 36169 | + /* If the VFS name is not the name of an existing VFS, but it is |
| 36170 | + ** the name of a file, then try to load that file as an extension. |
| 36171 | + ** Presumably the extension implements the desired VFS. */ |
| 36172 | + sqlite3 *db = 0; |
| 36173 | + char *zErr = 0; |
| 36174 | + sqlite3_open(":memory:", &db); |
| 36175 | + sqlite3_enable_load_extension(db, 1); |
| 36176 | + rc = sqlite3_load_extension(db, zVfs, 0, &zErr); |
| 36177 | + sqlite3_close(db); |
| 36178 | + if( (rc&0xff)!=SQLITE_OK ){ |
| 36179 | + cli_printf(stderr, "could not load extension VFS \"%s\": %s\n", |
| 36180 | + zVfs, zErr); |
| 36181 | + exit(1); |
| 36182 | + } |
| 36183 | + } |
| 36184 | +#endif |
| 36185 | + else{ |
| 36146 | 36186 | cli_printf(stderr,"no such VFS: \"%s\"\n", zVfs); |
| 36147 | 36187 | exit(1); |
| 36148 | 36188 | } |
| 36149 | 36189 | } |
| 36150 | 36190 | |
| 36151 | 36191 | |