Running a Sqlite3 Script from Command Line

后端 未结 4 1442
孤街浪徒
孤街浪徒 2020-12-29 05:12

I am writing a shell script to scp a project and part of it involves transferring some important tables in my database.

I have the following stored in the file

相关标签:
4条回答
  • 2020-12-29 05:36

    The parameter you give to the sqlite3 program is the database file name.

    To execute commands from a file, you must redirect the input to that file:

    $ sqlite3 mydatabase.db < SQLTableTransfer
    

    or tell it to read from that file:

    $ sqlite3 mydatabase.db ".read SQLTableTransfer"
    
    0 讨论(0)
  • 2020-12-29 05:37

    You can get a list of the spatial tables as follows:

    echo "SELECT f_table_name FROM geometry_columns;" | spatialite -noheader -silent your_db.sqlite

    0 讨论(0)
  • 2020-12-29 05:44

    For the lazy who want to just dump this into their .bashrc:

    ### Execute an sqlite3 file on a given db
    sql3-exec () {
      # TODO: write a  --help flag that doubles as error handling
      # TODO: Ensure that $1 is a db; Else display --help
      # TODO: Ensure that $2 is a .sql file; Else display --help
      # TODO: Probably store a backup (or at least a flag)...
      sqlite3 $1 ".read $2"
      true
    }
    
    0 讨论(0)
  • 2020-12-29 05:44

    For Windows CLI, assuming your database is loaded:

    sqlite> .read C:\\somesubdir\\some.sql
    
    0 讨论(0)
提交回复
热议问题