비주얼 베이직 6
SQLite ODBC 드라이버를 사용하여 데이터베이스에 접근할 수 있다.
ODBC 페이지의 지침을 따르십시오.
사용
아래는 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