Index: src/RS-SQLite.c =================================================================== --- src/RS-SQLite.c (revision 330) +++ src/RS-SQLite.c (working copy) @@ -31,7 +31,6 @@ RS_SQLite_bindParam *param); int RS_sqlite_import(sqlite3 *db, const char *zTable, const char *zFile, const char *separator, const char *eol, int skip); -int corrected_sqlite3_step(sqlite3_stmt *pStatement); /* The macro NA_STRING is a CHRSXP in R but a char * in Splus */ #ifdef USING_R @@ -398,11 +397,11 @@ qrylen += strlen(tname) + 1; sqlQuery = (char*) R_alloc(qrylen, sizeof(char)); snprintf(sqlQuery, qrylen, sqlFmt, tname); - rc = sqlite3_prepare(db, sqlQuery, -1, &stmt, &tail); + rc = sqlite3_prepare_v2(db, sqlQuery, -1, &stmt, &tail); if (rc != SQLITE_OK) { error("SQL error: %s\n", sqlite3_errmsg(db)); } - rc = corrected_sqlite3_step(stmt); + rc = sqlite3_step(stmt); ans = sqlite3_column_int(stmt, 0); sqlite3_finalize(stmt); return ans; @@ -434,7 +433,7 @@ snprintf(sqlQuery, sizeof(sqlQuery), "select %s from %s", column_name, table_name); - rc = sqlite3_prepare(db_connection, sqlQuery, strlen(sqlQuery), &stmt, &tail); + rc = sqlite3_prepare_v2(db_connection, sqlQuery, strlen(sqlQuery), &stmt, &tail); /* FIXME: how should we be handling errors? Could either follow the pattern in the rest of the package or start to use the condition system and raise specific conditions. @@ -443,7 +442,7 @@ error("SQL error: %s\n", sqlite3_errmsg(db_connection)); } - rc = corrected_sqlite3_step(stmt); + rc = sqlite3_step(stmt); col_type = sqlite3_column_type(stmt, 0); switch(col_type) { case SQLITE_INTEGER: @@ -481,7 +480,7 @@ mkChar((char*)sqlite3_column_text(stmt, 0))); } i++; - rc = corrected_sqlite3_step(stmt); + rc = sqlite3_step(stmt); } sqlite3_finalize(stmt); UNPROTECT(1); @@ -534,13 +533,10 @@ res->statement = dyn_statement; res->drvResultSet = NULL; - do { - if (db_statement) - sqlite3_finalize(db_statement); - state = sqlite3_prepare(db_connection, dyn_statement, -1, - &db_statement, NULL); + state = sqlite3_prepare_v2(db_connection, dyn_statement, -1, + &db_statement, NULL); - if (state != SQLITE_OK && state != SQLITE_SCHEMA) { + if (state != SQLITE_OK) { sqlite3_finalize(db_statement); res->drvResultSet = (void *)NULL; @@ -553,7 +549,7 @@ RS_DBI_errorMessage(buf, RS_DBI_ERROR); } - if(db_statement == NULL && state != SQLITE_SCHEMA){ + if(db_statement == NULL){ char *message = "nothing to execute"; RS_SQLite_setException(con, 0, message); RS_DBI_freeResultSet(rsHandle); @@ -589,9 +585,8 @@ else { /* if no bind parameters exist, we directly execute the query */ if(bind_count == 0){ - if (state != SQLITE_SCHEMA) { - state = corrected_sqlite3_step(db_statement); - if (state != SQLITE_DONE && state != SQLITE_SCHEMA) { + state = sqlite3_step(db_statement); + if (state != SQLITE_DONE) { char errMsg[2048]; sprintf(errMsg, "RS_SQLite_exec: could not execute1: %s", sqlite3_errmsg(db_connection)); @@ -604,7 +599,6 @@ RS_DBI_freeResultSet(rsHandle); RS_DBI_errorMessage(errMsg, RS_DBI_ERROR); } - } } else { char bindingErrorMsg[2048]; @@ -660,7 +654,7 @@ string, -1, SQLITE_TRANSIENT); break; } - if (state != SQLITE_OK && state != SQLITE_SCHEMA) { + if (state != SQLITE_OK) { char errMsg[2048]; sprintf(errMsg, "RS_SQLite_exec: could not bind data: %s", sqlite3_errmsg(db_connection)); @@ -678,8 +672,8 @@ } /* execute the statement */ - state = corrected_sqlite3_step(db_statement); - if (state != SQLITE_DONE && state != SQLITE_SCHEMA) { + state = sqlite3_step(db_statement); + if (state != SQLITE_DONE) { char errMsg[2048]; sprintf(errMsg, "RS_SQLite_exec: could not execute: %s", sqlite3_errmsg(db_connection)); @@ -696,7 +690,7 @@ /* reset the bind parameters */ state = sqlite3_reset(db_statement); - if (state != SQLITE_OK && state != SQLITE_SCHEMA) { + if (state != SQLITE_OK) { char errMsg[2048]; sprintf(errMsg, "RS_SQLite_exec: could not reset statement: %s", sqlite3_errmsg(db_connection)); @@ -722,7 +716,6 @@ res->rowsAffected = (Sint) sqlite3_changes(db_connection); RS_SQLite_setException(con, state, "OK"); } - } while (state == SQLITE_SCHEMA); return rsHandle; } @@ -957,16 +950,13 @@ { S_EVALUATOR - RS_DBI_connection *con; RS_DBI_resultSet *res; RS_DBI_fields *flds; sqlite3_stmt *db_statement; - sqlite3 *db_connection; s_object *output, *s_tmp; int j, state, expand; Sint num_rec; int num_fields, row_idx; - int done = 0, reprepare = 0; res = RS_DBI_getResultSet(rsHandle); if(res->isSelect != 1){ @@ -984,31 +974,15 @@ RS_DBI_ERROR); } - while (!done) { - if (reprepare) { - con = RS_DBI_getConnection(rsHandle); - db_connection = (sqlite3 *) con->drvConnection; - sqlite3_finalize(db_statement); - res->drvResultSet = (void*)NULL; - state = sqlite3_prepare(db_connection, res->statement, -1, &db_statement, - NULL); - res->drvResultSet = db_statement; - } - state = corrected_sqlite3_step(db_statement); + state = sqlite3_step(db_statement); row_idx = 0; - if (state != SQLITE_ROW && state != SQLITE_DONE && state != SQLITE_SCHEMA) { + if (state != SQLITE_ROW && state != SQLITE_DONE) { char errMsg[2048]; (void)sprintf(errMsg, "RS_SQLite_fetch: failed first step: %s", sqlite3_errmsg(sqlite3_db_handle(db_statement))); RS_DBI_errorMessage(errMsg, RS_DBI_ERROR); } - if (state == SQLITE_SCHEMA) - reprepare = 1; - else { - reprepare = 0; - done = 1; - } - } + if (!res->fields) { if (!(res->fields = RS_SQLite_createDataMappings(rsHandle))) { RS_DBI_errorMessage("corrupt SQLite resultSet, missing fieldDescription", @@ -1079,7 +1053,7 @@ else break; /* okay, no more fetching for now */ } - state = corrected_sqlite3_step(db_statement); + state = sqlite3_step(db_statement); if (state != SQLITE_ROW && state != SQLITE_DONE) { char errMsg[2048]; (void)sprintf(errMsg, "RS_SQLite_fetch: failed: %s", @@ -1150,7 +1124,7 @@ RS_DBI_ERROR); } - state = corrected_sqlite3_step(db_statement); + state = sqlite3_step(db_statement); row_idx = 0; if(state!=SQLITE_ROW && state!=SQLITE_DONE){ char errMsg[2048]; @@ -1232,7 +1206,7 @@ else break; /* okay, no more fetching for now */ } - state = corrected_sqlite3_step(db_statement); + state = sqlite3_step(db_statement); if (state != SQLITE_ROW && state != SQLITE_DONE) { char errMsg[2048]; (void)sprintf(errMsg, "RS_SQLite_fetch: failed: %s", @@ -1624,9 +1598,9 @@ zSql = sqlite3_mprintf("SELECT * FROM '%q'", zTable); if( zSql==0 ) return 0; nByte = strlen(zSql); - rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0); + rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); sqlite3_free(zSql); - if (rc != SQLITE_OK && rc != SQLITE_SCHEMA) { + if (rc != SQLITE_OK) { sqlite3_finalize(pStmt); (void) sprintf(errMsg, "RS_sqlite_import: %s", sqlite3_errmsg(db)); RS_DBI_errorMessage(errMsg, RS_DBI_ERROR); @@ -1646,9 +1620,9 @@ } zSql[j++] = ')'; zSql[j] = 0; - rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0); + rc = sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0); free(zSql); - if (rc != SQLITE_OK && rc != SQLITE_SCHEMA) { + if (rc != SQLITE_OK) { sqlite3_finalize(pStmt); (void) sprintf(errMsg, "RS_sqlite_import: %s", sqlite3_errmsg(db)); RS_DBI_errorMessage(errMsg, RS_DBI_ERROR); @@ -1695,8 +1669,8 @@ } } - rc = corrected_sqlite3_step(pStmt); - if (rc != SQLITE_DONE && rc != SQLITE_SCHEMA) { + rc = sqlite3_step(pStmt); + if (rc != SQLITE_DONE) { sqlite3_finalize(pStmt); (void) sprintf(errMsg, "RS_sqlite_import: %s", sqlite3_errmsg(db)); RS_DBI_errorMessage(errMsg, RS_DBI_ERROR); @@ -1704,7 +1678,7 @@ rc = sqlite3_reset(pStmt); free(zLine); zLine = NULL; - if (rc != SQLITE_OK && rc != SQLITE_SCHEMA) { + if (rc != SQLITE_OK) { sqlite3_finalize(pStmt); (void) sprintf(errMsg,"RS_sqlite_import: %s", sqlite3_errmsg(db)); zCommit = "ROLLBACK"; @@ -1778,13 +1752,3 @@ return buf; } - -/* from http://www.sqlite.org/capi3ref.html#sqlite3_step */ -int corrected_sqlite3_step(sqlite3_stmt *pStatement){ - int rc; - rc = sqlite3_step(pStatement); - if( rc==SQLITE_ERROR ){ - rc = sqlite3_reset(pStatement); - } - return rc; -}