@@ -19,6 +19,7 @@ Public Sub AllTests()
1919 TestDates
2020 TestStrings
2121 TestBackup
22+ TestBlob
2223 SQLite3Free ' Quite optional
2324End Sub
2425
@@ -850,6 +851,7 @@ Public Sub TestStrings()
850851
851852 Dim myString1 As String
852853 Dim myString2 As String
854+ Dim myLongString As String
853855 Dim myStringResult As String
854856
855857 Debug.Print "----- TestStrings Start -----"
@@ -860,6 +862,7 @@ Public Sub TestStrings()
860862 Debug.Print "SQLite3Open returned " & RetVal
861863
862864 myString2 = ""
865+ myLongString = String (10000 , "A" )
863866
864867 '------------------------
865868 ' Create the table
@@ -907,6 +910,23 @@ Public Sub TestStrings()
907910 Beep
908911 End If
909912
913+ RetVal = SQLite3Reset(myStmtHandle)
914+ If RetVal <> SQLITE_OK Then
915+ Debug.Print "SQLite3Reset returned " & RetVal, SQLite3ErrMsg(myDbHandle)
916+ Beep
917+ End If
918+
919+ RetVal = SQLite3BindText(myStmtHandle, 1 , myLongString)
920+ If RetVal <> SQLITE_OK Then
921+ Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle)
922+ Beep
923+ End If
924+
925+ RetVal = SQLite3Step(myStmtHandle)
926+ If RetVal <> SQLITE_DONE Then
927+ Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle)
928+ Beep
929+ End If
910930 ' Finalize the statement
911931 RetVal = SQLite3Finalize(myStmtHandle)
912932 Debug.Print "SQLite3Finalize returned " & RetVal
@@ -937,6 +957,16 @@ Public Sub TestStrings()
937957 Debug.Print "No row found"
938958 End If
939959
960+ RetVal = SQLite3Step(myStmtHandle)
961+ If RetVal = SQLITE_ROW Then
962+ ' We have access to the result columns here.
963+ myStringResult = SQLite3ColumnText(myStmtHandle, 0 )
964+
965+ Debug.Print "Long String is the same: " & (myStringResult = myLongString)
966+ ElseIf RetVal = SQLITE_DONE Then
967+ Debug.Print "No row found"
968+ End If
969+
940970 ' Finalize (delete) the statement
941971 RetVal = SQLite3Finalize(myStmtHandle)
942972 Debug.Print "SQLite3Finalize returned " & RetVal
@@ -997,6 +1027,93 @@ Public Sub TestBackup()
9971027 Debug.Print "----- TestBackup End -----"
9981028End Sub
9991029
1030+ Public Sub TestBlob ()
1031+ Dim testFile As String
1032+
1033+ Dim myDbHandle As Long
1034+ Dim myStmtHandle As Long
1035+ Dim RetVal As Long
1036+ Dim stepMsg As String
1037+ Dim i As Long
1038+
1039+ Dim myBlob(2 ) As Byte
1040+ Dim myBlobResult() As Byte
1041+
1042+ Debug.Print "----- TestBlob Start -----"
1043+
1044+ ' Open the database - getting a DbHandle back
1045+ testFile = "C:\TestSqlite3ForExcel.db3"
1046+ RetVal = SQLite3Open(testFile, myDbHandle)
1047+ Debug.Print "SQLite3Open returned " & RetVal
1048+
1049+ myBlob(0 ) = 90
1050+ myBlob(1 ) = 91
1051+ myBlob(2 ) = 92
1052+
1053+ '------------------------
1054+ ' Create the table
1055+ ' ================
1056+ ' (I've got no error checking here...)
1057+ SQLite3ExecuteNonQuery myDbHandle, "CREATE TABLE MyBlobTable (MyValue BLOB)"
1058+
1059+ '-------------------------
1060+ ' Prepare an insert statement with parameters
1061+ ' ===============
1062+ ' Create the sql statement - getting a StmtHandle back
1063+ RetVal = SQLite3PrepareV2(myDbHandle, "INSERT INTO MyBlobTable Values (@SomeString)" , myStmtHandle)
1064+ If RetVal <> SQLITE_OK Then
1065+ Debug.Print "SQLite3PrepareV2 returned " & SQLite3ErrMsg(myDbHandle)
1066+ Beep
1067+ End If
1068+
1069+ RetVal = SQLite3BindBlob(myStmtHandle, 1 , myBlob)
1070+ If RetVal <> SQLITE_OK Then
1071+ Debug.Print "SQLite3Bind returned " & RetVal, SQLite3ErrMsg(myDbHandle)
1072+ Beep
1073+ End If
1074+
1075+ RetVal = SQLite3Step(myStmtHandle)
1076+ If RetVal <> SQLITE_DONE Then
1077+ Debug.Print "SQLite3Step returned " & RetVal, SQLite3ErrMsg(myDbHandle)
1078+ Beep
1079+ End If
1080+
1081+ ' Finalize the statement
1082+ RetVal = SQLite3Finalize(myStmtHandle)
1083+ Debug.Print "SQLite3Finalize returned " & RetVal
1084+
1085+ '-------------------------
1086+ ' Select statement
1087+ ' ===============
1088+ ' Create the sql statement - getting a StmtHandle back
1089+ ' Now using named parameters!
1090+ RetVal = SQLite3PrepareV2(myDbHandle, "SELECT * FROM MyBlobTable" , myStmtHandle)
1091+ Debug.Print "SQLite3PrepareV2 returned " & RetVal
1092+
1093+ RetVal = SQLite3Step(myStmtHandle)
1094+ If RetVal = SQLITE_ROW Then
1095+ ' We have access to the result columns here.
1096+ myBlobResult = SQLite3ColumnBlob(myStmtHandle, 0 )
1097+ For i = LBound(myBlobResult) To UBound(myBlobResult)
1098+ Debug.Print "Blob byte " & i & ": " & myBlobResult(i)
1099+ Next
1100+ ElseIf RetVal = SQLITE_DONE Then
1101+ Debug.Print "No row found"
1102+ End If
1103+
1104+ ' Finalize (delete) the statement
1105+ RetVal = SQLite3Finalize(myStmtHandle)
1106+ Debug.Print "SQLite3Finalize returned " & RetVal
1107+
1108+ ' Close the database
1109+ RetVal = SQLite3Close(myDbHandle)
1110+ Kill testFile
1111+
1112+ Debug.Print "----- TestBlob End -----"
1113+ End Sub
1114+
1115+
1116+
10001117' SQLite3 Helper Functions
10011118Public Function SQLite3ExecuteNonQuery (ByVal dbHandle As Long , ByVal SqlCommand As String ) As Long
10021119 Dim stmtHandle As Long
0 commit comments