Posted: Fri Aug 29, 2008 2:28 pm
Can SQLiteColName be made to work with prepare/step method? I'd like to be able to return the column name with my results. Tried a few things, no joy.
*EDIT** Been playing with this a little and noticed some things are backwards and need some clarification.
A "column" is a column across >>>>>
A "row" is a line down (a row down) right?
You definitions seem to be done backwards. Regardless, I cannot seem to get the column names with the included routine below. It seems to return column definitions and not column names, no matter what I do to it??
Try this code and tell me where I have gone wrong please.
Code: Select all
lStatement = SQLitePrepare(DbHandle.l, "SELECT * FROM tableName WHERE record='" + Record.s + "'")
If lStatement
While SQLiteStep(lStatement) <> #False
Debug SQLiteColumnText(lStatement, 0)
Debug SQLiteColName(*Table.SQ3_TABLEMAP, 0) ; Is this possible?
Wend
SQLiteFinalize(lStatement) = #False
EndIf
A "column" is a column across >>>>>
A "row" is a line down (a row down) right?
You definitions seem to be done backwards. Regardless, I cannot seem to get the column names with the included routine below. It seems to return column definitions and not column names, no matter what I do to it??
Code: Select all
Procedure.s SQLiteColName(*Table.SQ3_TABLEMAP, Col.l)
Protected *val.l
If *Table
If Col > 0 And Col <= *Table\Cols
*val.l = PeekL(*Table\Table + ((Col - 1) * 4))
If *val
ProcedureReturn PeekS(*val, #PB_Any, SQ3\PeekMode)
EndIf
EndIf
EndIf
ProcedureReturn ""
EndProcedure
Try this code and tell me where I have gone wrong please.
Code: Select all
; Any specific modules that have to load first
XIncludeFile "C:\Development\Resources\Modules\Ts_Soft\_SqLite3Base.pbi" ; Prototype function declarations
; Initialise the SQLite3.x library and environment
SQLiteInit("C:\Development\Resources\Libraries\sqlite3upxl.dll") ; Load the external sqlite library
; Main program code
Define.SQ3_TABLEMAP Table
DbHandle.l = SQLiteOpen("D:\testicle.db", #True)
If DbHandle.l
;--------------------------------------------------------------------------
; Testing to see if I can get the number of columns first, then get the
; of the columns,
;--------------------------------------------------------------------------
Table.SQ3_TABLEMAP
SQLiteGetTable(DbHandle.l, "PRAGMA table_info(inventory)", Table) ; Works properly
; Debug SQLiteCols(Table) ; Rows down, not cols across!!!. This is backwards
sqliteCols = SQLiteRows(Table) ; Columns across, not rows down!!!. This is backwards. Gets the correct count of cols now
;--------------------------------------------------------------------------
; Get the column names from the table, jsut to prove that I can. Didn't work
;--------------------------------------------------------------------------
For ColNames = 0 To sqliteCols
Debug SQLiteColName(Table, ColNames.l) ; Returns column definitions, not column names???
Next ColNames
;--------------------------------------------------------------------------
; Don't free the table just yet, need column name from it
;--------------------------------------------------------------------------
; SQliteFreeTable(Table)
;**************************************************************************************************************
;--------------------------------------------------------------------------
; No problems with the below routine.
;--------------------------------------------------------------------------
lStatement = SQLitePrepare(DbHandle.l, "SELECT * FROM inventory WHERE record=2")
If lStatement
While SQLiteStep(lStatement) <> #False
For ColsAcross = 0 To sqliteCols
;--------------------------------------------------------------------------
; Returning the text in the columns
;--------------------------------------------------------------------------
Debug SQLiteColumnText(lStatement, ColsAcross) ; Doing this
;--------------------------------------------------------------------------
; Want to return the column name with the column text
;--------------------------------------------------------------------------
; Debug SQLiteColName(*Table.SQ3_TABLEMAP, ColsAcross.l) + ": " + SQLiteColumnText(lStatement, ColsAcross)
Next ColsAcross
Wend
;--------------------------------------------------------------------------
; Finalise the statement
;--------------------------------------------------------------------------
If SQLiteFinalize(lStatement) = #False
Debug SQLiteErrorMsg(DbHandle.l)
EndIf
EndIf
EndIf
;--------------------------------------------------------------------------
; Now free the table
;--------------------------------------------------------------------------
SQliteFreeTable(Table) ; Now free table, got everything I wanted
End