An example of how to do this with the shell would be helpful.

Oddly enough I can do it with applescript; but I can't do it with some other
shell tools I'm trying to use.

My problem has to do with how to pass multiple lines to a single command.
I'm sure it's quite simple but I keep poking around not getting anywhere.

This is the applescript version:

set this to "echo '
.read /a.sql 
.o stdout 
.dump 
.q
'|sqlite3 "
set this to paragraphs of this
set applescript's text item delimiters to "\n"
do shell script (this as text)
-- result:
"BEGIN TRANSACTION;
CREATE TABLE Responses (GFUP_ID TEXT,FullQNum TEXT,ResponseNumber
TEXT,SurveyVersion TEXT,RecordID TEXT);
INSERT INTO \"Responses\" VALUES('36780001', '00.1.01', '1', '2000', '1');
INSERT INTO \"Responses\" VALUES('36780001', '02.1.01', '1', '2000', '2');
INSERT INTO \"Responses\" VALUES('36780001', '02.1.02', '', '2000', '3');

Etc


> On Fri, May 30, 2008 at 09:24:29PM -0700, Bruce Robertson scratched on the
> wall:
>> Well, an interesting illustration of basic sqlite; but no relation to the
>> question being asked.
> 
> Actually, it is a good answer to the question that was asked.
> 
> Running SQLite without a database file creates an in-memory database.
> Using the .dump command will dump that in-memory DB to a SQL file that
> can then be re-read into a file-backed database (or back into a memory
> database), just as Mark asked about.
> 
> Of course, I assume Mark wants to do this via code.  That will
> require poking around the shell code to see how the ".dump" command
> is implemented within the command shell.
> 
>  -j
> 
> 
>>> On 5/30/08, Mark Stewart <[EMAIL PROTECTED]> wrote:
>>>> 
>>>>  Is there a recommended way to save an in-memory database to a file?  Is
>>>> there
>>>>  a way to access the underlying in-memory data directly to save out to disk
>>>>  (if that would even work)?
>>>> 
>>>>  My other thought was to create an empty file based db and attach it,
>>>>  creating tables and transferring all the data through sql.
>>>> 
>>>>  Maybe there is some other option?
>>>> 
>>> 
>>> 
>>> [12:04 AM] ~/foo$ ls
>>> [12:04 AM] ~/foo$ sqlite3
>>> SQLite version 3.5.6
>>> Enter ".help" for instructions
>>> sqlite> CREATE TABLE t (a, b);
>>> sqlite> INSERT INTO t VALUES (1, 'one');
>>> sqlite> INSERT INTO t VALUES (2, 'two');
>>> sqlite> SELECT * FROM t;
>>> 1|one
>>> 2|two
>>> sqlite> .q
>>> [12:04 AM] ~/foo$ ls
>>> [12:04 AM] ~/foo$ sqlite3
>>> SQLite version 3.5.6
>>> Enter ".help" for instructions
>>> sqlite> CREATE TABLE t (a, b);
>>> sqlite> INSERT INTO t VALUES (1, 'one');
>>> sqlite> INSERT INTO t VALUES (2, 'two');
>>> sqlite> SELECT * FROM t;
>>> 1|one
>>> 2|two
>>> sqlite> .o foo.sql
>>> sqlite> .dump
>>> sqlite> .q
>>> [12:05 AM] ~/foo$ ls
>>> foo.sql
>>> 12:05 AM] ~/foo$ cat foo.sql
>>> BEGIN TRANSACTION;
>>> CREATE TABLE t (a, b);
>>> INSERT INTO "t" VALUES(1,'one');
>>> INSERT INTO "t" VALUES(2,'two');
>>> COMMIT;
>>> [12:06 AM] ~/foo$
>>> _______________________________________________
>>> 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
> 
> -- 
> Jay A. Kreibich < J A Y  @  K R E I B I.C H >
> 
> "'People who live in bamboo houses should not throw pandas.' Jesus said that."
>  - "The Ninja", www.AskANinja.com, "Special Delivery 10: Pop!Tech 2006"
> _______________________________________________
> 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