Re: Shell Scripting SQLite
Re: Shell Scripting SQLite
- Subject: Re: Shell Scripting SQLite
- From: Bruce Robertson <email@hidden>
- Date: Sat, 31 May 2008 00:34:30 -0700
Turns out dump from memory db is way easier than I thought.
All the output is run together, you need to insert returns between some
commands.
Here's a simple applescript sample that creates a memory db and dumps it and
also provides an HTML output and line output.
A similar approach could be taken with straight shell scripting thus xplat.
The upshot is that it is very easy to pass around sqlite databases entirely
within FileMaker, such as for reports or for carrying script parameters.
-- start applescript
set cmd to "CREATE TABLE t1 (recID, Name, statusMarker);
INSERT INTO t1 VALUES (1, \"one\", 3);
INSERT INTO t1 VALUES (2, \"Line A
Line B
Line C\", 3);
INSERT INTO t1 VALUES (22, \"tw22o\", 12);
CREATE TABLE t2 as select recID as R1 , Name as R2 from t1;
.dump
.mode html
.header on
.echo off
SELECT * FROM t1;
select R1 as \"Record ID\", R2 as NAME from t2 as table2;
.mode line
SELECT * FROM t1 order by name;"
set cmd to "echo '" & cmd & "'|sqlite3 :memory: "
do shell script cmd
-- end script
=========================================================
RESULT showing the sql dump + HTML output + line output
=========================================================
"BEGIN TRANSACTION;
CREATE TABLE t1 (recID, Name, statusMarker);
INSERT INTO \"t1\" VALUES(1, 'one', 3);
INSERT INTO \"t1\" VALUES(2, 'Line A
Line B
Line C', 3);
INSERT INTO \"t1\" VALUES(22, 'tw22o', 12);
CREATE TABLE t2(R1,R2);
INSERT INTO \"t2\" VALUES(1, 'one');
INSERT INTO \"t2\" VALUES(2, 'Line A
Line B
Line C');
INSERT INTO \"t2\" VALUES(22, 'tw22o');
COMMIT;
<TR><TH>recID</TH><TH>Name</TH><TH>statusMarker</TH></TR>
<TR><TD>1</TD>
<TD>one</TD>
<TD>3</TD>
</TR>
<TR><TD>2</TD>
<TD>Line A
Line B
Line C</TD>
<TD>3</TD>
</TR>
<TR><TD>22</TD>
<TD>tw22o</TD>
<TD>12</TD>
</TR>
<TR><TH>Record ID</TH><TH>NAME</TH></TR>
<TR><TD>1</TD>
<TD>one</TD>
</TR>
<TR><TD>2</TD>
<TD>Line A
Line B
Line C</TD>
</TR>
<TR><TD>22</TD>
<TD>tw22o</TD>
</TR>
recID = 2
Name = Line A
Line B
Line C
statusMarker = 3
recID = 1
Name = one
statusMarker = 3
recID = 22
Name = tw22o
statusMarker = 12"
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden