Making SQLITE/SQLITE3 executable scripts

Use "here document" statements to build complex script files with embedded SQL statements via the sqlite/sqlite3 utility.

#! /usr/bin/env bash

# execute some bash scripting commands here

sqlite3 mydatabase <<SQL_ENTRY_TAG_1
SELECT * 
  FROM mytable 
  WHERE somecondition='somevalue';
SQL_ENTRY_TAG_1

# execute other bash scripting commands here

SQL_ENTRY_TAG_2
SELECT *
  FROM myothertable
  WHERE someothercondition='someothervalue';
SQL_ENTRY_TAG_2

Note that being in a bash script means that you can expand $-variables inside the SQL code directly. This is,however,not advised unless you can be sure that only trusted,competent people will run your code. Otherwise you'll be facing SQL injection attacks.

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能