On Saturday, 4 August, 2018 20:01, Stephen Chrzanowski <pontia...@gmail.com> 
wrote:

>I was right.  I got the tables done before a response.  But still
>would like to know if there's a SQLite method of doing so.

Of course there is.

>My method was to use a templating application that I wrote at work. I
>give it this variable declaration:

There is not really that much difference between using program (a) -vs- program 
(b) to generate the text file containing the SQL statements.  I do not know why 
you would want to do it in SQL since that would still require a custom program, 
programmed in whatever language the custom program is going to be written in, 
plus writing the SQL itself -- effectively at least doubling (and likely more) 
the effort.  It might be "cool" but it is complicated and brittle.  KISS is 
sorely missing in computer programming these days.  I can do it in about 4 
lines of Python which will take but a few seconds to write....

>Name=Resource

>I then give it this text:

>CREATE TABLE [%(Name)s]( [%(Name)ID] INTEGER PRIMARY KEY
>AUTOINCREMENT,
>[%(Name)Name] CHAR NOT NULL, UNIQUE([%(Name)Name]));
>CREATE UNIQUE INDEX [u%(Name)Name] ON [%(Name)s]([%(Name)Name]);

>It then gives me this result:

>CREATE TABLE [Resources]( [ResourceID] INTEGER PRIMARY KEY
>AUTOINCREMENT,
>[ResourceName] CHAR NOT NULL, UNIQUE([ResourceName]));
>CREATE UNIQUE INDEX [uResourceName] ON [Resources]([ResourceName]);

1) Why are you using AUTOINCREMENT?
2) The datatype CHAR does not exist.  The correct name is TEXT
3) Why are you creating a separate UNIQUE constraint rather than just 
specifying the column as UNIQUE?
4) Are you sure the text string is case sensitive for comparisons rather than 
merely case-preserving (that is, did you forget COLLATE NOCASE)?
5) You should not be creating duplicate UNIQUE indexes.

CREATE TABLE Resources (ResourceID INTEGER PRIMARY KEY, ResourceName TEXT NOT 
NULL UNIQUE);

is all you need.

>Repeat for each simple table I want, and things were done in just a
>couple of minutes.  Its a very basic template engine (Automatic Search &
>Replace until no keyword strings exist), but it takes big chunks of time off
>when we do upgrades to our 100+ servers around the world.

>BUT, if I could have the SQL version be provided a list of names, it
>goes and loops through repeating whatever processes I need based on that
>name for that loop, and creates the structures I'd need later on in life.
>;)

---
The fact that there's a Highway to Hell but only a Stairway to Heaven says a 
lot about anticipated traffic volume.




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

Reply via email to