#include "ffi.h"
#undef uint
-static void UnusedFunction()
+__attribute__((unused)) static void UnusedFunction()
{
int a;
a.OnGetString(0,0,0);
extern int __ecereVMethodID_class_OnFree;
private:
-int CollationCompare(Class type, int count1, void * data1, int count2, void * data2)
+static SerialBuffer collationBuffer1 { };
+static SerialBuffer collationBuffer2 { };
+static char storage1[512];
+static char storage2[512];
+
+int CollationCompare(Class type, int count1, const void * data1, int count2, const void * data2)
{
if(type.type == normalClass || type.type == noHeadClass)
{
Instance inst1, inst2;
int result;
- SerialBuffer buffer1 { size = count1, count = count1, buffer = data1 };
- SerialBuffer buffer2 { size = count2, count = count2, buffer = data2 };
+ SerialBuffer buffer1 { size = count1, count = count1, buffer = (byte *)data1 };
+ SerialBuffer buffer2 { size = count2, count = count2, buffer = (byte *)data2 };
((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnUnserialize])(type, &inst1, buffer1);
((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnUnserialize])(type, &inst2, buffer2);
- result = ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, inst1, inst2);
+ result = ((int (*)(void *, const void *, const void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, inst1, inst2);
buffer1.buffer = null;
buffer2.buffer = null;
{
void * inst1, * inst2;
int result;
- SerialBuffer buffer1 { size = count1, count = count1, buffer = data1 };
- SerialBuffer buffer2 { size = count2, count = count2, buffer = data2 };
-
- inst1 = new0 byte[type.structSize];
- inst2 = new0 byte[type.structSize];
+ //SerialBuffer buffer1 { size = count1, count = count1, buffer = (byte *)data1 };
+ //SerialBuffer buffer2 { size = count2, count = count2, buffer = (byte *)data2 };
+
+ SerialBuffer buffer1 = collationBuffer1;
+ SerialBuffer buffer2 = collationBuffer2;
+ buffer1.buffer = (byte*)data1;
+ buffer1.size = count1;
+ buffer1.count = count1;
+ buffer1.pos = 0;
+ buffer2.buffer = (byte*)data2;
+ buffer2.size = count2;
+ buffer2.count = count2;
+ buffer2.pos = 0;
+
+ if(type.structSize > 512)
+ {
+ inst1 = new0 byte[type.structSize];
+ inst2 = new0 byte[type.structSize];
+ }
+ else
+ {
+ inst1 = storage1;
+ inst2 = storage2;
+ }
((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnUnserialize])(type, inst1, buffer1);
((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnUnserialize])(type, inst2, buffer2);
buffer1.buffer = null;
buffer2.buffer = null;
- delete buffer1;
- delete buffer2;
- delete inst1;
- delete inst2;
+ //delete buffer1;
+ //delete buffer2;
+ if(type.structSize > 512)
+ {
+ delete inst1;
+ delete inst2;
+ }
return result;
}
else
- return ((int (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, data1, data2);
+ return ((int (*)(void *, const void *, const void *))(void *)type._vTbl[__ecereVMethodID_class_OnCompare])(type, data1, data2);
}
public class SQLiteStaticLink { } // Until .imp generation is fixed
{
bool success = true;
char command[1024];
+
+ sqlite3_exec(db, "PRAGMA page_size=4096;", null, null, null);
+
sprintf(command, "CREATE TABLE eda_table_fields(Table_Name TEXT, Name TEXT, Type TEXT, Length INT);");
sqlite3_exec(db, command, null, null, null);
delete name;
}
- String GetName()
+ const String GetName()
{
return name;
}
class SQLiteDatabase : Database
{
sqlite3 * db;
- AVLTree<String> collations { };
+ AVLTree<const String> collations { };
~SQLiteDatabase()
{
sqlite3_exec(db, "PRAGMA locking_mode=normal", null, null, null);
+ // "Simply setting the locking-mode to NORMAL is not enough - locks are not released until the next time the database file is accessed."
+ sqlite3_exec(db, "SELECT COUNT(*) from eda_table_fields", null, null, null);
sqlite3_close(db);
}
Table OpenTable(const String name, OpenOptions options)
{
char command[1024];
- int result;
+ //int result;
int nRows = 0, nCols = 0;
char ** t;
SQLiteTable table = null;
bool addFields = false;
sprintf(command, "SELECT Name FROM eda_table_fields WHERE Table_Name='%s';", name);
- result = sqlite3_get_table(db, command, &t, &nRows, &nCols, null);
+ /*result = */sqlite3_get_table(db, command, &t, &nRows, &nCols, null);
if(!nRows && !nCols)
addFields = true;
sprintf(command, "SELECT sql FROM sqlite_master WHERE type='table' AND name='%s';", name);
nCols = 0, nRows = 0;
- result = sqlite3_get_table(db, command, &t, &nRows, &nCols, null);
+ /*result = */sqlite3_get_table(db, command, &t, &nRows, &nCols, null);
if((nCols || nRows) || options.create)
{
sprintf(command, "INSERT INTO eda_table_fields (Table_Name, Name, Type, Length) VALUES ('%s', '%s', '%s', %d);", name,
fieldName, type.name, 0);
- result = sqlite3_exec(db, command, null, null, null);
+ /*result = */sqlite3_exec(db, command, null, null, null);
{
SQLiteField field { tbl = table, name = CopyString(fieldName), type = type, num = table._fields.count, sqliteType = sqliteType };
sqlite3_stmt * statement;
sprintf(command, "SELECT Name, Type, Length FROM eda_table_fields WHERE Table_Name='%s';", name);
- result = sqlite3_prepare_v2(db, command, -1, &statement, null);
+ /*result = */sqlite3_prepare_v2(db, command, -1, &statement, null);
while(sqlite3_step(statement) != SQLITE_DONE)
{
- char * fieldName = sqlite3_column_text(statement, 0);
- char * typeName = sqlite3_column_text(statement, 1);
+ const char * fieldName = (const char *)sqlite3_column_text(statement, 0);
+ const char * typeName = (const char *)sqlite3_column_text(statement, 1);
int length = sqlite3_column_int(statement, 2);
Class type = null;
int sqliteType = SQLITE_BLOB;
- ((Class)(&type)).OnGetDataFromString(typeName); // TODO: THIS REQUIRES A FIX SOMEWHERE ELSE
+ type.OnGetDataFromString(typeName);
if(type)
{
}
{
- Table * fTable = (Table *)eClass_GetProperty(type, "table");
+ Table * fTable = (Table *)(intptr)eClass_GetProperty(type, "table");
SQLiteField field { tbl = table, name = CopyString(fieldName), type = type, length = length, num = table._fields.count, sqliteType = sqliteType };
incref field;
if(fTable) refTable = *fTable;
return result == SQLITE_OK;
}
- bool CreateCustomFunction(char * name, SQLCustomFunction customFunction)
+ bool CreateCustomFunction(const char * name, SQLCustomFunction customFunction)
{
bool result = false;
Class cfClass = customFunction._class;
{
Class type = null;
bool pointer = false;
- String arg = tokens[c];
+ const String arg = tokens[c];
char * space;
- TrimLSpaces(arg, arg);
+ TrimLSpaces(tokens[c], tokens[c]);
if(strchr(arg, '*')) pointer = true;
if(pointer)
// Using String for generic pointer...
static class FFITypesHolder : Map<Class, String> { ~FFITypesHolder() { Free(); } }
FFITypesHolder structFFITypes { };
+__attribute__((unused)) static Iterator dummy; // TOFIX: forward struct declaration issues on Clang
public ffi_type * FFIGetType(Class type, bool structByValue)
{
if(a == class(String))
{
int numBytes = sqlite3_value_bytes(values[i]);
- char * text = sqlite3_value_text(values[i]);
+ const char * text = (const char *)sqlite3_value_text(values[i]);
*(char **)data = text ? new byte[numBytes+1] : null;
if(text)
memcpy(*(char **)data, text, numBytes+1);
SerialBuffer buffer = staticBuffer; //{ };
buffer.pos = 0;
buffer._size = sqlite3_value_bytes(values[i]);
- buffer._buffer = sqlite3_value_text(values[i]);
+ buffer._buffer = (byte *)sqlite3_value_text(values[i]);
//buffer._buffer = sqlite3_value_blob(curStatement);
buffer.count = buffer._size;
if(a.type == structClass)
{
SerialBuffer buffer { };
((void (*)(void *, void *, void *))(void *)r._vTbl[__ecereVMethodID_class_OnSerialize])(r, data, buffer);
- sqlite3_result_text(context, buffer._buffer, buffer.count, SQLITE_TRANSIENT);
+ sqlite3_result_text(context, (char *)buffer._buffer, buffer.count, SQLITE_TRANSIENT);
delete buffer;
// Avoid destroying Strings for now... (Returning memory owned by the Custom Function)
result = sqlite3_create_collation_v2(db.db, type.fullName, SQLITE_UTF8, type, CollationCompare, null);
}
}
- if(sqliteType != SQLITE_BLOB && eClass_IsDerived(type, class(eda::Id)))
+ if(sqliteType != SQLITE_BLOB && eClass_IsDerived(type, class(eda::Id)) && type != class(eda::Id))
{
- Table * table = (Table *)eClass_GetProperty(type, "table");
+ Table * table = (Table *)(intptr)eClass_GetProperty(type, "table");
if(table) refTable = *table;
if(refTable)
{
if(f.sqliteType != SQLITE_BLOB && eClass_IsDerived(f.type, class(eda::Id)))
{
- Table * tablePtr = (Table *)eClass_GetProperty(f.type, "table");
+ Table * tablePtr = (Table *)(intptr)eClass_GetProperty(f.type, "table");
if(tablePtr && *tablePtr == this)
primaryKey = f;
}
return result == SQLITE_OK;
}
- String GetName()
+ const String GetName()
{
return name;
}
}
else
{
- int bindId = findBindId;
sqlite3_reset((move == next) ? findStatement : lastFindStatement);
sqlite3_reset(curStatement);
curStatement = (move == next) ? findStatement : lastFindStatement;
return true;
}
- bool Query(char * queryString)
+ bool Query(const char * queryString)
{
bool status = true;
int result;
}
}
else
+ {
+ printf("SQLite Query Error: %s\n", queryString);
status = false;
+ }
}
else
curStatement = null;
{
buffer = SerialBuffer { };
((void (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnSerialize])(dataType, data, buffer);
- result = sqlite3_bind_text(statement, pos, buffer._buffer, buffer.count, SQLITE_TRANSIENT);
+ result = sqlite3_bind_text(statement, pos, (char *)buffer._buffer, buffer.count, SQLITE_TRANSIENT);
}
else
result = sqlite3_bind_null(statement, pos);
}
if(type.type == structClass)
{
- data = (int64)new0 byte[type.structSize];
- dataPtr = (void *) data;
+ data = (int64)(intptr)new0 byte[type.structSize];
+ dataPtr = (void *)(intptr)data;
}
// ((bool (*)())(void *)dataRow.GetData)(dataRow, fld, type, (type.type == structClass) ? (void *)data : &data);
- ((bool (*)())(void *)this.GetData)(this, fld, type, (type.type == structClass) ? (void *)data : &data);
+ ((bool (*)())(void *)this.GetData)(this, fld, type, (type.type == structClass) ? (void *)(intptr)data : &data);
if(type.type == normalClass || type.type == noHeadClass)
- dataPtr = (void *) data;
+ dataPtr = (void *)(intptr)data;
else
dataPtr = &data;
((bool (*)())(void *)this.BindData)(this, stmt, (*bindId)++, fld, type, dataPtr, &buffer);
// Reuse the buffer for Blobs...
if(fld.sqliteType == SQLITE_BLOB || fld.sqliteType == SQLITE_NULL)
{
- sqlite3_bind_text(stmt, (*bindId)++, buffer._buffer, buffer.count, SQLITE_TRANSIENT);
+ sqlite3_bind_text(stmt, (*bindId)++, (char *)buffer._buffer, buffer.count, SQLITE_TRANSIENT);
delete buffer;
}
else
result = GoToSysID(*(int *)data);
if(result)
findSysID = true;
- return result;
+ return result != 0;
}
useIndex = tbl.GetIndexOrder(order, false);
case SQLITE_TEXT:
{
int numBytes = sqlite3_column_bytes(curStatement, num);
- char * text = sqlite3_column_text(curStatement, num);
+ const char * text = (const char *)sqlite3_column_text(curStatement, num);
*(char **)data = text ? new byte[numBytes+1] : null;
if(text)
memcpy(*(char **)data, text, numBytes+1);
SerialBuffer buffer { };
//buffer._buffer = sqlite3_column_blob(curStatement, num);
buffer._size = sqlite3_column_bytes(curStatement, num);
- buffer._buffer = sqlite3_column_text(curStatement, num);
+ buffer._buffer = (byte *)sqlite3_column_text(curStatement, num);
buffer.count = buffer._size;
((void (*)(void *, void *, void *))(void *)dataType._vTbl[__ecereVMethodID_class_OnUnserialize])(dataType, data, buffer);
{
SQLiteField sqlFld = (SQLiteField)fld;
int result;
- int num = sqlFld.num + 1;
char command[1024];
if(updateStatement)
sqlite3_finalize(updateStatement);
sprintf(command, "UPDATE `%s` SET `%s` = ? WHERE ROWID = ?;", tbl.name, sqlFld.name);
+ // TODO: Shouldn't we cache those update statements per field?
result = sqlite3_prepare_v2(tbl.db.db, command, -1, &updateStatement, null);
sqlite3_bind_int64(updateStatement, 2, (sqlite3_int64)rowID);
BindData(updateStatement, 1, (SQLiteField)fld, data, null);
return !result;
}
- bool SetQueryParamText(int paramID, char * data)
+ bool SetQueryParamText(int paramID, const char * data)
{
int result;
if(curStatement != queryStatement)
return !result;
}
- bool SetQueryParamObject(int paramID, void * data, Class type)
+ bool SetQueryParamObject(int paramID, const void * data, Class type)
{
int result;
if(curStatement != queryStatement)
sqlite3_reset(queryStatement);
{
SerialBuffer buffer { };
- ((void (*)(void *, void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnSerialize])(type, data, buffer);
- result = sqlite3_bind_text(queryStatement, paramID, buffer._buffer, buffer.count, SQLITE_TRANSIENT);
+ ((void (*)(void *, const void *, void *))(void *)type._vTbl[__ecereVMethodID_class_OnSerialize])(type, data, buffer);
+ result = sqlite3_bind_text(queryStatement, paramID, (char *)buffer._buffer, buffer.count, SQLITE_TRANSIENT);
delete buffer;
}
return !result;
SQLiteField lastFld = tbl._fields.last;
return sqlite3_column_text(curStatement, lastFld.num + 1 + paramID);
}*/
- char * GetColumn(int paramID)
+ const char * GetColumn(int paramID)
{
- return sqlite3_column_text(curStatement, paramID);
+ return (const char *)sqlite3_column_text(curStatement, paramID);
}
}