[darwinbuild-changes] [762] branches/PR-7593824/darwinup
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 10 16:49:57 PST 2010
Revision: 762
http://trac.macosforge.org/projects/darwinbuild/changeset/762
Author: wsiegrist at apple.com
Date: 2010-03-10 16:49:56 -0800 (Wed, 10 Mar 2010)
Log Message:
-----------
Make schema upgrades work
Modified Paths:
--------------
branches/PR-7593824/darwinup/Database.cpp
branches/PR-7593824/darwinup/Database.h
Modified: branches/PR-7593824/darwinup/Database.cpp
===================================================================
--- branches/PR-7593824/darwinup/Database.cpp 2010-03-10 23:59:23 UTC (rev 761)
+++ branches/PR-7593824/darwinup/Database.cpp 2010-03-11 00:49:56 UTC (rev 762)
@@ -143,9 +143,12 @@
assert(this->create_tables() == 0);
assert(this->set_schema_version(this->m_schema_version) == 0);
} else {
- // not empty, but upgrade schema if needed
- uint32_t version = this->get_schema_version();
- IF_DEBUG("Connected to db and found version = %u \n", version);
+ // test schema versions
+ uint32_t version = 0;
+ if (this->has_information_table()) {
+ version = this->get_schema_version();
+ }
+
if (version < this->m_schema_version) {
IF_DEBUG("Upgrading schema from %u to %u \n", version, this->m_schema_version);
assert(this->upgrade_schema(version) == 0);
@@ -742,15 +745,37 @@
}
int Database::update_information_value(const char* variable, const char* value) {
- return this->update_value("update_information_value",
- this->m_information_table,
- this->m_information_table->column(2), // value
- (void**)&value,
- 1,
- this->m_information_table->column(1), // variable
- '=', variable);
+ int res = SQLITE_OK;
+ uint64_t* c;
+ res = this->count("count_info_var",
+ (void**)&c,
+ this->m_information_table,
+ 1,
+ this->m_information_table->column(1), // variable
+ '=', variable);
+
+ if (*c > 0) {
+ res = this->update_value("update_information_value",
+ this->m_information_table,
+ this->m_information_table->column(2), // value
+ (void**)&value,
+ 1,
+ this->m_information_table->column(1), // variable
+ '=', variable);
+ } else {
+ res = this->insert(m_information_table, variable, value);
+ }
+
+ return res;
}
+bool Database::has_information_table() {
+ int res = sqlite3_exec(this->m_db,
+ "SELECT count(*) FROM database_information;",
+ NULL, NULL, NULL);
+ return res == SQLITE_OK;
+}
+
uint32_t Database::get_schema_version() {
int res = SQLITE_OK;
char** vertxt = NULL;
@@ -767,6 +792,7 @@
}
int Database::set_schema_version(uint32_t version) {
+ IF_DEBUG("set_schema_version %u \n", version);
int res = DB_OK;
char* vertxt;
asprintf(&vertxt, "%u", version);
Modified: branches/PR-7593824/darwinup/Database.h
===================================================================
--- branches/PR-7593824/darwinup/Database.h 2010-03-10 23:59:23 UTC (rev 761)
+++ branches/PR-7593824/darwinup/Database.h 2010-03-11 00:49:56 UTC (rev 762)
@@ -191,8 +191,9 @@
int update_information_value(const char* variable, const char* value);
// get and set version info in actual database
+ bool has_information_table();
+ uint32_t get_schema_version();
int set_schema_version(uint32_t version);
- uint32_t get_schema_version();
// execute query with printf-style format, does not cache statement
int sql_once(const char* fmt, ...);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20100310/627cf9b6/attachment-0001.html>
More information about the darwinbuild-changes
mailing list