Its a bit out of context
This lives in a class that I use as a wrapper for a database (m_DB)
There are several different wrappers for different db’s (MS SQL, SQLITE, Postgresql etc) that allow me to implement things the way I like (or that dont exist like MBS TableSchema and DatabaseSchema for MS SQL)
This one is from the SQLIte wrapper
But this should give you an idea of how this works
then by making this one method use try / catch to catch errors you’re “done” as far as updating to API 2 methods
Public Function RawSQLSelect(query as string, ParamArray bindVars as variant) as RecordSet
Dim localDB As SQLiteDatabase = SQLiteDatabase(m_DB)
Dim ps As SQLitePreparedStatement = localDB.Prepare(query)
For i As Integer = 0 To bindVars.ubound
Select Case True
Case bindVars(i).Type = Variant.TypeBoolean
ps.BindType( i, SQLitePreparedStatement.SQLITE_BOOLEAN)
Case bindVars(i).Type = Variant.TypeColor
ps.BindType( i, SQLitePreparedStatement.SQLITE_INTEGER)
Case bindVars(i).Type = Variant.TypeCurrency
ps.BindType( i, SQLitePreparedStatement.SQLITE_DOUBLE)
Case bindVars(i).Type = Variant.TypeDate
ps.BindType( i, SQLitePreparedStatement.SQLITE_TEXT)
Case bindVars(i).Type = Variant.TypeDouble
ps.BindType( i, SQLitePreparedStatement.SQLITE_DOUBLE)
Case bindVars(i).Type = Variant.TypeInt32
ps.BindType( i, SQLitePreparedStatement.SQLITE_INTEGER)
Case bindVars(i).Type = Variant.TypeInt64
ps.BindType( i, SQLitePreparedStatement.SQLITE_INT64)
Case bindVars(i).Type = Variant.TypeSingle
ps.BindType( i, SQLitePreparedStatement.SQLITE_DOUBLE)
Case bindVars(i).Type = Variant.TypeString
ps.BindType( i, SQLitePreparedStatement.SQLITE_TEXT)
Else
Break
End Select
Next
Select Case bindVars.Ubound
Case -1
Return ps.SQLSelect
Case 0
Return ps.SQLSelect( bindVars(0) )
Case 1
Return ps.SQLSelect( bindVars(0), bindVars(1) )
Case 2
Return ps.SQLSelect( bindVars(0), bindVars(1), bindVars(2) )
Case 3
Return ps.SQLSelect( bindVars(0), bindVars(1), bindVars(2), bindvars(3) )
Case 4
Return ps.SQLSelect( bindVars(0), bindVars(1), bindVars(2), bindvars(3), bindvars(4) )
Case 5
Return ps.SQLSelect( bindVars(0), bindVars(1), bindVars(2), bindvars(3), bindvars(4), bindvars(5) )
Case 6
Return ps.SQLSelect( bindVars(0), bindVars(1), bindVars(2), bindvars(3), bindvars(4), bindvars(5), bindvars(6) )
Else
Break
End Select
If localDB.Error Then
Debugging.debuglog CurrentMethodName + " error " + Str(localDB.ErrorCode) + " " + localDB.ErrorMessage
Break
End If
End Function