SQLite: SQL for reading field names
Posted: Mon May 30, 2011 10:10 pm
This is the code from my CRUD SQLite Example.
Amazing! Only 10 lines of code!
No matter how many fields are in the table--
LiveCode fully populates DataGrid.
Note: "Connected()" is a function that checks for an active connection
But column names are created as: "column1, column2, etc."
This code could be better, if afterwards, it could then do a second SQL query,
to read all the field names in the table, then update the DataGrid column headings.
To do this, there's two things I'm stuck on.
1- The SQL to query to read all field names in a table.
2- How to reference the individual DataGrid column headers directly.
In this way, my CRUD SQLite Example code, would be able to take
any table name and populate DataGrid with field proper names.
Amazing! Only 10 lines of code!
No matter how many fields are in the table--
LiveCode fully populates DataGrid.
Code: Select all
on doRead ----------------------------------------------------------
if not Connected() then exit to top
try
put "SELECT * FROM users" into tSQL
put revdb_querylist(,,gConID,tSQL) into ptext
set the dgText of group "myGrid" to ptext
catch theError
answer warning theError
end try
end doRead
But column names are created as: "column1, column2, etc."
This code could be better, if afterwards, it could then do a second SQL query,
to read all the field names in the table, then update the DataGrid column headings.
To do this, there's two things I'm stuck on.
1- The SQL to query to read all field names in a table.
2- How to reference the individual DataGrid column headers directly.
In this way, my CRUD SQLite Example code, would be able to take
any table name and populate DataGrid with field proper names.