Index: src/allrepo.c ================================================================== --- src/allrepo.c +++ src/allrepo.c @@ -167,10 +167,13 @@ int quiet = 0; int dryRunFlag = 0; int showFile = find_option("showfile",0,0)!=0; int stopOnError = find_option("dontstop",0,0)==0; int rc; + int rowCount, i = 0; + char **azFilename = 0; + char **azTag = 0; int nToDel = 0; int showLabel = 0; dryRunFlag = find_option("dry-run","n",0)!=0; if( !dryRunFlag ){ @@ -345,25 +348,28 @@ " FROM global_config" " WHERE substr(name, 1, 5)=='repo:'" " ORDER BY 1" ); } - db_multi_exec("CREATE TEMP TABLE todel(x TEXT)"); db_prepare(&q, "SELECT name, tag FROM repolist ORDER BY 1"); - while( db_step(&q)==SQLITE_ROW ){ - const char *zFilename = db_column_text(&q, 0); + rowCount = db_all_column_text(&q, 0, &azFilename, 1, &azTag); + db_finalize(&q); + db_multi_exec("CREATE TEMP TABLE todel(x TEXT)"); + while( i0 ){ Index: src/db.c ================================================================== --- src/db.c +++ src/db.c @@ -344,10 +344,72 @@ int rc; rc = sqlite3_step(pStmt->pStmt); pStmt->nStep++; return rc; } + +/* +** Steps the SQL statement until there are no more rows. Returns the +** total number of rows processed by this function. If the pazValue1 +** parameter is non-zero, captures the iCol1'th column value from each +** row (as text) and stores the resulting final array pointer into it. +** If the pazValue2 parameter is non-zero, captures the iCol2'th column +** value from each row (as text) and stores the resulting final array +** pointer into it. The caller of this function is responsible for +** calling the db_all_column_free() function later, passing it the +** result of this function along with the values for both the pazValue1 +** and pazValue2 paramters. +*/ +int db_all_column_text( + Stmt *pStmt, /* The statement handle. */ + int iCol1, /* The first column number to fetch from the results. */ + char ***pazValue1, /* Array of iCol1'th column values from query. */ + int iCol2, /* The second column number to fetch from the results. */ + char ***pazValue2 /* Array of iCol2'th column values from query. */ +){ + int count = 0; + char **azValue1 = 0; + char **azValue2 = 0; + while( db_step(pStmt)==SQLITE_ROW ){ + count++; + if( pazValue1 ){ + azValue1 = fossil_realloc(azValue1, count * sizeof(char*)); + azValue1[count - 1] = fossil_strdup(db_column_text(pStmt, iCol1)); + } + if( pazValue2 ){ + azValue2 = fossil_realloc(azValue2, count * sizeof(char*)); + azValue2[count - 1] = fossil_strdup(db_column_text(pStmt, iCol2)); + } + } + if( pazValue1 ){ + *pazValue1 = azValue1; + } + if( pazValue2 ){ + *pazValue2 = azValue2; + } + return count; +} + +/* +** This function frees all the storage that was allocated by the +** db_all_column_text() function for a particular column. +*/ +void db_all_column_free( + int count, /* Number of string elements in the arrays. */ + char ***pazValue /* Array of column values from query. */ +){ + if( pazValue ){ + char **azValue = *pazValue; + int i; + for(i=0; i