I try get column list from Web sql (Chrome local database). Оne of the decisions - get info from sqlite_master
SELECT name, sql FROM sqlite_master WHERE type="table" AND name = "'+name+'";
For example i get this result
CREATE TABLE table_name ( id INTEGER PRIMARY KEY AUTOINCREMENT,
number INTEGER unique, description TEXT, password TEXT, url TEXT )
So help me write regex for get column names, or, maybe, show me another simple way get column names.
PS. i dont wont to do select * from table
... for getting columns names. I think this is bad solution..
To get the columns of a table, execute PRAGMA table_info(table_name)
:
Return a single row for each column of the named table. The columns of the returned data set are:
- cid: Column id (numbered from left to right, starting at 0)
- name: Column name
- type: Column declaration type.
- notnull: True if '
NOT NULL
' is part of column declaration- dflt_value: The default value for the column, if any.
Unfortunately, Chrome blocks all PRAGMA
s, so this doesn't work in WebSQL.
In WebSQL, you can access only tables that were created by your app, so you should just remember which columns your tables have.
Alternatively, you can just try to read from the table:
SELECT * FROM table_name LIMIT 1
With the LIMIT
clause, this will be very efficient because you read only some random record. (Except if you have some very big blob in that record.)