SQLITE 3 support
What about SQLITE 3 support and binding?
How is it possible to use, under Jabaco, sqlite3.dll and especially the export functions:
int sqlite3_open(
const char *filename, /* Database filename (UTF-8) */
sqlite3 **ppDb /* OUT: SQLite db handle */
);
int sqlite3_exec(
sqlite3*, /* An open database */
const char *sql, /* SQL to be evaluated */
int (*callback)(void*,int,char**,char**), /* Callback function */
void *, /* 1st argument to callback */
char **errmsg /* Error msg written here */
);
int sqlite3_get_table(
sqlite3 *db, /* An open database */
const char *zSql, /* SQL to be evaluated */
char ***pazResult, /* Results of the query */
int *pnRow, /* Number of result rows written here */
int *pnColumn, /* Number of result columns written here */
char **pzErrmsg /* Error msg written here */
);
void sqlite3_free_table(char **result);
int sqlite3_close(sqlite3 *);
Thanks,
Frank
How is it possible to use, under Jabaco, sqlite3.dll and especially the export functions:
int sqlite3_open(
const char *filename, /* Database filename (UTF-8) */
sqlite3 **ppDb /* OUT: SQLite db handle */
);
int sqlite3_exec(
sqlite3*, /* An open database */
const char *sql, /* SQL to be evaluated */
int (*callback)(void*,int,char**,char**), /* Callback function */
void *, /* 1st argument to callback */
char **errmsg /* Error msg written here */
);
int sqlite3_get_table(
sqlite3 *db, /* An open database */
const char *zSql, /* SQL to be evaluated */
char ***pazResult, /* Results of the query */
int *pnRow, /* Number of result rows written here */
int *pnColumn, /* Number of result columns written here */
char **pzErrmsg /* Error msg written here */
);
void sqlite3_free_table(char **result);
int sqlite3_close(sqlite3 *);
Thanks,
Frank
Hello frankp,
did you use sqlite3 in VB6?
i made a short look around the sourcecode of sqlite3 and i did not found the __stdcall calling convention.
in fact it is possible to use winapi-functions like the following, but winapi-functions use the __stdcall calling convention
i do not know if it is possible to call __cdecl-functions in jabaco, lets see what Manuel will say, i am interested in this point also
another problem would be the callbackfunction for the function sqlite3_exec this must be in __cdecl also
Maybe another (harder) solution would be to get the sourcode of sqlite3 and export all functions with __stdcall.
greetings
OlimilO
did you use sqlite3 in VB6?
i made a short look around the sourcecode of sqlite3 and i did not found the __stdcall calling convention.
in fact it is possible to use winapi-functions like the following, but winapi-functions use the __stdcall calling convention
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 |
Public WinAPI Function TheFunctionName lib "thedllname" (ByVal ahandle As Integer) As Integer 'int sqlite3_open( 'Const char *filename, /* Database filename (UTF-8) */ 'sqlite3 **ppDb /* OUT: SQLite db handle */ '); Private WinApi Function sqlite3_open Lib "sqlite3"( _ ByVal filename As String, _ ByVal ppDb As Integer _ ) As Integer |
i do not know if it is possible to call __cdecl-functions in jabaco, lets see what Manuel will say, i am interested in this point also
another problem would be the callbackfunction for the function sqlite3_exec this must be in __cdecl also
Maybe another (harder) solution would be to get the sourcode of sqlite3 and export all functions with __stdcall.
greetings
OlimilO
SQLITE 3 support
Hello OlimilO and thanks for your answer.
I haven't used sqlite3 with VB6 succesfully, but I do have use it succesfully with Rapid-Q and FreeBasic who also use stdcall (at least I think...).
I agree that using the callback function is rather difficult, so I don't use the sqlite_exec() function for SELECT queries. I use sqlite3_get_table() instead. I have also made a sort of "wrapper" dll in FreeBasic to acquire the result delimited data string from sqlite3_get_table(), as well as the number of rows and columns, without having to pass pointers as parameters. It works well with FreeBasic-compiled programs, but it fails to give the data string in Rapid-Q and VB6. In the latter cases I can only get the number of rows and columns. In Jabaco, I only get JRE error, concerning the sqlite3.dll module, not my own dll.
Greetings,
Frank
This post has been edited 1 times, last edit by "frankp" (Jan 29th 2009, 7:02pm)
SQLiteJDBC is a Java JDBC driver for SQLite. You should wait for the next Jabaco version. The current beta couldn't load this library.
Beginner
Location: Sesto Fiorentino, Florence (ITALY)
Occupation: design & development (HW, SW & FW)
I found this wrapper: http://www.ch-werner.de/javasqlite/. Provides no error! Someone knows how to manage it properly in Jabaco?
Massimo
Hmm... seems simple. The only thing you have to do is copying the files from javasqlite-20081006-win32.zip into your JRE-folder (the structure is already correct in the zip-file). Now you have installed the SQLite driver for JDBC and you can use it like all other JDBC-compatible databases:
|
|
Jabaco Source |
1 2 3 4 5 6 7 |
On Error Resume Next Dim database As New DataBase Dim driver As Class driver = Class.forName("SQLite.JDBCDriver") If driver = Nothing Then MsgBox "Not found!" On Error Goto 0 Call database.Connect("jdbc:sqlite:/:memory:") |
Beginner
Location: Sesto Fiorentino, Florence (ITALY)
Occupation: design & development (HW, SW & FW)
with the help of Manuel I would have understood how to use JavaSQLite wrapper in Jabaco, what follows is just a simple example to read the fields names:
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
Dim dbFile As String dbFile = App.Path & "/test.db" dbFile = Replace(dbFile, "\", "/") Dim driver As Class driver = Class.forName("SQLite.JDBCDriver") If driver = Nothing Then MsgBox "SQLite Driver Not Found!" Exit Sub End If Dim database As New DataBase Dim rs As ResultSet Dim rsMetaData As java#sql#ResultSetMetaData database.Connect("jdbc:sqlite:/" & dbFile) rs = database.ExecuteStatement("SELECT * FROM country ORDER BY iso_code") rsMetaData = rs.getMetaData Dim ColumnName(1 To rsMetaData.getColumnCount) AS String Dim f As Integer For f = 1 To rsMetaData.getColumnCount ColumnName(f) = rsMetaData.getColumnName(f) Next f rs.close |
... the problem is that I do not know what methods and properties to fill a JBGrid with data from a Select!
Perhaps this helps?
Do you know btw what should I include in Project/References?
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 |
rs = Database1.ExecuteStatement("SELECT * FROM Contacts") Do While res.next JBGrid1.TextMatrix(res.getRow() - 1, 0) = rs.getString("RecordId") JBGrid1.TextMatrix(res.getRow() - 1, 1) = rs.getString("Title") JBGrid1.TextMatrix(res.getRow() - 1, 2) = rs.getString("FirstNAME") JBGrid1.TextMatrix(res.getRow() - 1, 3) = rs.getString("MiddleName") JBGrid1.TextMatrix(res.getRow() - 1, 4) = rs.getString("LastName") rows = rows + 1 JBGrid1.Rows = rows Loop |
Do you know btw what should I include in Project/References?
I'm too late but i won't trash my sample...
Nothing. Just "install" the driver by copying the files from the zip into your Java (JRE)-folder.
Quoted
Do you know btw what should I include in Project/References?
I'll show you a better way in future. For now you could use this sample:
Quoted
... the problem is that I do not know what methods and properties to fill a JBGrid with data from a Select!
|
|
Jabaco Source |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
On Error Goto ERROUT Dim driver As Class driver = Class.forName("SQLite.JDBCDriver") If driver = Nothing Then MsgBox "Not found!" Call database1.Connect("jdbc:sqlite:/:memory:") Call database1.ExecuteStatement("CREATE TABLE user (id Integer PRIMARY KEY, name varchar(10) NOT NULL, desc varchar(30) NOT NULL)") Call database1.ExecuteStatement("INSERT INTO user (id, name, desc) VALUES (1, 'manuel', 'developer')") Call database1.ExecuteStatement("INSERT INTO user (id, name, desc) VALUES (2, 'frankp', 'developer')") Call database1.ExecuteStatement("INSERT INTO user (id, name, desc) VALUES (3, 'maxim', 'developer')") Call database1.ExecuteStatement("INSERT INTO user (id, name, desc) VALUES (4, 'david', 'supporter')") Dim rsAllUsers As java#sql#ResultSet rsAllUsers = database1.ExecuteStatement("SELECT * FROM user") Dim i As Integer Dim rsAllUserColCount = rsAllUsers.getMetaData.getColumnCount JBGrid1.Cols = rsAllUserColCount For i = 1 To rsAllUserColCount JBGrid1.Header(i-1) = rsAllUsers.getMetaData.getColumnName(i) Next Do While rsAllUsers.next For i = 1 To rsAllUserColCount JBGrid1.TextMatrix(rsAllUsers.getRow() - 1, i - 1) = rsAllUsers.getString(i) Next rows = rows + 1 JBGrid1.Rows = rows Loop Exit Sub ERROUT: MsgBox Err.toString |
Found some compilation problems when tried the SQLite sample code...
Hello,
But couldn´t reproduce the connection to the SQLite database, only because in the compilation process showed that there is an error, even when doing a copy-and-paste of the code mentioned above. Could you (or anyone) comment what I´m doing wrong ? I´ve sent the sample code (with the snapshot of the error tha occured), for better analysis. Please comment, when possible.
Regards,
Sven
I downloaded the file (http://www.ch-werner.de/javasqlite/javas…81006-win32.zip) and have put the contents in the appropriate folders (Bin and in Java\Jre6\lib\ext), as described in other place, here in the forum.I'm too late but i won't trash my sample...Nothing. Just "install" the driver by copying the files from the zip into your Java (JRE)-folder.
Quoted
Do you know btw what should I include in Project/References?I'll show you a better way in future. For now you could use this sample:
Quoted
... the problem is that I do not know what methods and properties to fill a JBGrid with data from a Select!
![]()
Jabaco Source
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 On Error Goto ERROUT Dim driver As Class driver = Class.forName("SQLite.JDBCDriver") If driver = Nothing Then MsgBox "Not found!" Call database1.Connect("jdbc:sqlite:/:memory:") Call database1.ExecuteStatement("CREATE TABLE user (id Integer PRIMARY KEY, name varchar(10) NOT NULL, desc varchar(30) NOT NULL)") Call database1.ExecuteStatement("INSERT INTO user (id, name, desc) VALUES (1, 'manuel', 'developer')") Call database1.ExecuteStatement("INSERT INTO user (id, name, desc) VALUES (2, 'frankp', 'developer')") Call database1.ExecuteStatement("INSERT INTO user (id, name, desc) VALUES (3, 'maxim', 'developer')") Call database1.ExecuteStatement("INSERT INTO user (id, name, desc) VALUES (4, 'david', 'supporter')") Dim rsAllUsers As java#sql#ResultSet rsAllUsers = database1.ExecuteStatement("SELECT * FROM user") Dim i As Integer Dim rsAllUserColCount = rsAllUsers.getMetaData.getColumnCount JBGrid1.Cols = rsAllUserColCount For i = 1 To rsAllUserColCount JBGrid1.Header(i-1) = rsAllUsers.getMetaData.getColumnName(i) Next Do While rsAllUsers.next For i = 1 To rsAllUserColCount JBGrid1.TextMatrix(rsAllUsers.getRow() - 1, i - 1) = rsAllUsers.getString(i) Next rows = rows + 1 JBGrid1.Rows = rows Loop Exit Sub ERROUT: MsgBox Err.toString
But couldn´t reproduce the connection to the SQLite database, only because in the compilation process showed that there is an error, even when doing a copy-and-paste of the code mentioned above. Could you (or anyone) comment what I´m doing wrong ? I´ve sent the sample code (with the snapshot of the error tha occured), for better analysis. Please comment, when possible.
Regards,
Sven
Similar threads
-
General topics, questions and discussions »-
Connect to MySQL database
(Jan 27th 2009, 4:41am)
-
General topics, questions and discussions »-
Will jabaco always be free ?
(Dec 18th 2008, 12:20pm)
-
Allgemeine Themen, Fragen und Diskussionen »-
jar einbinden
(Dec 2nd 2008, 11:00am)
