On Oct 5, 2004, at 22:27, Will Leshner wrote:
Tito Ciuro wrote:
3) Then I parse the CREATE TABLE... statement and separate columns from datatypes.
You can look for INTEGER PRIMARY KEY. Would that work for you?
In practice, how safe is it to parse the CREATE SQL?
How safe? Depends on the situation, I guess. If your program creates the tables, you can assume certain things, such as whether you create tables with or without CONSTRAINT, for example. However, if the database has been created elsewhere, it'll could be tough to determine what the columns/datatypes are. One simple statement may look like this:
create table Drug (DrugName varchar(32), TradeName varchar(32), Formulation varchar(10), SizeMg decimal(7,3));
A not-so simple one could look like this:
create table Drug (DrugID decimal(9,0), constraint drug_ID_null check (DrugID is not null), DrugName varchar(32), TradeName varchar(32) default 'Generic' , Formulation varchar(10), SizeMg decimal(7,3));
Unless, of course, you have a full SQL parser at your disposal.
You're right, but if Kirk can assume the structure of the SQL statement that created the table, parsing will work. Otherwise, since SQLite does not provide a way to break the info down for you, parsing the SQL statement could become more Voodoo than anything else...
-- Tito

