[sqlite] Creating SQLite database from other databases
I was wondering if there is a good way to create SQLite databases from either SQL Server or FoxPro? Thanks. CONFIDENTIALITY NOTICE: This email message, including any attachments, is for the use of the intended recipient(s) only and may contain information that is privileged, confidential, and prohibited from unauthorized disclosure under applicable law. If you are not the intended recipient of this message, any dissemination, distribution, or copying of this message is strictly prohibited. If you received this message in error, please notify the sender by reply email and destroy all copies of the original message and attachments. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Creating a database with a script or SQLite command
I have a need to create a database if it doesn't already exist. The obvious solution is to just use: sqlite3 newdatabase.db Except that it not only creates the db but also opens that db for commands. I am running this from a script so I want to just want to run the command from a script so that I know the database exists before issuing other commands. I searched around the Internet for what I thought would be an easy answer and didn't find one. I am running SQLite 3.3.13 from BusyBox 1.1.3 Thanks -- Pete Helgren Value Added Software, Inc www.asaap.com www.opensource4i.com ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Creating a database with a script or SQLite command
On 31 Aug 2011, at 2:36am, Pete Helgren wrote: I have a need to create a database if it doesn't already exist. The obvious solution is to just use: sqlite3 newdatabase.db Except that it not only creates the db but also opens that db for commands. Make yourself an empty database file and keep it somewhere safe. When you need a new one just copy this existing file, and rename and/or move it to the right folder. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Creating a database with a script or SQLite command
Thanks. I'll add a little more info This script is used to set up the initial DB in a programmable device that will then record data to the database and the database should never be replaced. So I just figured there would be a simple way to issue the sqlite commands in script. Even found an example using a createdb command, although I could never see where that was an SQLite command So, you suggest I script it like so: if [ -f /data/newdatabase.db]; then echo Nothing to do, database exists else cp newdatabase.db /data/newdatabase.db fi I am not much of a Linux guy so the scripting might be wrong. Pete Helgren Value Added Software, Inc www.asaap.com www.opensource4i.com On 8/30/2011 7:38 PM, Simon Slavin wrote: On 31 Aug 2011, at 2:36am, Pete Helgren wrote: I have a need to create a database if it doesn't already exist. The obvious solution is to just use: sqlite3 newdatabase.db Except that it not only creates the db but also opens that db for commands. Make yourself an empty database file and keep it somewhere safe. When you need a new one just copy this existing file, and rename and/or move it to the right folder. Simon. ___ 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
Re: [sqlite] Creating a database with a script or SQLite command
Pete Helgren p...@valadd.com wrote: I have a need to create a database if it doesn't already exist. The obvious solution is to just use: sqlite3 newdatabase.db Except that it not only creates the db but also opens that db for commands. I am running this from a script so I want to just want to run the command from a script so that I know the database exists before issuing other commands. Try something like echo .exit | sqlite3 newdatabase.db -- Igor Tandetnik ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Creating a database with a script or SQLite command
On 31 Aug 2011, at 2:53am, Pete Helgren wrote: Thanks. I'll add a little more info This script is used to set up the initial DB in a programmable device that will then record data to the database and the database should never be replaced. So I just figured there would be a simple way to issue the sqlite commands in script. The mechanism in SQLite which creates a database is to open one that doesn't exist. There's no command or C function which just makes a database without opening it. You could, of course, hack that functionality out of the source code but I think that's a poor solution. Even found an example using a createdb command, although I could never see where that was an SQLite command So, you suggest I script it like so: if [ -f /data/newdatabase.db]; then echo Nothing to do, database exists else cp newdatabase.db /data/newdatabase.db fi I am not much of a Linux guy so the scripting might be wrong. That would do fine. But as a single-command alternative you could use 'cp -n': cp -n newdatabase.db /data/newdatabase.db the '-n' means 'don't replace an existing file'. I tested it on my Unix box. I believe it's implemented in Linux, but you should definitely test it because I don't have Linux here. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Creating a database with a script or SQLite command
Forgot to mention: copying an existing database file also lets you set up the file the way you want without having to issue separate commands. For instance, you could create blank tables. Or set a specific page size. Or include some sort of DRM or security check in the 'blank' file. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Creating a database with a script or SQLite command
On Tue, Aug 30, 2011 at 09:54:21PM -0400, Igor Tandetnik scratched on the wall: Pete Helgren p...@valadd.com wrote: I have a need to create a database if it doesn't already exist. The obvious solution is to just use: sqlite3 newdatabase.db Except that it not only creates the db but also opens that db for commands. I am running this from a script so I want to just want to run the command from a script so that I know the database exists before issuing other commands. Try something like echo .exit | sqlite3 newdatabase.db Except that won't work**, since creating the database file is a lazy operation. There are several ways to force the creation of a zero-byte file (open/commit a transaction, for example), but that can be done with something as simple as touch(1). Creating the file and writing the full database header (making it a recognizable SQLite file) requires putting something into the sqlite3_master table (e.g. creating a user-defined table). This could be done with any CREATE TABLE IF NOT EXISTS... statement. Of course, I'm not sure what the big deal is. By default, if you attempt to open an SQLite database file that does not exist, the system will just go ahead and create it. This sounds like exactly the desired behavior. There is no need to pre-create the file. Assuming the start-up process continues with a series of CREATE TABLE IF NOT EXISTS... statements, a new database will have the file created and defined, while an existing database will create/ignore the tables depending on the existing structure. ** Who are you, and what did you do with Igor? -j -- Jay A. Kreibich J A Y @ K R E I B I.C H Intelligence is like underwear: it is important that you have it, but showing it to the wrong people has the tendency to make them feel uncomfortable. -- Angela Johnson ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Creating a database with a script or SQLite command
The only issue I had was finding an example of how I could do all of what you describe below in bash script. For example, if I put this in a script: sqlite3 newdatabase.db and save that as createdb.sh and execute it then the script never completes because SQLite is at the sqlite prompt, waiting for commands. Hence that option is a non-starter. Pete Helgren Value Added Software, Inc www.asaap.com www.opensource4i.com On 8/30/2011 8:23 PM, Jay A. Kreibich wrote: Of course, I'm not sure what the big deal is. By default, if you attempt to open an SQLite database file that does not exist, the system will just go ahead and create it. This sounds like exactly the desired behavior. There is no need to pre-create the file. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Creating a database with a script or SQLite command
I may end up going this direction, at the moment I am not having much luck with the conditional copy in Busybox. Your suggestion: cp -n newdatabase.db /data/newdatabase.db Isn't supported in the version of Busybox that I am running. Also the script example I tried: if [ -f /data/newdatabase.db]; then echo Nothing to do, database exists else cp newdatabase.db /data/newdatabase.db fi delivers the error [:missing] So I'll have to work through the scripting. Sure would be nice to have something like sqlite3 newdatabase.db .exit work so that it would just create the DB and exit Pete Helgren Value Added Software, Inc www.asaap.com www.opensource4i.com On 8/30/2011 8:14 PM, Simon Slavin wrote: Forgot to mention: copying an existing database file also lets you set up the file the way you want without having to issue separate commands. For instance, you could create blank tables. Or set a specific page size. Or include some sort of DRM or security check in the 'blank' file. Simon. ___ 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
Re: [sqlite] Creating a database with a script or SQLite command
On Tue, Aug 30, 2011 at 08:29:06PM -0600, Pete Helgren scratched on the wall: The only issue I had was finding an example of how I could do all of what you describe below in bash script. For example, if I put this in a script: sqlite3 newdatabase.db and save that as createdb.sh and execute it then the script never completes because SQLite is at the sqlite prompt, waiting for commands. Hence that option is a non-starter. You need to give sqlite3 a command, or it will go into interactive mode. That's how the shell is designed to work. You can do this, however: $ sqlite3 newdatabase.db .exit The existence of the command will cause sqlite3 to execute the command and quit, without going into interactive mode. As I explained before, this specific example won't actually create a database file, however. I suppose you could do something this: sqlite3 newdatabase.db CREATE TABLE IF NOT EXISTS ... sqlite3 newdatabase.db CREATE TABLE IF NOT EXISTS ... ... But that seems a bit wasteful. If you want to do all your initialization in one pass, I would do something like this: sqlite3 newdatabase.db EOF CREATE TABLE IF NOT EXISTS t1 ( a, b, c ); CREATE TABLE IF NOT EXISTS t2 ( d, e, f ); EOF -j -- Jay A. Kreibich J A Y @ K R E I B I.C H Intelligence is like underwear: it is important that you have it, but showing it to the wrong people has the tendency to make them feel uncomfortable. -- Angela Johnson ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Creating a database with a script or SQLite command
On 31 Aug 2011, at 3:53am, Pete Helgren wrote: I may end up going this direction, at the moment I am not having much luck with the conditional copy in Busybox. Your suggestion: cp -n newdatabase.db /data/newdatabase.db Isn't supported in the version of Busybox that I am running. Oh, you're running BusyBox, not a standard shell. okay, well here's a doc for BusyBox: http://busybox.net/downloads/BusyBox.html see whether cp will overwrite without any options set. Try it out. See what happens. Simon. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Creating a database with a script or SQLite command
Pete Helgren writes: I may end up going this direction, at the moment I am not having much luck with the conditional copy in Busybox. Your suggestion: cp -n newdatabase.db /data/newdatabase.db Isn't supported in the version of Busybox that I am running. Also the script example I tried: if [ -f /data/newdatabase.db]; then echo Nothing to do, database exists else cp newdatabase.db /data/newdatabase.db fi delivers the error [:missing] The primary token delimiter in POSIX Shell is space. Hence, the following line: if [ -f /data/newdatabase.db]; Is understood as: “check if the file ‘/data/newdatabase.db]’ exists” (note the closing bracket), and it certainly lacks a closing bracket for the ‘test’ (AKA ‘[’) command. The solution would be as follows: - if [ -f /data/newdatabase.db]; + if [ -f /data/newdatabase.db ]; OTOH, the when the ‘test’ form of the command is used, closing bracket is not necessary, thus: if test -f /data/newdatabase.db ; Please also consider joining the news:comp.unix.shell newsgroup (e. g., on Aioe, nntp://aioe.org/comp.unix.shell/), as there're quite a few folks familiar with the arcane art of Unix Shell programming. (AFAIK, Thunderbird has the support for the Internet News service.) […] -- FSF associate member #7257 Coming soon: Software Freedom Day http://mail.sf-day.org/lists/listinfo/ planning-ru (ru), sfd-discuss (en) ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Creating a database.
I know this is a fundamental question, but in the book I'm using to learn SQLite, there is no reference that I can find for what one needs to do to create a database. I thought that simply using a CREATE statement with a database name included might do the trick, but alas it does not. I went to the SQLite website and under the SQLite in 5 minutes page it says to simply do this (after downloading the appropriate files, which I did) at the dos prompt: SQLite3 test.db When I tried it, I received this back: SQLite version 3.7.3 Enter .help for instructions Enter SQL statements terminated with a ; sqlite I quit out of the SQLite shell and looked for test.db and did not find it. So my question remains. How do I create a database? R, John A.M. Darnell Senior Programmer Walsworth Publishing Company Brookfield, MO John may also be reached at johnamdarn...@gmail.commailto:johnamdarn...@gmail.com Trivia SF question: In the movie, THE MATRIX, just before Neo and Trinity take a harrowing ride up an elevator shaft holding on to an elevator cable, Neo mutters a single phrase. What is that phrase? ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Creating a database.
On Tue, Nov 30, 2010 at 10:40:52AM -0600, john darnell scratched on the wall: I know this is a fundamental question, but in the book I'm using to learn SQLite, there is no reference that I can find for what one needs to do to create a database. I thought that simply using a CREATE statement with a database name included might do the trick, but alas it does not. From code, you use sqlite3_open_v2( ). See the docs for specifics: http://sqlite.org/c3ref/open.html From the shell, you just access a non-existent file. I went to the SQLite website and under the SQLite in 5 minutes page it says to simply do this (after downloading the appropriate files, which I did) at the dos prompt: SQLite3 test.db When I tried it, I received this back: SQLite version 3.7.3 Enter .help for instructions Enter SQL statements terminated with a ; sqlite I quit out of the SQLite shell and looked for test.db and did not find it. So my question remains. How do I create a database? The SQLite library uses lazy file creation. There are a number of configuration parameters that become fixed once the database header is written to disk. As such, the actual file creation is delayed until it *must* be written. This gives you a chance to issue PRAGMA commands and setup the proper configuration after the database is open, but before the header is written. To force SQLite to actually write the database file to disk just issue a CREATE TABLE statement: CREATE TABLE t ( i ); -j -- Jay A. Kreibich J A Y @ K R E I B I.C H Intelligence is like underwear: it is important that you have it, but showing it to the wrong people has the tendency to make them feel uncomfortable. -- Angela Johnson ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] creating a database
Okay, I seem to have figured it out. One needs to create the database and then add a table before the database will be created. Sorry for the baby steps. R, John A.M. Darnell Senior Programmer Walsworth Publishing Company Brookfield, MO John may also be reached at johnamdarn...@gmail.commailto:johnamdarn...@gmail.com Trivia SF question: In the movie, THE MATRIX, just before Neo and Trinity take a harrowing ride up an elevator shaft holding on to an elevator cable, Neo mutters a single phrase. What is that phrase? ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Creating a Database from RealBasic code
This should be simple but does anyone know how to create a new database from within realbasic code? I try to shell out using the shell command but it's not liking that too much and there seems to be no create database function for sqlite. Dim s As Shell s= New Shell f = GetFolderItem() appPath=f.AbsolutePath 'appPath=app.ExecutableFile.Parent.AbsolutePath msgbox appPath #if TargetWin32 s.execute sqlite3.exe testdatabase.db 's.execute dir #endif If s.errorCode = 0 then msgbox done. else MsgBox Error code: + Str(s.errorCode) + chr(13) + s.result end if I get: Error code -2 Shell time out. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Creating a Database from RealBasic code
Hi Thomas, No need to shell out, you create from within the realbasic application. I'll pluck some example code and email it to you. Regards Denis On 04/23/2008 12:44 AM, Thomas E. Wright wrote: This should be simple but does anyone know how to create a new database from within realbasic code? I try to shell out using the shell command but it's not liking that too much and there seems to be no create database function for sqlite. Dim s As Shell s= New Shell f = GetFolderItem() appPath=f.AbsolutePath 'appPath=app.ExecutableFile.Parent.AbsolutePath msgbox appPath #if TargetWin32 s.execute sqlite3.exe testdatabase.db 's.execute dir #endif If s.errorCode = 0 then msgbox done. else MsgBox Error code: + Str(s.errorCode) + chr(13) + s.result end if I get: Error code -2 Shell time out. ___ 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
Re: [sqlite] Creating a Database from RealBasic code
Thanks Denis. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Denis Crowther Sent: Tuesday, April 22, 2008 10:54 AM To: General Discussion of SQLite Database Subject: Re: [sqlite] Creating a Database from RealBasic code Hi Thomas, No need to shell out, you create from within the realbasic application. I'll pluck some example code and email it to you. Regards Denis On 04/23/2008 12:44 AM, Thomas E. Wright wrote: This should be simple but does anyone know how to create a new database from within realbasic code? I try to shell out using the shell command but it's not liking that too much and there seems to be no create database function for sqlite. Dim s As Shell s= New Shell f = GetFolderItem() appPath=f.AbsolutePath 'appPath=app.ExecutableFile.Parent.AbsolutePath msgbox appPath #if TargetWin32 s.execute sqlite3.exe testdatabase.db 's.execute dir #endif If s.errorCode = 0 then msgbox done. else MsgBox Error code: + Str(s.errorCode) + chr(13) + s.result end if I get: Error code -2 Shell time out. ___ 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 ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Creating a database from inside a program
Rob Richardson wrote: So, I thought I could just issue the following command from inside my program: Sqlite3 newdatabase.db .read schemafile.txt But, when I issue this command from the DOS prompt, it gives me an error message saying that there is no command named read. Rob, You can pass your schema command file into sqlite in 3 ways. The first is using the -init option. sqlite3 -init schemafile.txt newdatabase.db The second is using input redirection. sqlite3 newdatabase.db schemafile.txt The third is supplying a read meta command on the command line. Note, you must quote the command so it gets passed to sqlite as a single string. sqlite3 newdatabase.db .read schemafile.txt HTH Dennis Cote - To unsubscribe, send email to [EMAIL PROTECTED] -
[sqlite] Creating a database from inside a program
Greetings! I need to be able to create a database with a known schema from inside a program. I used sqlite3.exe's .schema command to export the SQL needed to create the schema for my new database. I can create the database by the following steps: C:\: sqlite3 newdatabase.db Sqlite3 .read schemafile.txt At that point, my database is ready to go. But, sqlite3 is supposed to be able to accept commands on its command line. For example, the schema file was generated using this command: C:\: sqlite3 existingdatabase.db .schema schemafile.txt So, I thought I could just issue the following command from inside my program: Sqlite3 newdatabase.db .read schemafile.txt But, when I issue this command from the DOS prompt, it gives me an error message saying that there is no command named read. (Note the lack of a leading period.) If this won't work from a DOS prompt, I'm sure it won't work from my program. So, what is the recommended way to create a new database and its schema from inside a program? In case it matters, I'll be using Visual C# 2005 and the SQLite.net.dll file from SourceForge. Thank you very much! Rob Richardson RAD-CON INC.
Re: [sqlite] Creating a database from inside a program
Open the database as per normal with sqlite3_open(). Then issue the SQL commands necessary to create your schema. I have a nice little utility I wrote which will take an SQLite schema dump and convert it to an array of C strings that you can issue in sequence (and thanks to Microsoft for the technique). I've included the utility which converts an SQL export to C code. I'll let you work out the details for the rest. Clay Dowling Rob Richardson said: Greetings! I need to be able to create a database with a known schema from inside a program. I used sqlite3.exe's .schema command to export the SQL needed to create the schema for my new database. I can create the database by the following steps: C:\: sqlite3 newdatabase.db Sqlite3 .read schemafile.txt At that point, my database is ready to go. But, sqlite3 is supposed to be able to accept commands on its command line. For example, the schema file was generated using this command: C:\: sqlite3 existingdatabase.db .schema schemafile.txt So, I thought I could just issue the following command from inside my program: Sqlite3 newdatabase.db .read schemafile.txt But, when I issue this command from the DOS prompt, it gives me an error message saying that there is no command named read. (Note the lack of a leading period.) If this won't work from a DOS prompt, I'm sure it won't work from my program. So, what is the recommended way to create a new database and its schema from inside a program? In case it matters, I'll be using Visual C# 2005 and the SQLite.net.dll file from SourceForge. Thank you very much! Rob Richardson RAD-CON INC. -- Simple Content Management http://www.ceamus.com/* This file (c) Copyright 2004, 2005, 2006 Lazarus Internet Development * * Permission is given to use this source code for personal or * non-profit use free of charge, so long as this copyright is * maintained. You may use this source code for commercial use * so long as you have obtained a license from Lazarus Internet * Development. A license may be purchased by writing to * Clay Dowling [EMAIL PROTECTED] * * If you modify this source code and distribute it you must * indicate such in this header, and provide all support for * your modified version. * * $Id: sqlmodule.c 142 2006-05-28 17:43:28Z clay $ */ /* Create a C module which will return an array of strings, one for each * of the SQL statements in the passed file name * * This program runs on the SQL dumps/scripts produced by most SQL databases. * It's only requirement is that each statement ends with a semicolon (';'). * This rules out SQL Server, which terminates a statement with GO on a line * by itself. It should be a pretty easy adaptation though if such a feature * is needed. * * Comments and empty lines are ignored. * Lines with text are added to the array with a newline appended and * any single or double quotes escaped. * Lines which have a semi-colon cause a new array entry to be created */ #include stdio.h #include stdlib.h #include string.h #include ctype.h #define LINE_SIZE 2048 void markcomment(char*); const char* readline(FILE*); void escapeline(char*); void trim_trailing_space(char*); int main(int argc, char** argv) { FILE* in; FILE* out; char* filename; char* base; char* outfile; const char* line; if (argc == 1) { fprintf(stderr, usage: %s file.sql\n, argv[0]); return EXIT_FAILURE; } in = fopen(argv[1], r); if (!in) { perror(argv[1]); return EXIT_FAILURE; } filename = (char*)calloc(1, strlen(argv[1]) + 1); strcpy(filename, argv[1]); base = strrchr(filename, '.'); if (base) *base = '\0'; outfile = (char*)calloc(1, strlen(filename) + 6); snprintf(outfile, strlen(filename) + 6, mod%s.c, filename); out = fopen(outfile, w); if (!out) { perror(outfile); return EXIT_FAILURE; } fprintf(out, /* auto-generated SQL module */\n\n); fprintf(out, char** getsql() {\n); fprintf(out, static char *sql[] = {\n); while((line = readline(in))) { if (strlen(line) 0) { fprintf(out, \%s\, line); if (strchr(line, ';')) fprintf(out, ,\n); fprintf(out, \n); } } fprintf(out, 0};\n\n); fprintf(out, return sql;\n); fprintf(out, }\n); fclose(in); fclose(out); return EXIT_SUCCESS; } const char* readline(FILE* in) { static char line[LINE_SIZE]; memset(line, 0, LINE_SIZE); if (fgets(line, LINE_SIZE/2, in)) { markcomment(line); trim_trailing_space(line); escapeline(line); return line; } else return NULL; } void markcomment(char* line) { char* pos; pos = strstr(line, --); if (pos) *pos = '\0'; } void escapeline(char* line) { static char work[LINE_SIZE]; char* dst; char* src; memset(work, 0, LINE_SIZE); dst = work; src = line; while(*src) { switch(*src) { case '\'': case '\': case '\\': *dst++ =
Re: [sqlite] Creating a database from inside a program
On Fri, 29 Dec 2006 12:33:46 -0500, you wrote: Sqlite3 newdatabase.db .read schemafile.txt But, when I issue this command from the DOS prompt, it gives me an error message saying that there is no command named read. Try input redirection: Sqlite3 newdatabase.db schemafile.txt If your schemafile.txt contains valid SQLite statements, it should work. HTH -- ( Kees Nuyt ) c[_] - To unsubscribe, send email to [EMAIL PROTECTED] -
Re: [sqlite] Creating a database from inside a program
I have a nice solution that really works well, at least from C... 1. Create a template Database. (using whatever method you like, either embedded in your code or via sqlite3). 2. Copy the database to a new file, using plane old cp, copy, or if you like an in code copy using open, read/write, close... Then open the newly created copy. I've found that if you need mulitples of a single database structure this is a very fast way to do this, a lot faster than creating the DB and then creating the individual tables/indices. If you want really, really fast, you could load your templated db into memory and then just write this to disk whenever you need a new DB. Kees Nuyt [EMAIL PROTECTED] wrote: On Fri, 29 Dec 2006 12:33:46 -0500, you wrote: Sqlite3 newdatabase.db .read schemafile.txt But, when I issue this command from the DOS prompt, it gives me an error message saying that there is no command named read. Try input redirection: Sqlite3 newdatabase.db If your schemafile.txt contains valid SQLite statements, it should work. HTH -- ( Kees Nuyt ) c[_] - To unsubscribe, send email to [EMAIL PROTECTED] -
[sqlite] Creating a database
Hi, I know how to create a databse from a DOS prompt by going to the directory the .exe file is and by typing sqlite3 name.db which then creates the database, but what I do not know is how to create a database from my application I am building using VB.Net using the .dll file, I can successfully connect to and create tables and insert data, but as soon as I close the connection all the information is lost. The sqlite3 name.db command does not work as I am not accessing the .exe file. Does anyone out there have any ideas? Many thanks. John.
Re: [sqlite] Creating a database
I am using the C api and here a database i created if it dosen't exist. // Anders John Newby skrev: Hi, I know how to create a databse from a DOS prompt by going to the directory the .exe file is and by typing sqlite3 name.db which then creates the database, but what I do not know is how to create a database from my application I am building using VB.Net using the .dll file, I can successfully connect to and create tables and insert data, but as soon as I close the connection all the information is lost. The sqlite3 name.db command does not work as I am not accessing the .exe file. Does anyone out there have any ideas? Many thanks. John.
Re: [sqlite] Creating a database
To be more clearer the OPEN commad makes a database if it is missing // Anders Anders Persson skrev: I am using the C api and here a database i created if it dosen't exist. // Anders John Newby skrev: Hi, I know how to create a databse from a DOS prompt by going to the directory the .exe file is and by typing sqlite3 name.db which then creates the database, but what I do not know is how to create a database from my application I am building using VB.Net using the .dll file, I can successfully connect to and create tables and insert data, but as soon as I close the connection all the information is lost. The sqlite3 name.db command does not work as I am not accessing the .exe file. Does anyone out there have any ideas? Many thanks. John.
[sqlite] Can i use the command line tools--sqlite creating a database file ?
-