# # # patch "mlsqlite/ocaml-sqlite3.c" # from [aa91300e6fe9da56753089dc45ebb061c5a9f05f] # to [334cf3064dc352cce5fdc44fbbe2f69104eecba9] # # patch "mlsqlite/sqlite3.ml" # from [b0fdf5dd266be78db186bd51e9f15cc789f0954a] # to [30d614086bd175bbfe2d9a284b60cb947906da4c] # ============================================================ --- mlsqlite/ocaml-sqlite3.c aa91300e6fe9da56753089dc45ebb061c5a9f05f +++ mlsqlite/ocaml-sqlite3.c 334cf3064dc352cce5fdc44fbbe2f69104eecba9 @@ -362,26 +362,16 @@ convert_sqlite3_type (int t) /* Prepared statements */ -static int -ml_sqlite3_finalize_stmt (value s, sqlite3 **db) +CAMLprim value +ml_sqlite3_finalize_noerr (value s) { - int status = SQLITE_OK; sqlite3_stmt **p_stmt = (sqlite3_stmt **) Field (s, 0); if (*p_stmt != NULL) { - if (db != NULL) - *db = sqlite3_db_handle (*p_stmt); - status = sqlite3_finalize (*p_stmt); + sqlite3_finalize (*p_stmt); *p_stmt = NULL; } - return status; -} - -CAMLprim value -ml_sqlite3_finalize_noerr (value v) -{ - ml_sqlite3_finalize_stmt (v, NULL); return Val_unit; } @@ -503,6 +493,7 @@ ml_sqlite3_step (value stmt) s = ml_sqlite3_recompile (stmt, s); goto again; } + db = sqlite3_db_handle (s); ml_sqlite3_raise_exn (status, sqlite3_errmsg (db), TRUE); } } ============================================================ --- mlsqlite/sqlite3.ml b0fdf5dd266be78db186bd51e9f15cc789f0954a +++ mlsqlite/sqlite3.ml 30d614086bd175bbfe2d9a284b60cb947906da4c @@ -234,8 +234,8 @@ let _fold_prepare ?(final=false) db sql register_stmt db stmt ; let acc = try f acc stmt - with exn -> - if final then finalize_stmt stmt ; + with exn when final -> + finalize_stmt stmt ; raise exn in if final then finalize_stmt stmt ; loop acc nxt @@ -317,7 +317,12 @@ let rec fold_step f acc stmt = match step stmt with | `DONE -> acc | `ROW -> - fold_step f (f acc stmt) stmt + let acc = + try f acc stmt + with exn -> + reset stmt ; + raise exn in + fold_step f acc stmt let _fetch db sql f init = _fold_prepare