Visual Basic 6

We can access the database using a SQLite ODBC Driver.

Just follow the instructions on the ODBC page.


Bellow is an example using ADO.

You can use a similar code for a secondary node by just changing the URI string.

Example code
Option Explicit

Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

Public Sub Main()
  On Error GoTo locError

  Dim Conn As ADODB.Connection
  Dim Rst As ADODB.Recordset
  Dim URI As String
  Dim Status As String

  ' Open a connection
  URI = "file:C:\mydb.db?node=primary&bind=tcp://"
  Set Conn = New ADODB.Connection
  Conn.Open "DRIVER=SQLite3 ODBC Driver;Database=" & URI & ";Timeout=10000;"

  ' Check if the database is ready
    Set Rst = New ADODB.Recordset
    Rst.Open "PRAGMA sync_status", Conn, , , adCmdText
    If Rst.EOF Then
      MsgBox "Could not run 'PRAGMA sync_status'", vbExclamation
      GoTo locExit
    End If
    Status = Rst!sync_status
    Debug.Print Status
    If InStr(Status, """db_is_ready"": true") > 0 Then Exit Do
    Sleep 200

  ' Create a table and populate it
  Conn.Execute "CREATE TABLE IF NOT EXISTS t1 (name)"
  Conn.Execute "INSERT INTO t1 VALUES ('1st')"
  Conn.Execute "INSERT INTO t1 VALUES ('2nd')"
  Conn.Execute "INSERT INTO t1 VALUES ('3rd')"

  ' Fetch the table data
  Set Rst = New ADODB.Recordset
  Rst.Open "t1", Conn, , , adCmdTable
  Do While Not Rst.EOF
    Debug.Print "  " & Rst!Name


  ' Clean up

  If Not Rst Is Nothing Then
    If Rst.State = adStateOpen Then Rst.Close
  End If
  Set Rst = Nothing

  If Not Conn Is Nothing Then
    If Conn.State = adStateOpen Then Conn.Close
  End If
  Set Conn = Nothing

  Exit Sub


  If Err Then
    MsgBox Err.Source & ": " & Err.Description, , "Error"
  End If

  GoTo locExit

End Sub