How to read sql file in sqlite command in Mac terminal window

I am trying to point to a file that I have in the path. my test2.sqllooks like this:

create table setting (id integer primary key, status text)
insert into setting values (1, 'new')

When I type this command:

sqlite> .read users/name/test2.sql

I get this error:

Error: cannot open "test2.sql"

or behaves as if it was executed without errors, but records are not added to the table.

I do

sqlite> select * from setting;

and this goes back to:

sqlite> 

Are there any problems using the command .read?

+4
source share
4 answers

First, every SQL statement must end with a semicolon.

-- file: test2.sql
create table setting (id integer primary key, status text);
insert into setting values (1, 'new');

-, "test2.sql" , .read . , .

$ sqlite3 test.db
SQLite version 3.8.7.2 2014-11-18 20:57:56
Enter ".help" for usage hints.
sqlite> .read "test2.sql"

sqlite> .headers on
sqlite> .mode columns
sqlite> select * from setting;
id          status    
----------  ----------
1           new       

. , . users/name/test2.sql . /. ( POSIX /; HFS :.) , (?) : /users/name/test2.sql /users/name/test2.sql .

. , SQL , .

$ rm test.db
$ sqlite3 test.db < "test2.sql"
$ sqlite3 test.db
SQLite version 3.8.7.2 2014-11-18 20:57:56
Enter ".help" for usage hints.
sqlite> .headers on
sqlite> .mode columns
sqlite> select * from setting;
id          status    
----------  ----------
1           new       

, SQL.

$ ls -l "test2.sql"
-rw-rw-r-- 1 mike mike 118 Jan 15 09:28 test2.sql

, .

+1

.read .sql , .sql , SQLite. .sql ​​.

+1

, Windows. Windows . , "FN", "FN.txt"

0

I had the same problem, I found that I named the file test.sql.sql due to the windows hiding the file extensions (new computer). I renamed the file to test.sql and it worked.

0
source

All Articles