On Sun, Aug 15, 2010 at 5:58 PM, Simon Slavin <slav...@bigfraud.org> wrote:
>
> On 15 Aug 2010, at 11:31pm, Peng Yu wrote:
>
>> $ cat file.txt
>> 1     eenie
>> 2     meenie
>> 3     miny
>> 4     mo
>> $cat main.sql
>> #!/usr/bin/env bash
>>
>> rm -f main.db
>> sqlite3 main.db < file.txt <<EOF
>
> That cannot work: it would require a file with commands in and your file has 
> data in.
>
>> create table test (id integer primary key, value text);
>> .separator "\t"
>> .import /dev/stdin test
>>
>> .headers on
>> .mode column
>> select * from test;
>>
>> EOF
>
> Some of those lines are commands to your Unix shell and others are commands 
> for the sqlite3 program.  You cannot mix a shell script and SQL commands like 
> that.  Try these three files:

This is called here document in bash. You can mix sqlite3 code with bash code.

> $ cat file.tsv
> 1       eenie
> 2       meenie
> 3       miny
> 4       mo
>
> $cat importfile.sql
> create table test (id integer primary key, value text);
> .separator "\t"
> .import file.tsv test
> .headers on
> .mode column
> select * from test;
>
> $cat importfile
> #!/usr/bin/env bash
> rm -f main.db
> sqlite3 main.db '.read importfile.sql'

I didn't know .read command. I'll try it. But it seems that it is
functionally equivalent to bash here document.

But my question on how to read from stdin is still not answered.

> I have not tested this, but it should point you in the right direction.
>
> Simon.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
>



-- 
Regards,
Peng
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to