Discussion:
running a script?
John Salerno
2006-08-23 19:45:53 UTC
Permalink
Hi everyone. Can someone tell me the proper syntax for running a sql
script when starting up sqlite from the command line interface?

Thanks,
John

-----------------------------------------------------------------------------
To unsubscribe, send email to sqlite-users-unsubscribe-CzDROfG0BjIdnm+***@public.gmane.org
-----------------------------------------------------------------------------
Scott Baker
2006-08-23 19:53:19 UTC
Permalink
echo "SELECT * FROM Table" | sqlite database.bin
Post by John Salerno
Hi everyone. Can someone tell me the proper syntax for running a sql
script when starting up sqlite from the command line interface?
Thanks,
John
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
--
Scott Baker - RHCE
Canby Telcom System Administrator
503.266.8253

-----------------------------------------------------------------------------
To unsubscribe, send email to sqlite-users-unsubscribe-CzDROfG0BjIdnm+***@public.gmane.org
-----------------------------------------------------------------------------
John Salerno
2006-08-23 20:01:46 UTC
Permalink
I'm asking about an actual file, though, not just a single query. I've
tried something like what you suggest with the file path, but it
doesn't work.
Post by Scott Baker
echo "SELECT * FROM Table" | sqlite database.bin
Post by John Salerno
Hi everyone. Can someone tell me the proper syntax for running a sql
script when starting up sqlite from the command line interface?
Thanks,
John
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
--
Scott Baker - RHCE
Canby Telcom System Administrator
503.266.8253
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
To unsubscribe, send email to sqlite-users-unsubscribe-CzDROfG0BjIdnm+***@public.gmane.org
-----------------------------------------------------------------------------
Clay Dowling
2006-08-23 20:28:06 UTC
Permalink
Post by John Salerno
I'm asking about an actual file, though, not just a single query. I've
tried something like what you suggest with the file path, but it
doesn't work.
sqlite database.db < script.sql
Post by John Salerno
Post by Scott Baker
echo "SELECT * FROM Table" | sqlite database.bin
Post by John Salerno
Hi everyone. Can someone tell me the proper syntax for running a sql
script when starting up sqlite from the command line interface?
Thanks,
John
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
--
Scott Baker - RHCE
Canby Telcom System Administrator
503.266.8253
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
--
Simple Content Management
http://www.ceamus.com


-----------------------------------------------------------------------------
To unsubscribe, send email to sqlite-users-unsubscribe-CzDROfG0BjIdnm+***@public.gmane.org
-----------------------------------------------------------------------------
Ulrich Schöbel
2006-08-23 20:12:08 UTC
Permalink
Post by John Salerno
Hi everyone. Can someone tell me the proper syntax for running a sql
script when starting up sqlite from the command line interface?
Thanks,
John
---------------------------------------------------------------------------
---------------------------------------------------------------------------
--
cat scriptfile | sqlite3 mydb

or

sqlite3 -init scriptfile mydb

or

sqlite3 mydb < scriptfile

or (for a single sql command)

sqlite3 mydb 'sqlcmd'

Kind regards

Ulrich

-----------------------------------------------------------------------------
To unsubscribe, send email to sqlite-users-unsubscribe-CzDROfG0BjIdnm+***@public.gmane.org
-----------------------------------------------------------------------------
John Salerno
2006-08-23 20:22:03 UTC
Permalink
Thanks guys. Does any of this change for Windows though? I don't
believe I can use cat or | in the command prompt. I've also tried some
of those structures already and there seems to be a problem with my
file paths: C:\name\name\file.ext

I don't know if it's the colon or the slashes, but it won't work properly.

