| 11798 | } |
| 11799 | |
| 11800 | static int idxPopulateOneStat1( |
| 11801 | sqlite3expert *p, |
| 11802 | sqlite3_stmt *pIndexXInfo, |
| 11803 | sqlite3_stmt *pWriteStat, |
| 11804 | const char *zTab, |
| 11805 | const char *zIdx, |
| 11806 | char **pzErr |
| 11807 | ){ |
| 11808 | char *zCols = 0; |
| 11809 | char *zOrder = 0; |
| 11810 | char *zQuery = 0; |
| 11811 | int nCol = 0; |
| 11812 | int i; |
| 11813 | sqlite3_stmt *pQuery = 0; |
| 11814 | int *aStat = 0; |
| 11815 | int rc = SQLITE_OK; |
| 11816 | |
| 11817 | assert( p->iSample>0 ); |
| 11818 | |
| 11819 | /* Formulate the query text */ |
| 11820 | sqlite3_bind_text(pIndexXInfo, 1, zIdx, -1, SQLITE_STATIC); |
| 11821 | while( SQLITE_OK==rc && SQLITE_ROW==sqlite3_step(pIndexXInfo) ){ |
| 11822 | const char *zComma = zCols==0 ? "" : ", "; |
| 11823 | const char *zName = (const char*)sqlite3_column_text(pIndexXInfo, 0); |
| 11824 | const char *zColl = (const char*)sqlite3_column_text(pIndexXInfo, 1); |
| 11825 | zCols = idxAppendText(&rc, zCols, |
| 11826 | "%sx.%Q IS rem(%d, x.%Q) COLLATE %s", zComma, zName, nCol, zName, zColl |
| 11827 | ); |
| 11828 | zOrder = idxAppendText(&rc, zOrder, "%s%d", zComma, ++nCol); |
| 11829 | } |
| 11830 | sqlite3_reset(pIndexXInfo); |
| 11831 | if( rc==SQLITE_OK ){ |
| 11832 | if( p->iSample==100 ){ |
| 11833 | zQuery = sqlite3_mprintf( |
| 11834 | "SELECT %s FROM %Q x ORDER BY %s", zCols, zTab, zOrder |
| 11835 | ); |
| 11836 | }else{ |
| 11837 | zQuery = sqlite3_mprintf( |
| 11838 | "SELECT %s FROM temp."UNIQUE_TABLE_NAME" x ORDER BY %s", zCols, zOrder |
| 11839 | ); |
| 11840 | } |
| 11841 | } |
| 11842 | sqlite3_free(zCols); |
| 11843 | sqlite3_free(zOrder); |
| 11844 | |
| 11845 | /* Formulate the query text */ |
| 11846 | if( rc==SQLITE_OK ){ |
| 11847 | sqlite3 *dbrem = (p->iSample==100 ? p->db : p->dbv); |
| 11848 | rc = idxPrepareStmt(dbrem, &pQuery, pzErr, zQuery); |
| 11849 | } |
| 11850 | sqlite3_free(zQuery); |
| 11851 | |
| 11852 | if( rc==SQLITE_OK ){ |
| 11853 | aStat = (int*)idxMalloc(&rc, sizeof(int)*(nCol+1)); |
| 11854 | } |
| 11855 | if( rc==SQLITE_OK && SQLITE_ROW==sqlite3_step(pQuery) ){ |
| 11856 | IdxHashEntry *pEntry; |
| 11857 | char *zStat = 0; |
no test coverage detected