I've tryed to connect to a SQlite database (with this extension: .sqlite) using: AG_SQLite.dll.
But when I connect to the database and try to get all data it gives me an error:
Code:
Option Explicit
Private strFilename As String
Private Sub Command1_Click()
strFilename = "C:\data.sqlite"
ok
End Sub
Public Sub ok()
Dim DB_Handle As Long
Dim strErrMsg As String
Dim TableArray() As Variant
Dim strQuery As String
Dim intCounter1 As Integer
Dim intRecords As Integer
strQuery = "Select * From ASDTable"
DB_Handle = ModSqlite.sqlite_open(strFilename, 0, strErrMsg)
TableArray = ModSqlite.ags_sqlite_get_table(DB_Handle, strQuery, strErrMsg)
intRecords = ModSqlite.ags_number_of_rows_from_last_call
If intRecords > 0 Then
For intCounter1 = 1 To UBound(TableArray)
Text1.Text = Text1.Text & TableArray(intCounter1)
Next intCounter1
sqlite_close DB_Handle
Else
MsgBox "error"
End If
End Sub
Module /declarations:
Code:
Option Explicit
Public Declare Function sqlite_open Lib "AGS_SQLite.dll" (ByVal filename As String, ByVal mode As Long, ByRef errstr As String) As Long
Public Declare Sub sqlite_close Lib "AGS_SQLite.dll" (ByVal DB_Handle As Long)
Public Declare Function sqlite_last_insert_rowid Lib "AGS_SQLite.dll" (ByVal DB_Handle As Long) As Long
Public Declare Function sqlite_changes Lib "AGS_SQLite.dll" (ByVal DB_Handle As Long) As Long
Public Declare Function sqlite_libversion Lib "AGS_SQLite.dll" () As String
Public Declare Function sqlite_libencoding Lib "AGS_SQLite.dll" () As String
Public Declare Function ags_sqlite_get_table Lib "AGS_SQLite.dll" (ByVal DB_Handle As Long, ByVal SQLString As String, ByRef errstr As String) As Variant()
Public Declare Function ags_sqlite_libversion Lib "AGS_SQLite.dll" () As String
Public Declare Function ags_number_of_rows_from_last_call Lib "AGS_SQLite.dll" () As Long
I've tryed with other DLLs and methods but no success
Can someone give me a working example of reading data from a .sqlite file?!
Option Explicit 'https://sqlitening.planetsquires.com/index.php
Sub InsertT1(s As String)
Rem slsExe "insert into t values(null,'" + s + "')" 'no binding
slsExeBind "insert into t values(null,?)", slsBuildBindDat(s, "T") 'bind as text
End Sub
Private Sub Form_Load()
Dim x As Long
ChDrive App.Path
ChDir App.Path
Caption = "Type SQL and press Enter"
List1.TabStop = False
Text1.Text = "select * from t"
slsSetProcessMods "E1" 'E0=no errors,E1=show msgboxr,E2=show msgbox or crash, nothing crash
slsOpen ":memory:"
slsExe "create table t(c1 integer primary key,c2 text)"
slsExe "Begin immediate"
For x = 1 To 100
InsertT1 "Insert success"
Next
slsExe "End"
ShowRs
End Sub
Function ShowRs() As String
Dim s As String, sql As String, colnum As Long, rownum As Long, columns As Long, rows As Long
sql = Text1
slsSel Text1
columns = slsGetColumnCount
If columns = 0 Then MsgBox "No columns returned: " + sql, , "Sqlite": Exit Function
List1.Clear
Do While slsGetRow
rownum = rownum + 1
s = ""
For colnum = 1 To columns - 1
s = s + slsF(colnum) + " | "
Next
s = s + slsF(colnum)
List1.AddItem s
Loop
If rownum < 1 Then MsgBox "No rows returned: " + sql, , "Sqlite"
End Function
Private Sub Form_Resize()
List1.Move 0, 0, ScaleWidth, ScaleHeight - Text1.Height + 20
Text1.Move 0, List1.Top + List1.Height, ScaleWidth
End Sub
Private Sub Form_Unload(Cancel As Integer)
slsClose
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then KeyAscii = 0: ShowRs
End Sub
09/03/2023 10:15 AM 2,514 Form1.frm
09/03/2023 08:57 AM 6,866 Module1.bas is sqlitenings.inc
09/03/2023 10:15 AM 28,672 Project1.exe
09/03/2023 10:15 AM 667 Project1.vbp
09/03/2023 09:36 AM 84 Project1.vbw
05/26/2023 08:45 AM 1,132,091 sqlite3.dll
06/27/2023 09:21 PM 93,184 SQLitening.dll
07/23/2021 04:46 PM 11,776 sqlitenings.dll