Skip to content

Commit

Permalink
add sqlite.init.sql for running pragma on database
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Dec 8, 2015
1 parent 833f6e6 commit eca72a1
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions symmetric-client-clib/inc/common/ParameterConstants.h
Expand Up @@ -94,5 +94,6 @@
#define SYM_PARAMETER_HTTPS_ALLOW_SELF_SIGNED_CERTS "https.allow.self.signed.certs"

#define SYM_PARAMETER_SQLITE_BUSY_TIMEOUT_MS "sqlite.busy.timeout.ms"
#define SYM_PARAMETER_SQLITE_INIT_SQL "sqlite.init.sql"

#endif
Expand Up @@ -27,6 +27,7 @@
#include "db/platform/DatabasePlatform.h"
#include "db/platform/sqlite/SqliteDdlReader.h"
#include "db/sqlite/SqliteSqlTemplate.h"
#include "util/StringArray.h"

#define SYM_SQLITE_DEFAULT_BUSY_TIMEOUT_MS "30000"

Expand Down
2 changes: 1 addition & 1 deletion symmetric-client-clib/inc/model/Node.h
Expand Up @@ -23,7 +23,7 @@

#include <stdlib.h>

#define SYM_VERSION "3.7.27"
#define SYM_VERSION "3.7.27.1"

typedef enum SymNodeStatus {
SYM_NODE_STATUS_DATA_LOAD_NOT_STARTED,
Expand Down
15 changes: 14 additions & 1 deletion symmetric-client-clib/src/db/platform/sqlite/SqlitePlatform.c
Expand Up @@ -49,7 +49,7 @@ SymSqliteSqlTemplate * SymSqlitePlatform_getSqlTemplate(SymSqlitePlatform *this)
void SymSqlitePlatform_destroy(SymDatabasePlatform *super) {
SymLog_info("Closing SQLite database");
SymSqlitePlatform *this = (SymSqlitePlatform *) super;
// sqlite3_close(this->db);
sqlite3_close(this->db);
this->sqlTemplate->destroy(this->sqlTemplate);
// free(super->ddlReader);
free(this);
Expand Down Expand Up @@ -94,5 +94,18 @@ SymSqlitePlatform * SymSqlitePlatform_new(SymSqlitePlatform *this, SymProperties

SymLog_info("Detected database '%s', version '%s'", super->name, super->version);

char *initSql = properties->get(properties, SYM_PARAMETER_SQLITE_INIT_SQL, NULL);
if (SymStringUtils_isNotBlank(initSql)) {
int error, i;
SymLog_debug("Initializing database with '%s'", initSql);
SymStringArray *array = SymStringArray_split(initSql, ";");
for (i = 0; i < array->size; i++) {
char *sql = array->get(array, i);
if (SymStringUtils_isNotBlank(sql)) {
this->sqlTemplate->update(this->sqlTemplate, sql, NULL, NULL, &error);
}
}
}

return this;
}

0 comments on commit eca72a1

Please sign in to comment.