微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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.

原文地址:https://www.jb51.cc/sqlite/202278.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