Cool
But so work with Window, Linux, MacOS and x86,x64
Code: Select all
ImportC ""
sqlite3_create_function.i(DatabaseID, zFunctionName.p-utf8, nArg.i, eTextRep.i, *pApp, *xFunc, *xStep, *xFinal)
sqlite3_aggregate_context(*sqlite3_context, nBytes.i)
sqlite3_result_double(*sqlite3_context, dbl.d)
sqlite3_result_text(*sqlite3_context, *returnvalue, nBytes.i, *nParam)
sqlite3_value_numeric_type.i(*sqlite3_value)
sqlite3_value_double.d(*sqlite3_value)
sqlite3_value_int.i(*sqlite3_value)
sqlite3_value_type.i(*argv)
;Neue Funktionen
sqlite3_backup_init(pDest, zDestName.p-ascii, pSource, zSourceName.p-ascii)
sqlite3_backup_step(sqlite3_backup, nPage)
sqlite3_backup_finish(sqlite3_backup)
sqlite3_errcode(db)
EndImport
#SQLITE_UTF8 = 1 ; IMP: R-37514-35566
#SQLITE_UTF16LE = 2 ; IMP: R-03371-37637
#SQLITE_UTF16BE = 3 ; IMP: R-51971-34154
#SQLITE_UTF16 = 4 ; Use native byte order
#SQLITE_ANY = 5 ; Deprecated
#SQLITE_UTF16_ALIGNED = 8 ; sqlite3_create_collation only
#SQLITE_INTEGER = 1
#SQLITE_FLOAT = 2
#SQLITE_TEXT = 3
#SQLITE_BLOB = 4
#SQLITE_NULL = 5
#SQLITE_STATIC = 0
#SQLITE_TRANSIENT = -1
ProcedureC TypeOfFunc(*context, argc.i, *argv.integer)
Protected *Buffer
Select sqlite3_value_type(*argv\i)
Case #SQLITE_NULL
*Buffer = UTF8("null")
Case #SQLITE_INTEGER
*Buffer = UTF8("integer")
Case #SQLITE_TEXT
*Buffer = UTF8("text")
Case #SQLITE_FLOAT
*Buffer = UTF8("real")
Case #SQLITE_BLOB
*Buffer = UTF8("blob")
EndSelect
sqlite3_result_text(*context, *Buffer, -1, #SQLITE_TRANSIENT)
If *Buffer
FreeMemory(*Buffer)
EndIf
EndProcedure
Procedure RegisterSQLiteFunctions(dataBase.i)
Protected dataBaseID.i
dataBaseID = DatabaseID(dataBase)
sqlite3_create_function(dataBaseID, "typeofcol", 1, #SQLITE_UTF8, #Null, @TypeofFunc(), #Null, #Null)
EndProcedure
UseSQLiteDatabase()
DB = OpenDatabase(#PB_Any, ":memory:", "", "", #PB_Database_SQLite)
If DB
RegisterSQLiteFunctions(DB)
DatabaseUpdate(DB, "CREATE TABLE myTable (id INTEGER, data DOUBLE, description text)")
DatabaseUpdate(DB, "INSERT INTO myTable VALUES ( 1, 18.5, 'bla')")
If DatabaseQuery(DB, "SELECT typeofcol(id), typeofcol(data), typeofcol(description) FROM myTable")
If NextDatabaseRow(DB)
Debug GetDatabaseString(DB, 0)
Debug GetDatabaseString(DB, 1)
Debug GetDatabaseString(DB, 2)
EndIf
FinishDatabaseQuery(DB)
Else
Debug DatabaseError()
EndIf
CloseDatabase(DB)
EndIf