And about using .read and .import, does this mean you can't use them
on files that have semicolons in them?
Post by Ulrich Schöbel
Post by John Salerno
Hi everyone. Can someone tell me the proper syntax for running a sql
script when starting up sqlite from the command line interface?
Thanks,
John
---------------------------------------------------------------------------
---------------------------------------------------------------------------
--
cat scriptfile | sqlite3 mydb
or
sqlite3 -init scriptfile mydb
or
sqlite3 mydb < scriptfile
or (for a single sql command)
sqlite3 mydb 'sqlcmd'
Kind regards
Ulrich
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
To unsubscribe, send email to sqlite-users-unsubscribe-CzDROfG0BjIdnm+***@public.gmane.org
-----------------------------------------------------------------------------
Clark Christensen
2006-08-23 20:14:46 UTC
Permalink
From the SQLite shell
.read myfile

Or, from the OS command shell

sqlite3 foo.db ".read myfile"

.help in the SQLite shell will give you the available commands

Note. For me, it's a habit to end lines in the SQLite shell with a semicolon. That breaks the .read and .import commands because the SQLite shell includes the trailing semicolon as part of the file or table identifier.

-Clark


----- Original Message ----
From: John Salerno <johnjsal-***@public.gmane.org>
To: sqlite-users-CzDROfG0BjIdnm+***@public.gmane.org
Sent: Wednesday, August 23, 2006 1:01:46 PM
Subject: Re: [sqlite] running a script?

I'm asking about an actual file, though, not just a single query. I've
tried something like what you suggest with the file path, but it
doesn't work.
echo "SELECT * FROM Table" | sqlite database.bin
Post by John Salerno
Hi everyone. Can someone tell me the proper syntax for running a sql
script when starting up sqlite from the command line interface?
Thanks,
John
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
--
Scott Baker - RHCE
Canby Telcom System Administrator
503.266.8253
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
To unsubscribe, send email to sqlite-users-unsubscribe-CzDROfG0BjIdnm+***@public.gmane.org
-----------------------------------------------------------------------------





-----------------------------------------------------------------------------
To unsubscribe, send email to sqlite-users-unsubscribe-CzDROfG0BjIdnm+***@public.gmane.org
-----------------------------------------------------------------------------
Clark Christensen
2006-08-23 21:03:49 UTC
Permalink
It should work fine with filenames with semicolons. My problem is when I include the trailing semicolon, and it isn't really part of the filename or table name.

You _might_ need to use forward slashes instead of backslashes as the path separator inside the SQLite shell on Windows. Or you might need to use double backslashes. I remember having an issue like this, but I don't remember the details. I've just started putting the files in the default dir.

-Clark


----- Original Message ----
From: John Salerno <johnjsal-***@public.gmane.org>
To: sqlite-users-CzDROfG0BjIdnm+***@public.gmane.org; ***@outvert.com
Sent: Wednesday, August 23, 2006 1:22:03 PM
Subject: Re: [sqlite] running a script?

Thanks guys. Does any of this change for Windows though? I don't
believe I can use cat or | in the command prompt. I've also tried some
of those structures already and there seems to be a problem with my
file paths: C:\name\name\file.ext

I don't know if it's the colon or the slashes, but it won't work properly.

And about using .read and .import, does this mean you can't use them
on files that have semicolons in them?
Post by Ulrich Schöbel
Post by John Salerno
Hi everyone. Can someone tell me the proper syntax for running a sql
script when starting up sqlite from the command line interface?
Thanks,
John
---------------------------------------------------------------------------
---------------------------------------------------------------------------
--
cat scriptfile | sqlite3 mydb
or
sqlite3 -init scriptfile mydb
or
sqlite3 mydb < scriptfile
or (for a single sql command)
sqlite3 mydb 'sqlcmd'
Kind regards
Ulrich
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
-----------------------------------------------------------------------------
To unsubscribe, send email to sqlite-users-unsubscribe-CzDROfG0BjJQFI55V6+***@public.gmane.orgg
-----------------------------------------------------------------------------





-----------------------------------------------------------------------------
To unsubscribe, send email to sqlite-users-unsubscribe-CzDROfG0BjIdnm+***@public.gmane.org
-----------------------------------------------------------------------------
Continue reading on narkive:
Loading...