This is code I used a while ago. Don't use it anymore as I have a better
way to do this via my VB wrapper. There are some lines that deal with code
in other parts of my application, but I take it you can see that.
In case you didn't know this is VB(A).

Function GetSQLiteTableInfo2(strDB As String, _
                             strTable As String, _
                             Optional strSelect As String, _
                             Optional strOmitFields As String, _
                             Optional strAlias As String, _
                             Optional strFields As String, _
                             Optional strDataTypes As String, _
                             Optional bCurrentConnection As Boolean) As
String()

         'will produce the table fields as an 0-based 1-D array
         'and make the strings:
         'field1,field2,field3 etc.
         'field1, field2, field3 etc.
         'datatype1,datatype2,datatype3 etc.
         '------------------------------------------------------
         Dim r As Long
         Dim c As Long
         Dim strSQL As String
         Dim arr
         Dim arr2
         Dim arr3
         Dim strAlias2 As String
         Dim arrOmitFields
         Dim bOmit As Boolean
         Dim bDoneFirst As Boolean
         Dim lRows As Long
         Dim strError As String
         Dim lDBHandle As Long

10       If Len(strAlias) > 0 Then
20          strAlias2 = strAlias & "."
30       End If

40       If Len(strOmitFields) > 0 Then
50          arrOmitFields = Split(strOmitFields, ",")
60          bOmit = True
70       End If

80       If bShowErrors Then
90          On Error GoTo 0
100      Else
110         On Error GoTo ERROROUT
120      End If

130      If bCurrentConnection = False Then
140         OpenDB strDB
150      End If

160      strSQL = "pragma table_info('" & strTable & "')"
170      arr = GetFromDB(strSQL, lRows, strError, strDB)

180      If lRows = -1 Then
190         GoTo ERROROUT
200      End If

210      If bOmit Then
220         For c = 0 To UBound(arr)
230            If ValueIn1DArray(CStr(c + 1), arrOmitFields) = -1 Then
240               If bDoneFirst = False Then
250                  strSelect = strAlias2 & arr(c, 1)
260                  strFields = arr(c, 1)
270                  strDataTypes = arr(c, 2)
280                  bDoneFirst = True
290               Else
300                  strSelect = strSelect & ", " & strAlias2 & arr(c, 1)
310                  strFields = strFields & "," & arr(c, 1)
320                  strDataTypes = strDataTypes & "," & arr(c, 2)
330               End If
340            End If
350         Next
360      Else
370         For c = 0 To UBound(arr)
380            If c = 0 Then
390               strFields = arr(c, 1)
400               strSelect = strAlias2 & arr(c, 1)
410               strDataTypes = arr(c, 2)
420            Else
430               strFields = strFields & "," & arr(c, 1)
440               strSelect = strSelect & ", " & strAlias2 & arr(c, 1)
450               strDataTypes = strDataTypes & "," & arr(c, 2)
460            End If
470         Next
480      End If

490      arr2 = Split(strFields, ",")

500      ReDim arr3(0 To UBound(arr2)) As String

510      For r = 0 To UBound(arr2)
520         arr3(r) = arr2(r)
530      Next

540      GetSQLiteTableInfo2 = arr3

550      Exit Function
ERROROUT:

560      ReDim arr2(0 To 6) As String
570      arr2(0) = "-1"
580      arr2(1) = CStr(Err.Number)
590      arr2(2) = Err.Description
600      arr2(3) = CStr(Erl)
610      arr2(4) = strTable
620      arr2(5) = strOmitFields
630      arr2(6) = strAlias

650      GetSQLiteTableInfo2 = arr2

End Function


Have a nice Christmas as well.


RBS


-----Original Message-----
From: Cesar D. Rodas [mailto:[EMAIL PROTECTED] 
Sent: 25 December 2007 01:35
To: sqlite-users@sqlite.org
Subject: [sqlite] Helping with table definition?

Hello,

Merry Christmas for every one!

I am wondering if someone did a function (the language doesn't care very
much) to get the table information and want to share him/her code.

I know that you can have the SQL definition of a table doing a "select *
from sqlite_master where type='table' ", but I need to parse SQL and
understand it.

Thanks in advance.

-- 
Best Regards

Cesar D. Rodas
http://www.cesarodas.com
http://www.thyphp.com
http://www.phpajax.org
Phone: +595-961-974165



-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to