Results 1 to 6 of 6

Thread: Open SQLite database (.sqlite file)

  1. #1

    Thread Starter
    Member LoopUntil's Avatar
    Join Date
    Jul 2008
    Posts
    58

    Unhappy Open SQLite database (.sqlite file)

    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?!

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Open SQLite database (.sqlite file)

    Try using the SQLLite ODBC Driver

  3. #3

    Thread Starter
    Member LoopUntil's Avatar
    Join Date
    Jul 2008
    Posts
    58

    Re: Open SQLite database (.sqlite file)

    Some other solution?

  4. #4
    Junior Member
    Join Date
    Aug 2006
    Posts
    27

    Thumbs up Re: Open SQLite database (.sqlite file)

    Quote Originally Posted by LoopUntil View Post
    Some other solution?
    helo

    this example for you ...

    Code:
    Public Sub LoadGrid()
    
     
     
    Dim DB_Handle As Long
    Dim strErrMsg As String
    Dim TableArray() As Variant
    Dim intRecords As Integer
    
    Dim strQuery As String
    Dim intCounter1 As Integer
    Dim OutputString As String
    
    
    '/* clear list
    Lst_Teca.ListItems.Clear
    
    '/* path base 
    FILE_Database = App.Path & "\store.db" '[ local]
    strQuery = "Select * from Archivio"
    
    
    DB_Handle = ModSqlite.sqlite_open(FILE_Database, 0, strErrMsg)
    If DB_Handle <> 0 Then
        TableArray = ModSqlite.ags_sqlite_get_table(DB_Handle, strQuery, strErrMsg)
        If Len(strErrMsg) = 0 Then
             
            intRecords = ModSqlite.ags_number_of_rows_from_last_call
            
            If intRecords > 0 Then '/*  
                
    
                For intCounter1 = 1 To UBound(TableArray, 1)
                    OutputString = ""
              
               
                '/* show records on list  ---------------------------
                    With Lst_Teca.ListItems.Add
                        '/* [CodiceID]
    10                        .Text = TableArray(intCounter1, 0)
                        '/* [Titolo]
    20                        .SubItems(1) = TableArray(intCounter1, 1)
                        '/* [Sottotitolo]
    30                        .SubItems(2) = TableArray(intCounter1, 2)
                        '/* [Artista1]
    40                        .SubItems(3) = TableArray(intCounter1, 3)
                        '/* [Artista2]
    50                        .SubItems(4) = TableArray(intCounter1, 4)
                        '/* [Artista3]
    60                        .SubItems(5) = TableArray(intCounter1, 5)
                       '/* [Album]
    70                        .SubItems(6) = TableArray(intCounter1, 6)
                        '/* [Traccia]
    80                        .SubItems(7) = TableArray(intCounter1, 7)
                        '/* [Tema]
    90                        .SubItems(8) = TableArray(intCounter1, 8)
                        '/* [Genere]
    100                       .SubItems(9) = TableArray(intCounter1, 9)
                        '/* [Tempo]
    110                       .SubItems(10) = TableArray(intCounter1, 10)
                        '/* [Energia]
    120                       .SubItems(11) = TableArray(intCounter1, 11)
                        '/* [CodCategoria]
    130                       .SubItems(12) = TableArray(intCounter1, 12)
                        '/* [IndiceGradimento]
    140                       .SubItems(13) = TableArray(intCounter1, 13)
                        '/* [CodiciAudio]
    150                       .SubItems(14) = TableArray(intCounter1, 14)
                        '/* [ImmagineAlbum]
    160                       .SubItems(15) = TableArray(intCounter1, 15)
                        '/* [NMaxPassaggi]
    170                       .SubItems(16) = TableArray(intCounter1, 16)
                        '/* [NMinPassaggi]
    180                       .SubItems(17) = TableArray(intCounter1, 17)
                        '/* [SeparazioneBrano]
    190                       .SubItems(18) = TableArray(intCounter1, 18)
                        '/* [Abilitadal]
    200                       .SubItems(19) = TableArray(intCounter1, 19)
                        '/* [Abilitafinoal]
    210                       .SubItems(20) = TableArray(intCounter1, 20)
                        '/* [DATAGRID]
    220                       .SubItems(21) = TableArray(intCounter1, 21)
                        '/* [HOURGRID]
    230                       .SubItems(22) = TableArray(intCounter1, 22)
                        '/* [Fadein]
    240                       .SubItems(23) = TableArray(intCounter1, 23)
                        '/* [Start]
    250                       .SubItems(24) = TableArray(intCounter1, 24)
                        '/* [COUNTDOWN]
    260                       .SubItems(25) = TableArray(intCounter1, 25)
                        '/* [Fine]
    270                       .SubItems(26) = TableArray(intCounter1, 26)
                        '/* [FadeOut]
    280                       .SubItems(27) = TableArray(intCounter1, 27)
                        '/* [RitornelloIntro]
    290                       .SubItems(28) = TableArray(intCounter1, 28)
                        '/* [RitornelloEnd]
    300                       .SubItems(29) = TableArray(intCounter1, 29)
                        '/* [RitornelloOut]
    310                       .SubItems(30) = TableArray(intCounter1, 30)
                        '/* [Volume]
    320                       .SubItems(31) = TableArray(intCounter1, 31)
                        '/* [InfoFile]
    330                       .SubItems(32) = TableArray(intCounter1, 32)
                        '/* [Passaggio1]
    340                       .SubItems(33) = TableArray(intCounter1, 33)
                        '/* [Passaggio2]
    350                       .SubItems(34) = TableArray(intCounter1, 34)
                        '/* [Passaggio3]
    360                       .SubItems(35) = TableArray(intCounter1, 35)
                        '/* [Passaggio4]
    370                       .SubItems(36) = TableArray(intCounter1, 36)
                        '/* [CancellazioneAutomatica]
    380                       .SubItems(37) = TableArray(intCounter1, 37)
                        '/* [AudioContenuti]
    390                       .SubItems(38) = TableArray(intCounter1, 38)
                        '/* [AudioinConflitto]
    400                       .SubItems(39) = TableArray(intCounter1, 39)
                        '/* [Empty1]
    410                       .SubItems(40) = TableArray(intCounter1, 40)
                        '/* [Empty2]
    420                       .SubItems(41) = TableArray(intCounter1, 41)
                        '/* [Empty3]
    430                       .SubItems(42) = TableArray(intCounter1, 42)
                        '/* [Empty4]
    440                       .SubItems(43) = TableArray(intCounter1, 43)
                        '/* [Empty5]
    450                       .SubItems(44) = TableArray(intCounter1, 44)
                    End With
                Next intCounter1
            Else
            MsgBox "no record found"
            End If
        Else
            MsgBox strErrMsg, vbOKOnly, "SQLite Error"
        End If
        sqlite_close DB_Handle
    Else
        MsgBox "Error on open data"
    End If
    
    End Sub

    and full example with AGS_SQLite.dll

    ps : any extension of file is equal example : .db .sql .sqlite ..ecc
    example : data.sqlite / data.db / data.sql / data.dat ... ecc


    bye from sicily (Enna)
    Attached Files Attached Files
    Last edited by massimodan; Feb 12th, 2012 at 03:31 AM.

  5. #5
    Addicted Member
    Join Date
    Feb 2006
    Location
    Craiova, Romania
    Posts
    140
    Last edited by cliv; Feb 13th, 2012 at 08:55 AM.

  6. #6
    New Member
    Join Date
    Jul 2018
    Posts
    4

    SQLitening example

    Code:
    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
    Attached Images Attached Images  
    Last edited by gRens; Sep 3rd, 2023 at 10:33 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width