Since SQLite is type agnostic why don't you use generic field names?


Just name your fields 0-NN and keep a set of defines for field names.



Then you just use #define to name the fields.



create table mytable (field1,field2,field3,field4);



#define NAME "field1"

#define ADDR "field2"

#define CITY "field3"

#define ZIP "field4"



All you need to do is put quotes around the field names (note: it's actually 
just separate strings but putting quotes around the field names is the visual 
effect and easier to think about).

char *sql = "select "NAME" from mytable where "ZIP" like '3%'";



sql will then contain:

select field1 from mytable where field4 like '3%'



Dropping fields from your defines will automatically give you syntax errors 
during compilation as long as you don't name your new fields the same as ones 
you just deleted (can you say long-term maintenance?).





This is something you can't do with a strongly-typed database.







Michael D. Black

Senior Scientist

NG Information Systems

Advanced Analytics Directorate



________________________________
From: sqlite-users-boun...@sqlite.org [sqlite-users-boun...@sqlite.org] on 
behalf of Jack Hughes [jhug...@openxtra.co.uk]
Sent: Tuesday, August 02, 2011 6:03 AM
To: General Discussion of SQLite Database
Subject: EXT :[sqlite] Field drop work around

Hello all,

Is there a workaround for the lack of support for dropping fields? I have an 
application and need to evolve the database schema as features are added and 
removed. Leaving fields sitting inside the database that are no longer used 
will lead to a schema that is difficult to understand. Especially so when the 
field is marked as NOT NULL. Years from now I will need to supply a value for a 
field when inserting a row that has long ago ceased to be used.

Any ideas how I can remove unused fields from the database would be appreciated.

Regards,

Jack Hughes

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to