** Add an SQL statement to the analysis. */
| 10199 | ** Add an SQL statement to the analysis. |
| 10200 | */ |
| 10201 | int sqlite3_expert_sql( |
| 10202 | sqlite3expert *p, /* From sqlite3_expert_new() */ |
| 10203 | const char *zSql, /* SQL statement to add */ |
| 10204 | char **pzErr /* OUT: Error message (if any) */ |
| 10205 | ){ |
| 10206 | IdxScan *pScanOrig = p->pScan; |
| 10207 | IdxStatement *pStmtOrig = p->pStatement; |
| 10208 | int rc = SQLITE_OK; |
| 10209 | const char *zStmt = zSql; |
| 10210 | |
| 10211 | if( p->bRun ) return SQLITE_MISUSE; |
| 10212 | |
| 10213 | while( rc==SQLITE_OK && zStmt && zStmt[0] ){ |
| 10214 | sqlite3_stmt *pStmt = 0; |
| 10215 | rc = sqlite3_prepare_v2(p->dbv, zStmt, -1, &pStmt, &zStmt); |
| 10216 | if( rc==SQLITE_OK ){ |
| 10217 | if( pStmt ){ |
| 10218 | IdxStatement *pNew; |
| 10219 | const char *z = sqlite3_sql(pStmt); |
| 10220 | int n = STRLEN(z); |
| 10221 | pNew = (IdxStatement*)idxMalloc(&rc, sizeof(IdxStatement) + n+1); |
| 10222 | if( rc==SQLITE_OK ){ |
| 10223 | pNew->zSql = (char*)&pNew[1]; |
| 10224 | memcpy(pNew->zSql, z, n+1); |
| 10225 | pNew->pNext = p->pStatement; |
| 10226 | if( p->pStatement ) pNew->iId = p->pStatement->iId+1; |
| 10227 | p->pStatement = pNew; |
| 10228 | } |
| 10229 | sqlite3_finalize(pStmt); |
| 10230 | } |
| 10231 | }else{ |
| 10232 | idxDatabaseError(p->dbv, pzErr); |
| 10233 | } |
| 10234 | } |
| 10235 | |
| 10236 | if( rc!=SQLITE_OK ){ |
| 10237 | idxScanFree(p->pScan, pScanOrig); |
| 10238 | idxStatementFree(p->pStatement, pStmtOrig); |
| 10239 | p->pScan = pScanOrig; |
| 10240 | p->pStatement = pStmtOrig; |
| 10241 | } |
| 10242 | |
| 10243 | return rc; |
| 10244 | } |
| 10245 | |
| 10246 | int sqlite3_expert_analyze(sqlite3expert *p, char **pzErr){ |
| 10247 | int rc; |
no test coverage detected