Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Change the name of the STMT virtual table to SQLITE_STMT. Also remove the first column of that virtual table, which was a pointer leak. |
---|---|
Downloads: | Tarball | ZIP archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
1bc4e93407b7894b0271fbde3720930d |
User & Date: | drh 2017-07-14 15:14:21.567 |
Context
2017-07-14
| ||
15:18 | Fix a typo in the header comment to the remember extension. No code changes. (check-in: 604b9664f4 user: drh tags: trunk) | |
15:14 | Change the name of the STMT virtual table to SQLITE_STMT. Also remove the first column of that virtual table, which was a pointer leak. (check-in: 1bc4e93407 user: drh tags: trunk) | |
13:24 | Minor updates to requirements marks and documention. No changes to code. (check-in: 8f6dd5e290 user: drh tags: trunk) | |
Changes
Changes to ext/misc/stmt.c.
︙ | ︙ | |||
25 26 27 28 29 30 31 | #include "sqlite3ext.h" #endif SQLITE_EXTENSION_INIT1 #include <assert.h> #include <string.h> #ifndef SQLITE_OMIT_VIRTUALTABLE | < < < < < < < < < < < < < < < < < | 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include "sqlite3ext.h" #endif SQLITE_EXTENSION_INIT1 #include <assert.h> #include <string.h> #ifndef SQLITE_OMIT_VIRTUALTABLE /* stmt_vtab is a subclass of sqlite3_vtab which will ** serve as the underlying representation of a stmt virtual table */ typedef struct stmt_vtab stmt_vtab; struct stmt_vtab { sqlite3_vtab base; /* Base class - must be first */ |
︙ | ︙ | |||
88 89 90 91 92 93 94 | sqlite3_vtab **ppVtab, char **pzErr ){ stmt_vtab *pNew; int rc; /* Column numbers */ | < | | | | | | | | | | | | | 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 | sqlite3_vtab **ppVtab, char **pzErr ){ stmt_vtab *pNew; int rc; /* Column numbers */ #define STMT_COLUMN_SQL 0 /* SQL for the statement */ #define STMT_COLUMN_NCOL 1 /* Number of result columns */ #define STMT_COLUMN_RO 2 /* True if read-only */ #define STMT_COLUMN_BUSY 3 /* True if currently busy */ #define STMT_COLUMN_NSCAN 4 /* SQLITE_STMTSTATUS_FULLSCAN_STEP */ #define STMT_COLUMN_NSORT 5 /* SQLITE_STMTSTATUS_SORT */ #define STMT_COLUMN_NAIDX 6 /* SQLITE_STMTSTATUS_AUTOINDEX */ #define STMT_COLUMN_NSTEP 7 /* SQLITE_STMTSTATUS_VM_STEP */ #define STMT_COLUMN_REPREP 8 /* SQLITE_STMTSTATUS_REPREPARE */ #define STMT_COLUMN_RUN 9 /* SQLITE_STMTSTATUS_RUN */ #define STMT_COLUMN_MEM 10 /* SQLITE_STMTSTATUS_MEMUSED */ rc = sqlite3_declare_vtab(db, "CREATE TABLE x(sql,ncol,ro,busy,nscan,nsort,naidx,nstep," "reprep,run,mem)"); if( rc==SQLITE_OK ){ pNew = sqlite3_malloc( sizeof(*pNew) ); *ppVtab = (sqlite3_vtab*)pNew; if( pNew==0 ) return SQLITE_NOMEM; memset(pNew, 0, sizeof(*pNew)); pNew->db = db; |
︙ | ︙ | |||
166 167 168 169 170 171 172 | static int stmtColumn( sqlite3_vtab_cursor *cur, /* The cursor */ sqlite3_context *ctx, /* First argument to sqlite3_result_...() */ int i /* Which column to return */ ){ stmt_cursor *pCur = (stmt_cursor*)cur; switch( i ){ | < < < < | 148 149 150 151 152 153 154 155 156 157 158 159 160 161 | static int stmtColumn( sqlite3_vtab_cursor *cur, /* The cursor */ sqlite3_context *ctx, /* First argument to sqlite3_result_...() */ int i /* Which column to return */ ){ stmt_cursor *pCur = (stmt_cursor*)cur; switch( i ){ case STMT_COLUMN_SQL: { sqlite3_result_text(ctx, sqlite3_sql(pCur->pStmt), -1, SQLITE_TRANSIENT); break; } case STMT_COLUMN_NCOL: { sqlite3_result_int(ctx, sqlite3_column_count(pCur->pStmt)); break; |
︙ | ︙ | |||
291 292 293 294 295 296 297 | }; #endif /* SQLITE_OMIT_VIRTUALTABLE */ int sqlite3StmtVtabInit(sqlite3 *db){ int rc = SQLITE_OK; #ifndef SQLITE_OMIT_VIRTUALTABLE | | | 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | }; #endif /* SQLITE_OMIT_VIRTUALTABLE */ int sqlite3StmtVtabInit(sqlite3 *db){ int rc = SQLITE_OK; #ifndef SQLITE_OMIT_VIRTUALTABLE rc = sqlite3_create_module(db, "sqlite_stmt", &stmtModule, 0); #endif return rc; } #ifndef SQLITE_CORE #ifdef _WIN32 __declspec(dllexport) |
︙ | ︙ |
Changes to test/stmtvtab1.test.
︙ | ︙ | |||
28 29 30 31 32 33 34 | set x giraffe set y mango set z alabama do_execsql_test stmtvtab1-100 { CREATE TABLE t1(a,b,c); INSERT INTO t1 VALUES($a,$b,$c); CREATE INDEX t1a ON t1(a); | | | | | | | | | | | 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | set x giraffe set y mango set z alabama do_execsql_test stmtvtab1-100 { CREATE TABLE t1(a,b,c); INSERT INTO t1 VALUES($a,$b,$c); CREATE INDEX t1a ON t1(a); SELECT run, sql FROM sqlite_stmt ORDER BY 1; } {1 {SELECT run, sql FROM sqlite_stmt ORDER BY 1;} 1 {CREATE INDEX t1a ON t1(a);} 1 {INSERT INTO t1 VALUES($a,$b,$c);} 1 {CREATE TABLE t1(a,b,c);}} set x neon set y event set z future do_execsql_test stmtvtab1-110 { INSERT INTO t1 VALUES($a,$b,$c); SELECT reprep,run,SQL FROM sqlite_stmt WHERE sql LIKE '%INSERT%' AND NOT busy; } {1 2 {INSERT INTO t1 VALUES($a,$b,$c);}} set x network set y fit set z metal do_execsql_test stmtvtab1-120 { INSERT INTO t1 VALUES($a,$b,$c); SELECT reprep,run,SQL FROM sqlite_stmt WHERE sql LIKE '%INSERT%' AND NOT busy; } {1 3 {INSERT INTO t1 VALUES($a,$b,$c);}} set x history set y detail set z grace do_execsql_test stmtvtab1-130 { CREATE INDEX t1b ON t1(b); INSERT INTO t1 VALUES($a,$b,$c); SELECT reprep,run,SQL FROM sqlite_stmt WHERE sql LIKE '%INSERT%' AND NOT busy; } {2 4 {INSERT INTO t1 VALUES($a,$b,$c);}} # All statements are still in cache # do_execsql_test stmtvtab1-140 { SELECT count(*) FROM sqlite_stmt WHERE NOT busy; } {6} # None of the prepared statements should use more than a couple thousand # bytes of memory # #db eval {SELECT mem, sql FROM sqlite_stmt} {puts [format {%5d %s} $mem $sql]} do_execsql_test stmtvtab1-150 { SELECT count(*) FROM sqlite_stmt WHERE mem>5000; } {0} # Flushing the cache clears all of the prepared statements. # db cache flush do_execsql_test stmtvtab1-160 { SELECT * FROM sqlite_stmt WHERE NOT busy; } {} |