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..
We will be using sys. columns to get the column names in a table. It is a system table and used for maintaining column information.
Column search A feature that can be used to search for column names in SQL Server is Object search. This feature allows users to find all SQL objects containing the specified phrase.
To get the column name of a table we use sp_help with the name of the object or table name. sp_columns returns all the column names of the object. The following query will return the table's column names: sp_columns @table_name = 'News'
To get the columns of a table, execute PRAGMA table_info(table_name)
:
PRAGMA table_info()
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With