Hi Bill,

It's great to see a fellow AppleScript programmer here on the SQLite discussion list.

I tried finding a pragma command for .headers on, but didn't have any luck.

As I understand it, the .headers (and other dot commands) only affect the sqlite3 shell command output, so therefore only exist within the shell program, not in PRAGMAs etc.

sqlite> .headers on | .mode column customers | select * from customers ;

The reason I am trying to do this in one call rather than using multiple lines is that one "do shell script" call is totally independent from the next, unlike scripting to a shell window which I don't want to do.

Yes, the dot commands only seem to affect the current sqlite3 shell session, and therefore if sent as a separate single shell instruction, it won't affect the next shell instruction.

sqlite> .headers on
sqlite> .mode column customers
sqlite> select * from customers ;

If you just needed the headers on, you could rewrite the above using one of the sqlite3 options, ie:

sqlite3 -header -column "/Users/bill/Documents/mydatabase.db" "select * from customers"

see:
man sqlite3
for more details.

But let's assume you need to issue dot commands that aren't covered by the command line options.

The solution to sending this as one shell command line, without having to enter the sqlite3 program's interactive mode, nor creating a temporary batch file, is to write it using a pipe like this:

echo '.headers on
.mode column customers
select * from customers;' | sqlite3 '/Users/bill/Documents/ mydatabase.db'

Note that because you are hitting return inside quotes, the shell command interpreter allows you to enter the 3 lines as one command, before executing.

is that I am calling it from Applescript

Using AppleScript to issue the above:

do shell script "echo '.headers on
.mode column customers
select * from customers;' | sqlite3 '/Users/bill/Documents/ mydatabase.db'"

or something like:

set linefeed to ASCII character 10
set dotCommands to ".headers on" & linefeed & ".mode column customers"
set sqlCommands to "select * from customers;"
set databasePath to "/Users/tom/Documents/mydatabase.db"
do shell script "echo '" & dotCommands & linefeed & sqlCommands & "' | sqlite3 " & quoted form of databasePath

There's a good article on using "do shell script" (and issuing shell commands in one line) at:
http://developer.apple.com/technotes/tn2002/tn2065.html

Thanks,
Tom


-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to