Riporto di seguito questa discussione apparsa nella M.L. ufficiale:
" I am trying to get a list of the tables in a SQLite database.
According to SQLite.org the table called "sqlite_master" lists all the tables and indices in the DB[1]. I have a SQlite browser tool that seems to confirm that, because it returns table names from the target DB, when this is executed: SELECT 'tables' from SQLITE_MASTER
My problem is getting the table names and the fields in each of the tables of a Database with an unknown structure. For this project, I do not know the name of the fields, because I am looking at DB's created by someone else. That means that the example included in the definition of "For Each" will not work.
Using Gambas, I connect to the SQlite database, then do a query:
Public Sub DisplayDbInfo()
Dim strDbTablesQuery As String ' The string that is the select statement
Dim rsDbTableInfo As Result
strDbTablesQuery = "Select name From sqlite_master WHERE type = 'table' ORDER BY name"
rsDbTableInfo = $hConn.Exec(strDbTablesQuery)
' For debugging:
Print "Num of Tables = " & rsDbTableInfo.Count ' 9 Tables
Print "rsDbTableInfo.max = " & rsDbTableInfo.Max ' 8
Print "Num of Fields returned = " & rsDbTableInfo.Fields.Count
For intCount = 0 To rsDbTableInfo.Fields.Count - 1 ' Number of Fields found
Print "rsDbTableInfo.Fields[i] = " & Str(rsDbTableInfo.Fields[intCount])
Next
However, all I get from the previous lines is this: (ResultField 0x1aa6718).
I tried using 'Result', 'ResultField', 'Result.Felds' and other things, but I cannot get field names.
How do I get the actual name of the field?
paul "
" Salut Paul,
this is out from DB-diff3 (you can get the whole code from here : http://dashboard68.users.sourceforge.net/ )
Private Function fill_Fields(tbl As Table) As Collection
Dim fld As Field
Dim sKeyPraefix As String = tbl.Name & sSep & "FIELDS" & sSep
Dim colFields As New Collection
Dim clsFld As ClsFields
Dim sPKey As String
For Each fld In tbl.Fields
sPKey = Upper(sKeyPraefix & fld.Name)
clsFld = New ClsFields
clsFld.Key = sPKey
clsFld.fldDefault = fld.Default
clsFld.fldLength = fld.Length
clsFld.fldName = fld.Name
clsFld.fldTable = fld.Table
clsFld.fldType = fld.Type
colFields.Add(clsFld, sPKey)
Next
Return colFields
End
--
Amicalement
Charlie "