Fossil SCM
Earlier refactoring broke the new array-based setting method: got a little too clever with my use of DB handles.
Commit
3bcf3abd56df7e0ddd00aee06fe5d2299d9752e5fc4ffb18337b2abe18f53bd2
Parent
c625c259a13b9b7…
1 file changed
+6
-5
M
src/db.c
+6
-5
| --- src/db.c | ||
| +++ src/db.c | ||
| @@ -4518,23 +4518,24 @@ | ||
| 4518 | 4518 | /* |
| 4519 | 4519 | ** Serializes the passed array as a JSON array of strings. |
| 4520 | 4520 | */ |
| 4521 | 4521 | const char* json_serialize_array(char* const azValues[], size_t nValues){ |
| 4522 | 4522 | Stmt q; |
| 4523 | - sqlite3* db; | |
| 4524 | - sqlite3_open(":memory:", &db); | |
| 4525 | - sqlite3_carray_init(db, 0, 0); | |
| 4523 | + sqlite3 *old_g_db = g.db; | |
| 4524 | + sqlite3_open(":memory:", &g.db); | |
| 4525 | + sqlite3_carray_init(g.db, 0, 0); | |
| 4526 | 4526 | db_prepare(&q, "SELECT json_group_array(value) FROM carray(?1)"); |
| 4527 | 4527 | if( sqlite3_carray_bind(q.pStmt, 1, (void*)azValues, nValues, CARRAY_TEXT, |
| 4528 | 4528 | SQLITE_STATIC)!= SQLITE_OK){ |
| 4529 | 4529 | fossil_fatal("Could not bind argv array for JSON: %s\n", |
| 4530 | - sqlite3_errmsg(db)); | |
| 4530 | + sqlite3_errmsg(g.db)); | |
| 4531 | 4531 | } |
| 4532 | 4532 | if( db_step(&q)==SQLITE_ROW ){ |
| 4533 | 4533 | const char* ret = fossil_strdup(db_column_text(&q, 0)); |
| 4534 | 4534 | db_finalize(&q); |
| 4535 | - sqlite3_close(db); | |
| 4535 | + sqlite3_close(g.db); | |
| 4536 | + g.db = old_g_db; | |
| 4536 | 4537 | return ret; |
| 4537 | 4538 | }else{ |
| 4538 | 4539 | fossil_fatal("SQLite error: %s", sqlite3_errmsg(g.db)); |
| 4539 | 4540 | } |
| 4540 | 4541 | } |
| 4541 | 4542 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -4518,23 +4518,24 @@ | |
| 4518 | /* |
| 4519 | ** Serializes the passed array as a JSON array of strings. |
| 4520 | */ |
| 4521 | const char* json_serialize_array(char* const azValues[], size_t nValues){ |
| 4522 | Stmt q; |
| 4523 | sqlite3* db; |
| 4524 | sqlite3_open(":memory:", &db); |
| 4525 | sqlite3_carray_init(db, 0, 0); |
| 4526 | db_prepare(&q, "SELECT json_group_array(value) FROM carray(?1)"); |
| 4527 | if( sqlite3_carray_bind(q.pStmt, 1, (void*)azValues, nValues, CARRAY_TEXT, |
| 4528 | SQLITE_STATIC)!= SQLITE_OK){ |
| 4529 | fossil_fatal("Could not bind argv array for JSON: %s\n", |
| 4530 | sqlite3_errmsg(db)); |
| 4531 | } |
| 4532 | if( db_step(&q)==SQLITE_ROW ){ |
| 4533 | const char* ret = fossil_strdup(db_column_text(&q, 0)); |
| 4534 | db_finalize(&q); |
| 4535 | sqlite3_close(db); |
| 4536 | return ret; |
| 4537 | }else{ |
| 4538 | fossil_fatal("SQLite error: %s", sqlite3_errmsg(g.db)); |
| 4539 | } |
| 4540 | } |
| 4541 |
| --- src/db.c | |
| +++ src/db.c | |
| @@ -4518,23 +4518,24 @@ | |
| 4518 | /* |
| 4519 | ** Serializes the passed array as a JSON array of strings. |
| 4520 | */ |
| 4521 | const char* json_serialize_array(char* const azValues[], size_t nValues){ |
| 4522 | Stmt q; |
| 4523 | sqlite3 *old_g_db = g.db; |
| 4524 | sqlite3_open(":memory:", &g.db); |
| 4525 | sqlite3_carray_init(g.db, 0, 0); |
| 4526 | db_prepare(&q, "SELECT json_group_array(value) FROM carray(?1)"); |
| 4527 | if( sqlite3_carray_bind(q.pStmt, 1, (void*)azValues, nValues, CARRAY_TEXT, |
| 4528 | SQLITE_STATIC)!= SQLITE_OK){ |
| 4529 | fossil_fatal("Could not bind argv array for JSON: %s\n", |
| 4530 | sqlite3_errmsg(g.db)); |
| 4531 | } |
| 4532 | if( db_step(&q)==SQLITE_ROW ){ |
| 4533 | const char* ret = fossil_strdup(db_column_text(&q, 0)); |
| 4534 | db_finalize(&q); |
| 4535 | sqlite3_close(g.db); |
| 4536 | g.db = old_g_db; |
| 4537 | return ret; |
| 4538 | }else{ |
| 4539 | fossil_fatal("SQLite error: %s", sqlite3_errmsg(g.db)); |
| 4540 | } |
| 4541 | } |
| 4542 |