I've seen multiple requests for an SQLite-Plugin for Simba. I wrote one.. Should be enough exports for our needs.
I wrote it in such a way that there are no memory allocations other than what SQLite does itself. For you, there's no "Init" or "Free" functions.
Source:
https://github.com/Brandon-T/XIO-SQLitePlugin
Release (Windows & OSX):
https://github.com/Brandon-T/XIO-SQLitePlugin/releases
Example:
Simba Code:
{$loadlib SQLitePlugin}
var
db: SQLite;
res: Integer;
begin
res := db.open('C:/Users/Brandon/Desktop/Contacts.db', $00000002 or $00000004); //readwrite | create
if (res <> 0) then
writeln('Error Creating DB');
db.close();
end.
The data types are fairly simple (Context is the `self` pointer -- You can copy, move, read, do whatever you want -- Do NOT assign to it):
Simba Code:
type SQLiteContextRecord = packed record
context: pointer;
end;
type SQLiteBackupRecord = packed record
context: pointer;
end;
type SQLiteValueRecord = packed record
context: pointer;
end;
type SQLiteStatementRecord = packed record
context: pointer;
end;
type SQLiteBlobRecord = packed record
context: pointer;
end;
type SQLiteRecord = packed record
context: pointer;
end;
and the methods that are exported are:
Simba Code:
function SQLiteContext.aggregate(nBytes: Integer): SQLiteContext;
function SQLiteContext.count(): Integer;
function SQLiteContext.dbHandle(): SQLite;
function SQLiteBackup.finish(): Integer;
function SQLiteBackup.pageCount(): Integer;
function SQLiteBackup.remaining(): Integer;
function SQLiteBackup.step(nPage: Integer): Integer;
function SQLiteValue.blobValue(): SQLiteBlob;
function SQLiteValue.bytesValue(): Integer;
function SQLiteValue.doubleValue(): Double;
function SQLiteValue.intValue(): Integer;
function SQLiteValue.int64Value(): Int64;
function SQLiteValue.textValue(): PChar;
function SQLiteValue.valueType(): Integer;
function SQLiteValue.numericType(): Integer;
function SQLiteStatement.bindBlob(I: Integer; zData: Pointer; nData: Integer; xDel: procedure(ptr: Pointer)): Integer;
function SQLiteStatement.bindBlob64(I: Integer; zData: Pointer; nData: UInt64; xDel: procedure(ptr: Pointer)): Integer;
function SQLiteStatement.bindDouble(I: Integer; rValue: Double): Integer;
function SQLiteStatement.bindInt(I: Integer; iValue: Integer): Integer;
function SQLiteStatement.bindInt64(I: Integer; iValue: Int64): Integer;
function SQLiteStatement.bindNull(I: Integer): Integer;
function SQLiteStatement.bindParameterCount(): Integer;
function SQLiteStatement.bindParameterIndex(name: String): Integer;
function SQLiteStatement.bindParameterName(i: Integer): PChar;
function SQLiteStatement.bindText(I: Integer; zData: String; nData: Integer; xDel: procedure(ptr: Pointer)): Integer;
function SQLiteStatement.bindText64(I: Integer; zData: String; nData: Int64; xDel: procedure(ptr: Pointer); encoding: UInt8): Integer;
function SQLiteStatement.bindValue(I: Integer; value: SQLiteValue): Integer;
function SQLiteStatement.bindZeroBlob(i: Integer; n: Integer): Integer;
function SQLiteStatement.bindZeroBlob64(i: Integer; n: Int64): Integer;
function SQLiteStatement.clearBindings(): Integer;
function SQLiteStatement.columnBlob(iCol: Integer): Pointer;
function SQLiteStatement.columnBytes(iCol: Integer): Integer;
function SQLiteStatement.columnCount(): Integer;
function SQLiteStatement.columnDeclType(N: Integer): PChar;
function SQLiteStatement.columnDouble(iCol: Integer): Double;
function SQLiteStatement.columnInt(iCol: Integer): Integer;
function SQLiteStatement.columnInt64(iCol: Integer): Int64;
function SQLiteStatement.columnName(iCol: Integer): PChar;
function SQLiteStatement.columnText(iCol: Integer): PChar;
function SQLiteStatement.columnType(iCol: Integer): Integer;
function SQLiteStatement.columnValue(iCol: Integer): SQLiteValue;
function SQLiteStatement.dataCount(): Integer;
function SQLiteStatement.finalize(): Integer;
function SQLiteStatement.reset(): Integer;
function SQLiteStatement.step(): Integer;
function SQLiteBlob.bytes(): Integer;
function SQLiteBlob.close(): Integer;
function SQLiteBlob.read(z: Pointer; n: Integer; iOffset: Integer): Integer;
function SQLiteBlob.reopen(iRow: Integer): Integer;
function SQLiteBlob.write(z: Pointer; n: Integer; iOffset: Integer): Integer;
function SQLite.backup(pDestDb: SQLite; zDestDb: String): SQLiteBackup;
function SQLite.changes(): Integer;
function SQLite.close(): Integer;
function SQLite.createFunction(zFunc: String; nArg: Integer; enc: Integer; pCtx: Pointer; xSFunc: procedure(ctx: pointer; i: Integer; value: pointer); xDestroy: procedure(ptr: pointer)): Integer;
function SQLite.cacheFlush(): Integer;
function SQLite.errorCode(): Integer;
function SQLite.errorMessage(): PChar;
function SQLite.errorString(errorCode: Integer): PChar;
function SQLite.exec(sql: String): Integer;
function SQLite.lastInsertedRowId(): Int64;
function SQLite.libVersion(): PChar;
function SQLite.libVersionNumber(): Integer;
function SQLite.open(fileName: String; flags: Integer): Integer;
function SQLite.prepare(sql: String; nBytes: Integer; var statement: SQLiteStatement): Integer;
P.S. I'd export all the constants and enums but Simba has problems with those OR I'm doing it wrong..