[darwinbuild-changes] [195] trunk/darwinxref
source_changes at macosforge.org
source_changes at macosforge.org
Wed Oct 4 01:57:53 PDT 2006
Revision: 195
http://trac.macosforge.org/projects/darwinbuild/changeset/195
Author: kevin
Date: 2006-10-04 01:57:53 -0700 (Wed, 04 Oct 2006)
Log Message:
-----------
- added support for CFData in the sqlite database
Modified Paths:
--------------
trunk/darwinxref/DBDataStore.c
trunk/darwinxref/DBPlugin.h
trunk/darwinxref/DBTclPlugin.c
Modified: trunk/darwinxref/DBDataStore.c
===================================================================
--- trunk/darwinxref/DBDataStore.c 2005-08-24 04:42:50 UTC (rev 194)
+++ trunk/darwinxref/DBDataStore.c 2006-10-04 08:57:53 UTC (rev 195)
@@ -119,6 +119,27 @@
return str;
}
+CFDataRef SQL_CFDATA(const char* fmt, ...) {
+ int res;
+ CFDataRef data = NULL;
+ sqlite3_stmt* stmt = NULL;
+ va_list args;
+ char* errmsg;
+ va_start(args, fmt);
+ sqlite3* db = _DBPluginGetDataStorePtr();
+ if (db) {
+ char *query = sqlite3_vmprintf(fmt, args);
+ sqlite3_prepare(db, query, -1, &stmt, NULL);
+ res = sqlite3_step(stmt);
+ if (res == SQLITE_ROW) {
+ const void* buf = sqlite3_column_blob(stmt, 0);
+ data = CFDataCreate(NULL, buf, sqlite3_column_bytes(stmt, 0));
+ }
+ sqlite3_finalize(stmt);
+ }
+ return data;
+}
+
static int sqlAddStringToArray(void* pArg, int argc, char **argv, char** columnNames) {
CFMutableArrayRef array = pArg;
CFStringRef str = cfstr(argv[0]);
@@ -295,6 +316,8 @@
res = DBCopyPropArray(build, project, property);
} else if (type == CFDictionaryGetTypeID()) {
res = DBCopyPropDictionary(build, project, property);
+ } else if (type == CFDataGetTypeID()) {
+ res = DBCopyPropData(build, project, property);
}
return res;
}
@@ -315,6 +338,22 @@
return res;
}
+CFDataRef _DBCopyPropData(CFStringRef build, CFStringRef project, CFStringRef property) {
+ char* cbuild = strdup_cfstr(build);
+ char* cproj = strdup_cfstr(project);
+ char* cprop = strdup_cfstr(property);
+ char* sql;
+ if (cproj && *cproj != 0)
+ sql = "SELECT value FROM properties WHERE property=%Q AND build=%Q AND project=%Q";
+ else
+ sql = "SELECT value FROM properties WHERE property=%Q AND build=%Q AND project IS NULL";
+ CFDataRef res = SQL_CFDATA(sql, cprop, cbuild, cproj);
+ free(cproj);
+ free(cprop);
+ free(cbuild);
+ return res;
+}
+
CFArrayRef _DBCopyPropArray(CFStringRef build, CFStringRef project, CFStringRef property) {
char* cbuild = strdup_cfstr(build);
char* cproj = strdup_cfstr(project);
@@ -430,6 +469,10 @@
return (CFStringRef)_DBCopyPropWithInheritance(build, project, property, (void*)_DBCopyPropString);
}
+CFDataRef DBCopyPropData(CFStringRef build, CFStringRef project, CFStringRef property) {
+ return (CFDataRef)_DBCopyPropWithInheritance(build, project, property, (void*)_DBCopyPropData);
+}
+
CFArrayRef DBCopyPropArray(CFStringRef build, CFStringRef project, CFStringRef property) {
return (CFArrayRef)_DBCopyPropWithInheritance(build, project, property, (void*)_DBCopyPropArray);
}
@@ -461,6 +504,8 @@
res = DBSetPropArray(build, project, property, value);
} else if (type == CFDictionaryGetTypeID()) {
res = DBSetPropDictionary(build, project, property, value);
+ } else if (type == CFDataGetTypeID()) {
+ res = DBSetPropData(build, project, property, value);
}
return res;
}
@@ -484,6 +529,39 @@
return 0;
}
+int DBSetPropData(CFStringRef build, CFStringRef project, CFStringRef property, CFDataRef value) {
+ sqlite3* db = _DBPluginGetDataStorePtr();
+ char* cbuild = strdup_cfstr(build);
+ char* cproj = strdup_cfstr(project);
+ char* cprop = strdup_cfstr(property);
+ char* sql = NULL;
+ sqlite3_stmt* stmt = NULL;
+ int i = 1;
+ int res;
+ if (project) {
+ SQL("DELETE FROM properties WHERE build=%Q AND project=%Q AND property=%Q", cbuild, cproj, cprop);
+ sql = "INSERT INTO properties (build,project,property,value) VALUES (?, ?, ?, ?)";
+ } else {
+ SQL("DELETE FROM properties WHERE build=%Q AND project IS NULL AND property=%Q", cbuild, cprop);
+ sql = "INSERT INTO properties (build,property,value) VALUES (?, ?, ?)";
+ }
+
+ sqlite3_prepare(db, sql, -1, &stmt, NULL);
+ sqlite3_bind_text(stmt, i++, cbuild, -1, NULL);
+ if (project) sqlite3_bind_text(stmt, i++, cproj, -1, NULL);
+ sqlite3_bind_text(stmt, i++, cprop, -1, NULL);
+ sqlite3_bind_blob(stmt, i++, CFDataGetBytePtr(value), CFDataGetLength(value), NULL);
+ res = sqlite3_step(stmt);
+ if (res != SQLITE_DONE) fprintf(stderr, "%s:%d result = %d\n", __FILE__, __LINE__, res);
+ sqlite3_finalize(stmt);
+
+ free(cbuild);
+ if (project) free(cproj);
+ free(cprop);
+ return 0;
+}
+
+
int DBSetPropArray(CFStringRef build, CFStringRef project, CFStringRef property, CFArrayRef value) {
char* cbuild = strdup_cfstr(build);
char* cproj = strdup_cfstr(project);
Modified: trunk/darwinxref/DBPlugin.h
===================================================================
--- trunk/darwinxref/DBPlugin.h 2005-08-24 04:42:50 UTC (rev 194)
+++ trunk/darwinxref/DBPlugin.h 2006-10-04 08:57:53 UTC (rev 195)
@@ -139,11 +139,13 @@
CFTypeRef DBCopyProp(CFStringRef build, CFStringRef project, CFStringRef property);
CFStringRef DBCopyPropString(CFStringRef build, CFStringRef project, CFStringRef property);
+CFDataRef DBCopyPropData(CFStringRef build, CFStringRef project, CFStringRef property);
CFArrayRef DBCopyPropArray(CFStringRef build, CFStringRef project, CFStringRef property);
CFDictionaryRef DBCopyPropDictionary(CFStringRef build, CFStringRef project, CFStringRef property);
int DBSetProp(CFStringRef build, CFStringRef project, CFStringRef property, CFTypeRef value);
int DBSetPropString(CFStringRef build, CFStringRef project, CFStringRef property, CFStringRef value);
+int DBSetPropData(CFStringRef build, CFStringRef project, CFStringRef property, CFDataRef value);
int DBSetPropArray(CFStringRef build, CFStringRef project, CFStringRef property, CFArrayRef value);
int DBSetPropDictionary(CFStringRef build, CFStringRef project, CFStringRef property, CFDictionaryRef value);
Modified: trunk/darwinxref/DBTclPlugin.c
===================================================================
--- trunk/darwinxref/DBTclPlugin.c 2005-08-24 04:42:50 UTC (rev 194)
+++ trunk/darwinxref/DBTclPlugin.c 2006-10-04 08:57:53 UTC (rev 195)
@@ -63,6 +63,21 @@
return tcl_result;
}
+Tcl_Obj* tcl_cfdata(CFDataRef cf) {
+ Tcl_Obj* tcl_result = NULL;
+ if (cf) {
+ CFIndex length = CFDataGetLength(cf);
+ unsigned char* buffer = (unsigned char*)Tcl_Alloc(length);
+ if (buffer) {
+ CFDataGetBytes(cf, CFRangeMake(0, length), (UInt8*)buffer);
+ tcl_result = Tcl_NewByteArrayObj(buffer, length);
+ Tcl_Free((char*)buffer);
+ }
+ }
+ return tcl_result;
+}
+
+
Tcl_Obj* tcl_cfarray(CFArrayRef array) {
Tcl_Obj** objv;
int i, objc = CFArrayGetCount(array);
@@ -132,6 +147,8 @@
DBPlugin* plugin = (DBPlugin*)data;
if (strcmp(type, "string") == 0) {
plugin->datatype = CFStringGetTypeID();
+ } else if (strcmp(type, "data") == 0) {
+ plugin->datatype = CFDataGetTypeID();
} else if (strcmp(type, "array") == 0) {
plugin->datatype = CFArrayGetTypeID();
} else if (strcmp(type, "dictionary") == 0) {
@@ -184,7 +201,24 @@
return TCL_OK;
}
+int DBCopyPropDataCmd(ClientData data, Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]) {
+ if (objc != 4) {
+ Tcl_WrongNumArgs(interp, 1, objv, "build project property");
+ return TCL_ERROR;
+ }
+ CFStringRef build = cfstr_tcl(objv[1]);
+ CFStringRef project = cfstr_tcl(objv[2]);
+ CFStringRef property = cfstr_tcl(objv[3]);
+ CFDataRef res = DBCopyPropData(build, project, property);
+ if (data) {
+ Tcl_SetObjResult(interp, tcl_cfdata(res));
+ CFRelease(res);
+ }
+ return TCL_OK;
+}
+
+
int DBSetPropArrayCmd(ClientData data, Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]) {
if (objc != 5) {
Tcl_WrongNumArgs(interp, 1, objv, "build project property list");
@@ -287,6 +321,7 @@
Tcl_CreateObjCommand(interp, "DBGetCurrentBuild", DBGetCurrentBuildCmd, (ClientData)plugin, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "DBSetPropString", DBSetPropStringCmd, (ClientData)plugin, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "DBCopyPropString", DBCopyPropStringCmd, (ClientData)plugin, (Tcl_CmdDeleteProc *)NULL);
+ Tcl_CreateObjCommand(interp, "DBCopyPropData", DBCopyPropDataCmd, (ClientData)plugin, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "DBSetPropArray", DBSetPropArrayCmd, (ClientData)plugin, (Tcl_CmdDeleteProc *)NULL);
Tcl_CreateObjCommand(interp, "DBCopyPropArray", DBCopyPropArrayCmd, (ClientData)plugin, (Tcl_CmdDeleteProc *)NULL);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20061004/b95b0b63/attachment.html
More information about the darwinbuild-changes
mailing list