** Add an SQL statement to the analysis. */
| 12107 | ** Add an SQL statement to the analysis. |
| 12108 | */ |
| 12109 | int sqlite3_expert_sql( |
| 12110 | sqlite3expert *p, /* From sqlite3_expert_new() */ |
| 12111 | const char *zSql, /* SQL statement to add */ |
| 12112 | char **pzErr /* OUT: Error message (if any) */ |
| 12113 | ){ |
| 12114 | IdxScan *pScanOrig = p->pScan; |
| 12115 | IdxStatement *pStmtOrig = p->pStatement; |
| 12116 | int rc = SQLITE_OK; |
| 12117 | const char *zStmt = zSql; |
| 12118 | |
| 12119 | if( p->bRun ) return SQLITE_MISUSE; |
| 12120 | |
| 12121 | while( rc==SQLITE_OK && zStmt && zStmt[0] ){ |
| 12122 | sqlite3_stmt *pStmt = 0; |
| 12123 | rc = sqlite3_prepare_v2(p->dbv, zStmt, -1, &pStmt, &zStmt); |
| 12124 | if( rc==SQLITE_OK ){ |
| 12125 | if( pStmt ){ |
| 12126 | IdxStatement *pNew; |
| 12127 | const char *z = sqlite3_sql(pStmt); |
| 12128 | int n = STRLEN(z); |
| 12129 | pNew = (IdxStatement*)idxMalloc(&rc, sizeof(IdxStatement) + n+1); |
| 12130 | if( rc==SQLITE_OK ){ |
| 12131 | pNew->zSql = (char*)&pNew[1]; |
| 12132 | memcpy(pNew->zSql, z, n+1); |
| 12133 | pNew->pNext = p->pStatement; |
| 12134 | if( p->pStatement ) pNew->iId = p->pStatement->iId+1; |
| 12135 | p->pStatement = pNew; |
| 12136 | } |
| 12137 | sqlite3_finalize(pStmt); |
| 12138 | } |
| 12139 | }else{ |
| 12140 | idxDatabaseError(p->dbv, pzErr); |
| 12141 | } |
| 12142 | } |
| 12143 | |
| 12144 | if( rc!=SQLITE_OK ){ |
| 12145 | idxScanFree(p->pScan, pScanOrig); |
| 12146 | idxStatementFree(p->pStatement, pStmtOrig); |
| 12147 | p->pScan = pScanOrig; |
| 12148 | p->pStatement = pStmtOrig; |
| 12149 | } |
| 12150 | |
| 12151 | return rc; |
| 12152 | } |
| 12153 | |
| 12154 | int sqlite3_expert_analyze(sqlite3expert *p, char **pzErr){ |
| 12155 | int rc; |
no test coverage detected