Visual Basic 6
我们可以使用SQLite ODBC驱动程序访问数据库。
只需按照ODBC页面上的说明进行操作即可。
使用方法
Bellow是使用ADO的示例。
您只需更改URI字符串即可为副节点使用类似的代码。
代码示例
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://0.0.0.0:1234"
Set Conn = New ADODB.Connection
Conn.Open "DRIVER=SQLite3 ODBC Driver;Database=" & URI & ";Timeout=10000;"
' Check if the database is ready
Do
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
Loop
' 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
Rst.MoveNext
Loop
locExit:
' 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
locError:
If Err Then
MsgBox Err.Source & ": " & Err.Description, , "Error"
End If
GoTo locExit
End Sub