[darwinbuild-changes] [717] branches/PR-7489777/darwinup
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 24 08:03:53 PST 2010
Revision: 717
http://trac.macosforge.org/projects/darwinbuild/changeset/717
Author: wsiegrist at apple.com
Date: 2010-02-24 08:03:53 -0800 (Wed, 24 Feb 2010)
Log Message:
-----------
Use macros to make schema creation easier
Modified Paths:
--------------
branches/PR-7489777/darwinup/DB.cpp
branches/PR-7489777/darwinup/DB.h
branches/PR-7489777/darwinup/Database.h
Modified: branches/PR-7489777/darwinup/DB.cpp
===================================================================
--- branches/PR-7489777/darwinup/DB.cpp 2010-02-24 03:39:58 UTC (rev 716)
+++ branches/PR-7489777/darwinup/DB.cpp 2010-02-24 16:03:53 UTC (rev 717)
@@ -45,29 +45,25 @@
}
void DarwinupDatabase::init_schema() {
- // XXX: use macros to make this cleaner
-
this->m_archives_table = new Table("archives");
- // index pk unique
- assert(m_archives_table->add_column(new Column("serial", TYPE_INTEGER, false, true, false))==0);
- assert(m_archives_table->add_column(new Column("uuid", TYPE_BLOB, true, false, true))==0);
- assert(m_archives_table->add_column(new Column("name", TYPE_TEXT))==0);
- assert(m_archives_table->add_column(new Column("date_added", TYPE_INTEGER))==0);
- assert(m_archives_table->add_column(new Column("active", TYPE_INTEGER))==0);
- assert(m_archives_table->add_column(new Column("info", TYPE_INTEGER))==0);
+ ADD_PK(m_archives_table, "serial");
+ ADD_INDEX(m_archives_table, "uuid", TYPE_BLOB, true);
+ ADD_TEXT(m_archives_table, "name");
+ ADD_INTEGER(m_archives_table, "date_added");
+ ADD_INTEGER(m_archives_table, "active");
+ ADD_INTEGER(m_archives_table, "info");
assert(this->add_table(this->m_archives_table)==0);
this->m_files_table = new Table("files");
- // index pk unique
- assert(m_files_table->add_column(new Column("serial", TYPE_INTEGER, false, true, false))==0);
- assert(m_files_table->add_column(new Column("archive", TYPE_INTEGER))==0);
- assert(m_files_table->add_column(new Column("info", TYPE_INTEGER))==0);
- assert(m_files_table->add_column(new Column("mode", TYPE_INTEGER))==0);
- assert(m_files_table->add_column(new Column("uid", TYPE_INTEGER))==0);
- assert(m_files_table->add_column(new Column("gid", TYPE_INTEGER))==0);
- assert(m_files_table->add_column(new Column("size", TYPE_INTEGER))==0);
- assert(m_files_table->add_column(new Column("digest", TYPE_BLOB))==0);
- assert(m_files_table->add_column(new Column("path", TYPE_TEXT, true, false, false))==0);
+ ADD_PK(m_files_table, "serial");
+ ADD_INTEGER(m_files_table, "archive");
+ ADD_INTEGER(m_files_table, "info");
+ ADD_INTEGER(m_files_table, "mode");
+ ADD_INTEGER(m_files_table, "uid");
+ ADD_INTEGER(m_files_table, "gid");
+ ADD_INTEGER(m_files_table, "size");
+ ADD_BLOB(m_files_table, "digest");
+ ADD_INDEX(m_files_table, "path", TYPE_TEXT, false);
assert(this->add_table(this->m_files_table)==0);
}
Modified: branches/PR-7489777/darwinup/DB.h
===================================================================
--- branches/PR-7489777/darwinup/DB.h 2010-02-24 03:39:58 UTC (rev 716)
+++ branches/PR-7489777/darwinup/DB.h 2010-02-24 16:03:53 UTC (rev 717)
@@ -37,6 +37,7 @@
#include <assert.h>
#include <uuid/uuid.h>
#include <time.h>
+
#include "Database.h"
#include "Table.h"
#include "Archive.h"
Modified: branches/PR-7489777/darwinup/Database.h
===================================================================
--- branches/PR-7489777/darwinup/Database.h 2010-02-24 03:39:58 UTC (rev 716)
+++ branches/PR-7489777/darwinup/Database.h 2010-02-24 16:03:53 UTC (rev 717)
@@ -64,9 +64,20 @@
#define FOUND(x) ((x & DB_FOUND) && !(x & DB_ERROR))
+// Schema creation macros
+#define ADD_COLUMN(table, name, type, index, pk, unique) \
+ assert(table->add_column(new Column(name, type, index, pk, unique))==0);
+#define ADD_INDEX(table, name, type, unique) \
+ assert(table->add_column(new Column(name, type, true, false, unique))==0);
+#define ADD_PK(table, name) \
+ assert(table->add_column(new Column(name, TYPE_INTEGER, false, true, false))==0);
+#define ADD_TEXT(table, name) \
+ assert(table->add_column(new Column(name, TYPE_TEXT))==0);
+#define ADD_INTEGER(table, name) \
+ assert(table->add_column(new Column(name, TYPE_INTEGER))==0);
+#define ADD_BLOB(table, name) \
+ assert(table->add_column(new Column(name, TYPE_BLOB))==0);
-
-
// libcache callbacks
bool cache_key_is_equal(void* key1, void* key2, void* user);
void cache_key_retain(void* key_in, void** key_out, void* user_data);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20100224/df11b3dd/attachment.html>
More information about the darwinbuild-changes
mailing list