Fossil

Diff
Login

Differences From Artifact [c0a24c5b2d]:

To Artifact [f83da5d476]:


3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
  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){
  Stmt q;
  db_assert_protection_off_or_not_sensitive(zName);
  db_unprotect(PROTECT_CONFIG);
  db_begin_transaction();
  if( globalFlag ){
    db_swap_connections();
    sqlite3_carray_init(g.db, 0, 0);      /* not registered globally on purpose */
    db_prepare(&q, "REPLACE INTO global_config(name,value) VALUES(%Q,"
                     "(SELECT json_group_array(value) FROM carray(?1)))",
                    zName);
    sqlite3_carray_bind(q.pStmt, 1, azValues, nValues, CARRAY_TEXT, SQLITE_STATIC);
    db_exec(&q);
    db_swap_connections();
  }else{
    sqlite3_carray_init(g.db, 0, 0);      /* ditto */
    db_prepare(&q, "REPLACE INTO config(name,value,mtime) VALUES(%Q,"
                     "(SELECT json_group_array(value) FROM carray(?1)),now())",
                    zName);
    sqlite3_carray_bind(q.pStmt, 1, azValues, nValues, CARRAY_TEXT, SQLITE_STATIC);
    db_exec(&q);
  }
  if( globalFlag && g.repositoryOpen ){
    db_multi_exec("DELETE FROM config WHERE name=%Q", zName);
  }
  db_end_transaction(0);
  db_protect_pop();
}
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);







<
<
<
<
|
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







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

4530
4531
4532
4533
4534
4535

4536
4537
4538



4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
/*
** 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;

  sqlite3_open(":memory:", &g.db);
  sqlite3_carray_init(g.db, 0, 0);
  db_prepare(&q, "SELECT json_group_array(value) FROM carray(?1)");
  if( sqlite3_carray_bind(q.pStmt, 1, g.argv+2, g.argc-2, CARRAY_TEXT,
        SQLITE_STATIC)!= SQLITE_OK){
    fossil_fatal("Could not bind argv array: %s\n", sqlite3_errmsg(g.db));

  }
  if( db_step(&q)==SQLITE_ROW ){
    fossil_print("%s\n", db_column_text(&q, 0));



  }else{ 
    fossil_fatal("SQLite error: %s", sqlite3_errmsg(g.db));
  }
  db_finalize(&q);
  sqlite3_close(g.db);
  g.db = 0;
  g.repositoryOpen = 0;
  g.localOpen = 0;
}

/*
** COMMAND: test-without-rowid
**
** Usage: %fossil test-without-rowid FILENAME...
**







>
>
>
>
>
>
>

>
|
|

|

|
>


|
>
>
>



<
<
<
<
<







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...
**