Thread

Posted on Thu Feb 14 19:06:25 2008 by jpolache
create database, check for table
I am using DBD::SQLite in a perl script and am very happy with it. I would like to add the capability to check at script start if the database exists, and if not, create it and the same with the one table the script requires. I looked at perldoc DBD:SQLite and perldoc DBI but if the answer was there I missed it. Any hints?
Direct Responses: 7107 | Write a response
Posted on Thu Feb 14 22:21:51 2008 by dougmcq in response to 7106
Re: create database, check for table
Try technique @ http://www.perlmeme.org/faqs/file_io/directory_listing.html Doug
Direct Responses: 7108 | Write a response
Posted on Thu Feb 14 23:38:05 2008 by jpolache in response to 7107
Re: create database, check for table
Check for the file that represents the database. I guess that was to obvious for me to think of. OK, so the next step would be to create the database from within the script if it does not already exist. As far as I can tell, the way to create a SQLite database is to call the sqlite3.exe [DBNAME] from the command line. I could use a system call from within the script (system("sqlite3 [DBNAME]";) but how would I send .quit to stop the utility? Is there something else obvious I'm missing?
Direct Responses: 7112 | Write a response
Posted on Fri Feb 15 14:53:52 2008 by dougmcq in response to 7108
Re: create database, check for table
See if sqlite3 supports a -f option (text file command stack). If so, have script build the text file then invoke sqlite3. PS - If file structure is 'known' might be easier to build a template DB then just copy it in with the script then start to populate
Write a response