I am trying to write a simple SQL database viewer and have solved most problems but I an stuck on how to get items into the columns of the listview gadget.
The problem is that the number of columns will change with different Databases.
I can create the number of columns in the listview gadget dynamically, just can not get the dat in.
This is the function I have
Code: Select all
Global tablename$ ; Table Name
Global DB$ ; Database Name
Global RD = {} ; Record Data
;Field[] = field names
;count = number of fields in DB Table
;fieldlist string of all columns in Table
Function p_GetDBRecord() ; ******************************************************************************
db = sqlite3.open(DB$)
For row In db:nrows("SELECT * FROM " .. tablename$ )
For Info = 0 To Count-1
RD[Info] = row[""..field[Info].. ""]
fieldlist$ = fieldlist$ .."\""..rd[Info].."\", "
Next
len = StrLen(fieldlist$)
fieldlist$ = MidStr(fieldlist$,0,len-2)
moai.DoMethod("dbinfo","insert","bottom",fieldlist$)
fieldlist$ = ""
Next
db:close()
EndFunction
If I hard code the fieldlist$,
ie. list all the columns I have in the database
moai.DoMethod("dbinfo","insert","bottom",RD[1],RD[2],rd[3], .....) for all the fields it works
but as the number of fields in different databases will have different numbers of fields that will not work.
I tried to create a string of the columns ie fieldlist$ = fieldlist$ .."\""..rd[Info].."\", "
but I get an error string expected in agument 5. - in Function DoMethod
Does anyone know how i can represent all the columns of the listview as a table or string that moai.DoMethod will not throw up an error with.
Thanks