[darwinbuild-changes] [727] branches/PR-7489777/darwinup
source_changes at macosforge.org
source_changes at macosforge.org
Mon Mar 1 17:24:52 PST 2010
Revision: 727
http://trac.macosforge.org/projects/darwinbuild/changeset/727
Author: wsiegrist at apple.com
Date: 2010-03-01 17:24:51 -0800 (Mon, 01 Mar 2010)
Log Message:
-----------
Fix table creation to execute the CREATE INDEX queries by changing Table::create() to return a string so Database can use sqlite3_exec on it. Add an index on files.archive to speed up preceding/superceding file queries.
Modified Paths:
--------------
branches/PR-7489777/darwinup/DB.cpp
branches/PR-7489777/darwinup/Database.cpp
branches/PR-7489777/darwinup/Depot.cpp
branches/PR-7489777/darwinup/Table.cpp
branches/PR-7489777/darwinup/Table.h
Modified: branches/PR-7489777/darwinup/DB.cpp
===================================================================
--- branches/PR-7489777/darwinup/DB.cpp 2010-03-01 23:16:58 UTC (rev 726)
+++ branches/PR-7489777/darwinup/DB.cpp 2010-03-02 01:24:51 UTC (rev 727)
@@ -56,7 +56,7 @@
this->m_files_table = new Table("files");
ADD_PK(m_files_table, "serial");
- ADD_INTEGER(m_files_table, "archive");
+ ADD_INDEX(m_files_table, "archive", TYPE_INTEGER, false);
ADD_INTEGER(m_files_table, "info");
ADD_INTEGER(m_files_table, "mode");
ADD_INTEGER(m_files_table, "uid");
Modified: branches/PR-7489777/darwinup/Database.cpp
===================================================================
--- branches/PR-7489777/darwinup/Database.cpp 2010-03-01 23:16:58 UTC (rev 726)
+++ branches/PR-7489777/darwinup/Database.cpp 2010-03-02 01:24:51 UTC (rev 727)
@@ -574,7 +574,7 @@
int Database::create_tables() {
int res = SQLITE_OK;
for (uint32_t i=0; i<m_table_count; i++) {
- res = this->execute(m_tables[i]->create(this->m_db));
+ this->sql_once(m_tables[i]->create());
if (res!=SQLITE_OK) {
fprintf(stderr, "Error: sql error trying to create table: %s: %s\n",
m_tables[i]->name(), m_error);
Modified: branches/PR-7489777/darwinup/Depot.cpp
===================================================================
--- branches/PR-7489777/darwinup/Depot.cpp 2010-03-01 23:16:58 UTC (rev 726)
+++ branches/PR-7489777/darwinup/Depot.cpp 2010-03-02 01:24:51 UTC (rev 727)
@@ -1017,6 +1017,7 @@
return res;
}
+// XXX: cache what files we have seen in memory so we do not have to query db
int Depot::has_file(Archive* archive, File* file) {
// check for the destination prefix in file's path, remove if found
char *path, *relpath;
Modified: branches/PR-7489777/darwinup/Table.cpp
===================================================================
--- branches/PR-7489777/darwinup/Table.cpp 2010-03-01 23:16:58 UTC (rev 726)
+++ branches/PR-7489777/darwinup/Table.cpp 2010-03-02 01:24:51 UTC (rev 727)
@@ -155,54 +155,6 @@
return 0;
}
-sqlite3_stmt* Table::create(sqlite3* db) {
- size_t size = 0;
- if (!m_create_sql) {
- uint32_t i = 0;
-
- // size of "create table ( );" plus table name, plus 1 for each column to separate
- size = strlen(m_name) + 22 + m_column_count;
- for (i=0; i<m_column_count; i++) {
- // size for column spec
- size += strlen(m_columns[i]->create());
- // size for create index query
- size += 26 + 2*strlen(m_columns[i]->name()) + 2*strlen(m_name);
- }
-
- // create creation sql
- m_create_sql = (char*)malloc(size);
- strlcpy(m_create_sql, "CREATE TABLE ", size);
- strlcat(m_create_sql, m_name, size);
- strlcat(m_create_sql, " (", size);
- // get creation sql for each column
- for (i=0; i<m_column_count; i++) {
- if (i) strlcat(m_create_sql, ", ", size); // comma separate after 0th column
- strlcat(m_create_sql, m_columns[i]->create(), size);
- }
- strlcat(m_create_sql, "); ", size);
-
- for (i=0; i<m_column_count; i++) {
- if (m_columns[i]->is_index()) {
- char* buf;
- asprintf(&buf, "CREATE INDEX %s_%s ON %s (%s);",
- m_name, m_columns[i]->name(), m_name, m_columns[i]->name());
- strlcat(m_create_sql, buf, size);
- free(buf);
- }
- }
- }
-
- sqlite3_stmt* stmt = (sqlite3_stmt*)malloc(sizeof(sqlite3_stmt*));
- int res = sqlite3_prepare_v2(db, m_create_sql, size, &stmt, NULL); \
- if (res != SQLITE_OK) { \
- fprintf(stderr, "Error: unable to prepare CREATE statement: %s\n",
- sqlite3_errmsg(db)); \
- return NULL; \
- }
-
- return stmt;
-}
-
sqlite3_stmt* Table::count(sqlite3* db) {
sqlite3_stmt* stmt = (sqlite3_stmt*)malloc(sizeof(sqlite3_stmt*));
char* query;
@@ -469,6 +421,50 @@
return pps;
}
+const char* Table::create() {
+ size_t size = 0;
+ if (!m_create_sql) {
+ uint32_t i = 0;
+
+ // size of "create table ( );" plus table name, plus 1 for each column to separate
+ size = strlen(m_name) + 22 + m_column_count;
+ for (i=0; i<m_column_count; i++) {
+ // size for column spec
+ size += strlen(m_columns[i]->create());
+ // size for create index query
+ size += 26 + 2*strlen(m_columns[i]->name()) + 2*strlen(m_name);
+ }
+
+ // create creation sql
+ m_create_sql = (char*)malloc(size);
+ strlcpy(m_create_sql, "CREATE TABLE ", size);
+ strlcat(m_create_sql, m_name, size);
+ strlcat(m_create_sql, " (", size);
+ // get creation sql for each column
+ for (i=0; i<m_column_count; i++) {
+ if (i) strlcat(m_create_sql, ", ", size); // comma separate after 0th column
+ strlcat(m_create_sql, m_columns[i]->create(), size);
+ }
+ strlcat(m_create_sql, "); ", size);
+
+ for (i=0; i<m_column_count; i++) {
+ fprintf(stderr, "DEBUG: loop for index: %s %d %s \n",
+ m_name, i, m_columns[i]->name());
+ if (m_columns[i]->is_index()) {
+ char* buf;
+ asprintf(&buf, "CREATE INDEX %s_%s ON %s (%s);",
+ m_name, m_columns[i]->name(), m_name, m_columns[i]->name());
+ strlcat(m_create_sql, buf, size);
+ fprintf(stderr, "DEBUG: latest sql: %s \n", m_create_sql);
+ free(buf);
+ }
+ }
+ }
+ fprintf(stderr, "DEBUG: final sql: %s \n", m_create_sql);
+
+ return (const char*)m_create_sql;
+}
+
int Table::where_va_columns(uint32_t count, char* query, size_t size,
size_t* used, va_list args) {
char tmpstr[256];
Modified: branches/PR-7489777/darwinup/Table.h
===================================================================
--- branches/PR-7489777/darwinup/Table.h 2010-03-01 23:16:58 UTC (rev 726)
+++ branches/PR-7489777/darwinup/Table.h 2010-03-02 01:24:51 UTC (rev 727)
@@ -60,7 +60,6 @@
/**
* sql statement generators (cached on Table)
*/
- sqlite3_stmt* create(sqlite3* db);
sqlite3_stmt* count(sqlite3* db);
sqlite3_stmt* update(sqlite3* db);
sqlite3_stmt* insert(sqlite3* db);
@@ -92,6 +91,8 @@
protected:
+ const char* create();
+
int where_va_columns(uint32_t count, char* query, size_t size,
size_t* used, va_list args);
const Column** columns();
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20100301/40408800/attachment-0001.html>
More information about the darwinbuild-changes
mailing list