@@ -12,6 +12,7 @@ Public Sub AllTests()
1212
1313 TestVersion
1414 TestOpenClose
15+ TestOpenCloseV2
1516 TestError
1617 TestInsert
1718 TestSelect
@@ -20,6 +21,8 @@ Public Sub AllTests()
2021 TestStrings
2122 TestBackup
2223 TestBlob
24+ TestWriteReadOnly
25+
2326 SQLite3Free ' Quite optional
2427End Sub
2528
@@ -60,6 +63,32 @@ Public Sub TestOpenClose()
6063
6164End Sub
6265
66+ Public Sub TestOpenCloseV2 ()
67+ Dim testFile As String
68+ Dim myDbHandle As Long
69+ Dim myDbHandleV2 As Long
70+ Dim RetVal As Long
71+
72+ ' Open the database in Read Write Access
73+ testFile = "C:\TestSqlite3ForExcel.db3"
74+ RetVal = SQLite3Open(testFile, myDbHandle)
75+ Debug.Print "SQLite3Open returned " & RetVal
76+
77+ ' Open the database in Read Only Access
78+ testFile = "C:\TestSqlite3ForExcel.db3"
79+ RetVal = SQLite3OpenV2(testFile, myDbHandleV2, SQLITE_OPEN_READONLY, "" )
80+ Debug.Print "SQLite3OpenV2 returned " & RetVal
81+
82+ RetVal = SQLite3Close(myDbHandleV2)
83+ Debug.Print "SQLite3Close V2 returned " & RetVal
84+
85+ RetVal = SQLite3Close(myDbHandle)
86+ Debug.Print "SQLite3Close returned " & RetVal
87+
88+ Kill testFile
89+
90+ End Sub
91+
6392Public Sub TestError ()
6493 Dim myDbHandle As Long
6594 Dim RetVal As Long
@@ -1113,6 +1142,78 @@ Public Sub TestBlob()
11131142End Sub
11141143
11151144
1145+ Public Sub TestWriteReadOnly ()
1146+ Dim testFile As String
1147+ Dim myDbHandle As Long
1148+ Dim myDbHandleV2 As Long
1149+ Dim myStmtHandle As Long
1150+ Dim RetVal As Long
1151+
1152+ ' Open the database in Read Write Access
1153+ testFile = "C:\TestSqlite3ForExcel.db3"
1154+ RetVal = SQLite3Open(testFile, myDbHandle)
1155+ Debug.Print "SQLite3Open returned " & RetVal
1156+
1157+ ' Open the database in Read Only Access
1158+ testFile = "C:\TestSqlite3ForExcel.db3"
1159+ RetVal = SQLite3OpenV2(testFile, myDbHandleV2, SQLITE_OPEN_READONLY, Empty )
1160+ Debug.Print "SQLite3OpenV2 returned " & RetVal
1161+
1162+ ' Create the sql statement - getting a StmtHandle back
1163+ RetVal = SQLite3PrepareV2(myDbHandle, "CREATE TABLE MyFirstTable (TheId INTEGER, TheText TEXT, TheValue REAL)" , myStmtHandle)
1164+ Debug.Print "SQLite3PrepareV2 returned " & RetVal
1165+
1166+ ' Start running the statement
1167+ RetVal = SQLite3Step(myStmtHandle)
1168+ Debug.Print "SQLite3Step returned " & RetVal
1169+
1170+ ' Finalize (delete) the statement
1171+ RetVal = SQLite3Finalize(myStmtHandle)
1172+ Debug.Print "SQLite3Finalize returned " & RetVal
1173+
1174+ ' Create the sql statement - getting a StmtHandle back with Read Only
1175+ RetVal = SQLite3PrepareV2(myDbHandleV2, "CREATE TABLE MySecondTable (TheId INTEGER, TheText TEXT, TheValue REAL)" , myStmtHandle)
1176+ 'RetVal = SQLite3PrepareV2(myDbHandleV2, "SELECT * FROM MyFirstTable", myStmtHandle)
1177+ Debug.Print "SQLite3PrepareV2 returned " & RetVal
1178+
1179+ ' Start running the statement with Read Only
1180+ RetVal = SQLite3Step(myStmtHandle)
1181+ Debug.Print "SQLite3Step returned " & RetVal
1182+
1183+ If RetVal = SQLITE_READONLY Then
1184+ Debug.Print "Cannot Write in Read Only database"
1185+ End If
1186+
1187+ ' Finalize (delete) the statement with Read Only
1188+ RetVal = SQLite3Finalize(myStmtHandle)
1189+ Debug.Print "SQLite3Finalize returned " & RetVal
1190+
1191+ ' Create the sql statement - getting a StmtHandle back with Read Only
1192+ RetVal = SQLite3PrepareV2(myDbHandleV2, "SELECT * FROM MyFirstTable" , myStmtHandle)
1193+ Debug.Print "SQLite3PrepareV2 returned " & RetVal
1194+
1195+ ' Start running the statement with Read Only
1196+ RetVal = SQLite3Step(myStmtHandle)
1197+ Debug.Print "SQLite3Step returned " & RetVal
1198+
1199+ If RetVal = SQLITE_DONE Then
1200+ Debug.Print "But Reading is granted on Read Only database"
1201+ End If
1202+
1203+ ' Finalize (delete) the statement with Read Only
1204+ RetVal = SQLite3Finalize(myStmtHandle)
1205+ Debug.Print "SQLite3Finalize returned " & RetVal
1206+
1207+ RetVal = SQLite3Close(myDbHandleV2)
1208+ Debug.Print "SQLite3Close V2 returned " & RetVal
1209+
1210+ RetVal = SQLite3Close(myDbHandle)
1211+ Debug.Print "SQLite3Close returned " & RetVal
1212+
1213+ Kill testFile
1214+
1215+ End Sub
1216+
11161217
11171218' SQLite3 Helper Functions
11181219Public Function SQLite3ExecuteNonQuery (ByVal dbHandle As Long , ByVal SqlCommand As String ) As Long
@@ -1161,3 +1262,4 @@ Public Sub SQLite3ExecuteQuery(ByVal dbHandle As Long, ByVal sqlQuery As String)
11611262 RetVal = SQLite3Finalize(stmtHandle)
11621263 Debug.Print "SQLite3Finalize returned " & RetVal
11631264End Sub
1265+
0 commit comments