Java 學習記錄109 — Introduction to SQLite

張小雄
3 min readJan 25, 2022

今天我們要學的是資料庫 — SQLite

安裝環境

先到 https://www.sqlite.org/download.html

安裝對應的版本

我的電腦是WIN10

我下載了

sqlite-dll-win64-x64–3370200.zip (890.05 KiB)

sqlite-tools-win32-x86–3370200.zip (1.84 MiB)

拉一個資料把解壓縮的檔案直接丟到一起

把這個資料夾拉到你想要的路徑上,等下環境的路徑就是用這個資料夾

接著對著左下 “開始” 點右鍵 -> “系統”

接著往下拉找到 “進階系統設定”

在下方取消的上面點 “環境變數”

在上方的欄位找到 “Path”,選起來點編輯

進去後點右上角 “新增”,把剛弄好的資料夾的路徑複製過來(建議是放在C槽下方,不要有中文)

這樣環境變數就設定好了

接著打開 cmd 來驗證安裝是否成功

輸入:sqlite3

輸出:

SQLite version 3.37.2 2022–01–06 13:25:41

Enter “.help” for usage hints.

Connected to a transient in-memory database.

Use “.open FILENAME” to reopen on a persistent database.

就代表安裝成功(版本號可能隨著時間各有不同)

之後練習都是用 cmd 進行

cmd 清屏:cls

開啟 sqlite:sqlite3

退出 sqlite:.quit

輸入:.help

結果:

.archive … Manage SQL archives

.auth ON|OFF Show authorizer callbacks

.backup ?DB? FILE Backup DB (default “main”) to FILE

.bail on|off Stop after hitting an error. Default OFF

.binary on|off Turn binary output on or off. Default OFF

.cd DIRECTORY Change the working directory to DIRECTORY

.changes on|off Show number of rows changed by SQL

.check GLOB Fail if output since .testcase does not match

.clone NEWDB Clone data into NEWDB from the existing database

.connection [close] [#] Open or close an auxiliary database connection

.databases List names and files of attached databases

.dbconfig ?op? ?val? List or change sqlite3_db_config() options

.dbinfo ?DB? Show status information about the database

.dump ?OBJECTS? Render database content as SQL

.echo on|off Turn command echo on or off

.eqp on|off|full|… Enable or disable automatic EXPLAIN QUERY PLAN

.excel Display the output of next command in spreadsheet

.exit ?CODE? Exit this program with return-code CODE

.expert EXPERIMENTAL. Suggest indexes for queries

.explain ?on|off|auto? Change the EXPLAIN formatting mode. Default: auto

.filectrl CMD … Run various sqlite3_file_control() operations

.fullschema ? — indent? Show schema and the content of sqlite_stat tables

.headers on|off Turn display of headers on or off

.help ?-all? ?PATTERN? Show help text for PATTERN

.import FILE TABLE Import data from FILE into TABLE

.imposter INDEX TABLE Create imposter table TABLE on index INDEX

.indexes ?TABLE? Show names of indexes

.limit ?LIMIT? ?VAL? Display or change the value of an SQLITE_LIMIT

.lint OPTIONS Report potential schema issues.

.load FILE ?ENTRY? Load an extension library

.log FILE|off Turn logging on or off. FILE can be stderr/stdout

.mode MODE ?TABLE? Set output mode

.nonce STRING Disable safe mode for one command if the nonce matches

.nullvalue STRING Use STRING in place of NULL values

.once ?OPTIONS? ?FILE? Output for the next SQL command only to FILE

.open ?OPTIONS? ?FILE? Close existing database and reopen FILE

.output ?FILE? Send output to FILE or stdout if FILE is omitted

.parameter CMD … Manage SQL parameter bindings

.print STRING… Print literal STRING

.progress N Invoke progress handler after every N opcodes

.prompt MAIN CONTINUE Replace the standard prompts

.quit Exit this program

.read FILE Read input from FILE

.recover Recover as much data as possible from corrupt db.

.restore ?DB? FILE Restore content of DB (default “main”) from FILE

.save FILE Write in-memory database into FILE

.scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off

.schema ?PATTERN? Show the CREATE statements matching PATTERN

.selftest ?OPTIONS? Run tests defined in the SELFTEST table

.separator COL ?ROW? Change the column and row separators

.session ?NAME? CMD … Create or control sessions

.sha3sum … Compute a SHA3 hash of database content

.shell CMD ARGS… Run CMD ARGS… in a system shell

.show Show the current values for various settings

.stats ?ARG? Show stats or turn stats on or off

.system CMD ARGS… Run CMD ARGS… in a system shell

.tables ?TABLE? List names of tables matching LIKE pattern TABLE

.testcase NAME Begin redirecting output to ‘testcase-out.txt’

.testctrl CMD … Run various sqlite3_test_control() operations

.timeout MS Try opening locked tables for MS milliseconds

.timer on|off Turn SQL timer on or off

.trace ?OPTIONS? Output each SQL statement as it is run

.vfsinfo ?AUX? Information about the top-level VFS

.vfslist List all available VFSes

.vfsname ?AUX? Print the name of the VFS stack

.width NUM1 NUM2 … Set minimum column widths for columnar output

--

--