[Gambas-user] How do I get the names of fields with unknown names?

paulwheeler paulwheeler at ...546...
Sat Nov 23 19:25:15 CET 2013


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. [0]

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




More information about the User mailing list