Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
| Comment: | Extracted json_serialize_array() function common to both test-json-carray and settings commands, reducing redundant code. |
|---|---|
| Downloads: | Tarball | ZIP archive |
| Timelines: | family | ancestors | descendants | both | fossil-spawn |
| Files: | files | file ages | folders |
| SHA3-256: |
ead1432af9b5288d1f294ac4b02feae0 |
| User & Date: | wyoung 2021-06-22 03:45:22.026 |
| Original Comment: | Extracted json_serialize_array() function common to both test-json-carray and settings commands, reducing redundant code. No functional change. |
References
|
2021-06-22
| ||
| 08:46 | [ead1432af9 | An earlier refactoring on this branch] broke the new array-based setting method: got a little too clever with my use of DB handles. check-in: 3bcf3abd56 user: wyoung tags: fossil-spawn | |
Context
|
2021-06-22
| ||
| 03:52 | Renamed the test-* wrapper for the new JSON array serializer to better match its internal implementation function. NFC. check-in: 06d27250d5 user: wyoung tags: fossil-spawn | |
| 03:45 | Extracted json_serialize_array() function common to both test-json-carray and settings commands, reducing redundant code. check-in: ead1432af9 user: wyoung tags: fossil-spawn | |
| 02:37 | Taught "fossil settings" how to accept multiple ?VALUES? parameters, storing the result as a JSON-encoded array in the config table. Nothing uses this yet, but the resulting SQL DB manipulation appears to work correctly. check-in: ca069402f8 user: wyoung tags: fossil-spawn | |
Changes
Changes to src/db.c.
| ︙ | ︙ | |||
3218 3219 3220 3221 3222 3223 3224 |
if( globalFlag && g.repositoryOpen ){
db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
}
db_end_transaction(0);
db_protect_pop();
}
void db_set_array(const char *zName, char* azValues[], size_t nValues, int globalFlag){
| < < < < | < < < < < < < < < < < < < < < < < < < < < | 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 |
if( globalFlag && g.repositoryOpen ){
db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
}
db_end_transaction(0);
db_protect_pop();
}
void db_set_array(const char *zName, char* azValues[], size_t nValues, int globalFlag){
db_set(zName, json_serialize_array(azValues, nValues), globalFlag);
}
void db_unset(const char *zName, int globalFlag){
db_begin_transaction();
db_unprotect(PROTECT_CONFIG);
if( globalFlag ){
db_swap_connections();
db_multi_exec("DELETE FROM global_config WHERE name=%Q", zName);
|
| ︙ | ︙ | |||
4522 4523 4524 4525 4526 4527 4528 4529 |
/*
** COMMAND: test-json-carray
**
** Serializes the passed arguments as a JSON array of strings, proving that
** the JSON1 and Carray SQLite extensions are cooperating.
*/
void test_json_carray_cmd(void){
Stmt q;
| > > > > > > > > | | | | > | > > > < < < < < | 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 |
/*
** COMMAND: test-json-carray
**
** Serializes the passed arguments as a JSON array of strings, proving that
** the JSON1 and Carray SQLite extensions are cooperating.
*/
void test_json_carray_cmd(void){
fossil_print("%s\n", json_serialize_array(g.argv+2, g.argc-2));
}
/*
** Serializes the passed array as a JSON array of strings.
*/
const char* json_serialize_array(char* const azValues[], size_t nValues){
Stmt q;
sqlite3* db;
sqlite3_open(":memory:", &db);
sqlite3_carray_init(db, 0, 0);
db_prepare(&q, "SELECT json_group_array(value) FROM carray(?1)");
if( sqlite3_carray_bind(q.pStmt, 1, (void*)azValues, nValues, CARRAY_TEXT,
SQLITE_STATIC)!= SQLITE_OK){
fossil_fatal("Could not bind argv array for JSON: %s\n",
sqlite3_errmsg(db));
}
if( db_step(&q)==SQLITE_ROW ){
const char* ret = fossil_strdup(db_column_text(&q, 0));
db_finalize(&q);
sqlite3_close(db);
return ret;
}else{
fossil_fatal("SQLite error: %s", sqlite3_errmsg(g.db));
}
}
/*
** COMMAND: test-without-rowid
**
** Usage: %fossil test-without-rowid FILENAME...
**
|
| ︙ | ︙ |