Skip to content

Commit ff84ba6

Browse files
committed
SQLiteCExecSQL - TableMetaAPI
1 parent 102a2dc commit ff84ba6

File tree

5 files changed

+42
-63
lines changed

5 files changed

+42
-63
lines changed

Project/SQLite/C/RecordsetADO/SQLiteCRecordsetADO.cls

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ Friend Sub AddMeta()
6464
Dim ColumnIndex As Long
6565
For ColumnIndex = 0 To UBound(TableMeta)
6666
With TableMeta(ColumnIndex)
67-
If this.DbExec.UseTableMetaAPI Then
67+
If .TableMeta Then
6868
Select Case .AffinityType
6969
Case SQLITE_INTEGER
7070
.AdoType = adInteger

Project/SQLite/C/SQLiteCConst.bas

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ Public Type SQLiteCColumnMeta
7171
TableName As String
7272
OriginName As String
7373
DataType As SQLiteDataType
74+
TableMeta As Boolean '''' Set to True if table meta is available
7475
DeclaredTypeC As String
7576
Affinity As SQLiteTypeAffinity
7677
AffinityType As SQLiteDataType

Project/SQLite/C/Statement/SQLiteCExecSQL.cls

+39-56
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,6 @@ Private Type TSQLiteCExecSQL
7777
PageSize As Long
7878
FilledPagesCount As Long
7979
RowCount As Long
80-
'''' Meta API's fenced with the .UseTableMetadataAPI flag will fail if executed
81-
'''' against the PRAGMA-Table-functions SELECTs. Set it to false in such a case.
82-
UseTableMetaAPI As Boolean
8380
End Type
8481
Private this As TSQLiteCExecSQL
8582

@@ -106,7 +103,6 @@ Friend Sub Init(ByVal DbStmt As SQLiteCStatement)
106103
.MetaLoaded = False
107104
.AffinityMap = Array(SQLITE_BLOB, SQLITE_TEXT, SQLITE_TEXT, _
108105
SQLITE_INTEGER, SQLITE_FLOAT)
109-
.UseTableMetaAPI = True
110106
End With
111107
End Sub
112108

@@ -154,17 +150,6 @@ Public Property Get RowCount() As Long
154150
End Property
155151

156152

157-
'@Ignore ProcedureNotUsed
158-
Public Property Get UseTableMetaAPI() As Boolean
159-
UseTableMetaAPI = this.UseTableMetaAPI
160-
End Property
161-
162-
163-
Public Property Let UseTableMetaAPI(ByVal Value As Boolean)
164-
this.UseTableMetaAPI = Value
165-
End Property
166-
167-
168153
'@Ignore ProcedureNotUsed
169154
Public Property Get PageCount() As Long
170155
PageCount = this.PageCount
@@ -246,6 +231,7 @@ Attribute ColumnMetaAPI.VB_Description = "Retrieves columns metadata."
246231
hStmt = dbs.StmtHandle
247232

248233
Dim ResultCode As SQLiteResultCodes
234+
ResultCode = SQLITE_OK
249235
With ColumnInfo
250236
If .Initialized <> -1 Then Err.Raise ErrNo.InvalidParameterErr, _
251237
"SQLiteCExecSQL", "Set .ColumnIndex and .Initialized=-1 before the call!"
@@ -278,48 +264,45 @@ Attribute ColumnMetaAPI.VB_Description = "Retrieves columns metadata."
278264
ColumnNamePtr = sqlite3_column_origin_name(hStmt, ColumnIndex)
279265
If ColumnNamePtr <> 0 Then .OriginName = UTFlib.StrFromUTF8Ptr(ColumnNamePtr)
280266

281-
'''' Meta API's fenced with the .UseTableMetadataAPI flag will fail if executed
282-
'''' against the PRAGMA-Table-functions SELECTs. Set it to false in such a case.
283-
If this.UseTableMetaAPI Then
284-
Dim DataTypePtr As Variant
285-
DataTypePtr = sqlite3_column_decltype(hStmt, ColumnIndex)
286-
If DataTypePtr <> 0 Then
287-
.DeclaredTypeC = UTFlib.StrFromUTF8Ptr(DataTypePtr)
288-
.Affinity = TypeAffinityFromDeclaredType(.DeclaredTypeC)
289-
.AffinityType = this.AffinityMap(.Affinity - SQLITE_AFF_NONE - 1)
290-
Else
291-
'''' SQLITE_RANGE is expected for a calculated column, such as "count(*)"
292-
'''' Only return an error, if this is not the case; otherwise, continue.
293-
If dbc.ErrInfoRetrieve <> SQLITE_RANGE Then GoTo META_ERROR:
294-
End If
267+
Dim DataTypePtr As Variant
268+
DataTypePtr = sqlite3_column_decltype(hStmt, ColumnIndex)
269+
If DataTypePtr <> 0 Then
270+
.DeclaredTypeC = UTFlib.StrFromUTF8Ptr(DataTypePtr)
271+
.Affinity = TypeAffinityFromDeclaredType(.DeclaredTypeC)
272+
.AffinityType = this.AffinityMap(.Affinity - SQLITE_AFF_NONE - 1)
273+
.TableMeta = True
274+
Else
275+
'''' SQLITE_RANGE is expected for a calculated column, such as "count(*)"
276+
'''' Only return an error, if this is not the case; otherwise, continue.
277+
If dbc.ErrInfoRetrieve <> SQLITE_RANGE Then GoTo META_ERROR:
278+
.TableMeta = False
279+
End If
295280

296-
'''' For queries against PRAGMA functions, table_column_metadata
297-
'''' should return SQLITE_ERROR (no such table column...).
298-
''''
299-
'''' Make sure that relevant previous APIs did not return null pointers.
300-
'''' This issue occurs for calculated columns, but basic armor would cut
301-
'''' off this information for all columns.
302-
''''
303-
If DatabaseNamePtr <> 0 And TableNamePtr <> 0 And ColumnNamePtr <> 0 Then
304-
Dim NotNull As Long
305-
NotNull = False
306-
Dim PrimaryKey As Long
307-
PrimaryKey = False
308-
Dim AutoIncrement As Long
309-
AutoIncrement = False
310-
Dim CollationPtr As Variant: CollationPtr = 0 '''' RD workaround
311-
ResultCode = sqlite3_table_column_metadata(dbc.DbHandle, _
312-
DatabaseNamePtr, TableNamePtr, ColumnNamePtr, _
313-
DataTypePtr, CollationPtr, NotNull, PrimaryKey, AutoIncrement)
314-
If ResultCode = SQLITE_OK And DataTypePtr <> 0 And CollationPtr <> 0 Then
315-
.DeclaredTypeT = UTFlib.StrFromUTF8Ptr(DataTypePtr)
316-
.Collation = UTFlib.StrFromUTF8Ptr(CollationPtr)
317-
.NotNull = CBool(NotNull)
318-
.PrimaryKey = CBool(PrimaryKey)
319-
.AutoIncrement = CBool(AutoIncrement)
320-
Else
321-
ResultCode = dbc.ErrInfoRetrieve
322-
End If
281+
'''' For queries against PRAGMA functions, table_column_metadata
282+
'''' should return SQLITE_ERROR (no such table column...).
283+
''''
284+
'''' Make sure that relevant previous APIs did not return null pointers.
285+
''''
286+
If DatabaseNamePtr <> 0 And TableNamePtr <> 0 And _
287+
ColumnNamePtr <> 0 And DataTypePtr <> 0 Then
288+
Dim NotNull As Long
289+
NotNull = False
290+
Dim PrimaryKey As Long
291+
PrimaryKey = False
292+
Dim AutoIncrement As Long
293+
AutoIncrement = False
294+
Dim CollationPtr As Variant: CollationPtr = 0 '''' RD workaround
295+
ResultCode = sqlite3_table_column_metadata(dbc.DbHandle, _
296+
DatabaseNamePtr, TableNamePtr, ColumnNamePtr, _
297+
DataTypePtr, CollationPtr, NotNull, PrimaryKey, AutoIncrement)
298+
If ResultCode = SQLITE_OK And DataTypePtr <> 0 And CollationPtr <> 0 Then
299+
.DeclaredTypeT = UTFlib.StrFromUTF8Ptr(DataTypePtr)
300+
.Collation = UTFlib.StrFromUTF8Ptr(CollationPtr)
301+
.NotNull = CBool(NotNull)
302+
.PrimaryKey = CBool(PrimaryKey)
303+
.AutoIncrement = CBool(AutoIncrement)
304+
Else
305+
ResultCode = dbc.ErrInfoRetrieve
323306
End If
324307
End If
325308
End With

Project/SQLite/C/Statement/SQLiteCStatementTests.bas

+1-6
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ End Sub
625625

626626

627627
'@TestMethod("Query 2D RowSet")
628-
Private Sub ztcGetRowSet2D_SelectPragmaTableWithUseTableMetadataAPI()
628+
Private Sub ztcGetRowSet2D_SelectPragmaTable()
629629
On Error GoTo TestFail
630630
TestCounter = TestCounter + 1
631631

@@ -646,11 +646,6 @@ Act:
646646
SQLQuery = FixSQLFunc.SelectPragmaNoRowid
647647
Dim RowSet2D As Variant
648648
Assert:
649-
dbs.DbExecutor.UseTableMetaAPI = True
650-
RowSet2D = dbs.GetRowSet2D(SQLQuery)
651-
Assert.IsTrue IsError(RowSet2D), "Expected an error from RowSet2D."
652-
Assert.AreEqual CVErr(SQLITE_ERROR), RowSet2D, "Expected SQLITE_RANGE error."
653-
dbs.DbExecutor.UseTableMetaAPI = False
654649
RowSet2D = dbs.GetRowSet2D(SQLQuery)
655650
Assert.IsFalse IsError(RowSet2D), "Unexpected error from RowSet2D."
656651
Assert.IsTrue IsArray(RowSet2D), "Expected a rowset result."

SQLiteCAdoReflectVBAdev.xls

10.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)