LiteCLI は,コードアシスト機能付きの,SQLite 3 コマンドラインクライアント
【目次】
Ubuntu で OS のシステム更新を行うときは, 端末で,次のコマンドを実行する.
Ubuntu のインストールは別ページ »で説明
sudo apt -y update sudo apt -yV upgrade sudo /sbin/shutdown -r now
Python のインストールは行わない(Ubuntu のシステム Python を用いる.)
Python, pip のコマンドでの起動のまとめ.
Ubuntu のシステム Python を用いるとき, python, pip は,次のコマンドで起動できる.
Ubuntu での Python 開発環境(JupyterLab, spyder, nteract)のインストール: 別ページ »で説明
端末で,次のコマンドを実行する.
sudo apt -y update sudo apt -y install python-is-python3 python3-dev python-dev-is-python3 python3-pip python3-setuptools python3-venv build-essential
端末で,次のコマンドを実行する.
sudo pip3 install -q git+https://github.com/dbcli/litecli.git
litecli
「exit」で終了
exit
このとき,データベース名として mydb を指定する.SQLite 3の流儀で,データベース名はファイル名になる.
※ データベース名はなんでも良いが、アルファベットのみを使うのが良い.
litecli mydb
「help」で,ヘルプが表示される.
help
「PRAGMA encoding;」で,エンコーディングが表示される.
pragma encoding;
「exit」で終了.
exit
SQLite 3 の説明は https://www.sqlite.org/sqlite.html
ここでの設定
litecli
.open hoge.db
exit
litecli
.open hoge.db
※ テーブル名に日本語を使うとエラーが出る場合がある.
create table order_records ( id integer primary key not null, year integer not null CHECK ( year > 2008 ), month integer not null CHECK ( month >= 1 AND month <= 12 ), day integer not null CHECK ( day >= 1 AND day <= 31 ), customer_name text not null, product_name text not null, unit_price real not null check ( unit_price > 0 ), qty integer not null default 1 check ( qty > 0 ), created_at timestamp with time zone not null, updated_at timestamp with time zone, check ( ( unit_price * qty ) < 200000 ) );
.tables
begin transaction; insert into order_records (id, year, month, day, customer_name, product_name, unit_price, qty, created_at) values( 1, 2022, 1, 26, 'kaneko', 'orange A', 1.2, 10, datetime('now', 'localtime') ); insert into order_records (id, year, month, day, customer_name, product_name, unit_price, qty, created_at) values( 2, 2022, 1, 26, 'miyamoto', 'Apple M', 2.5, 2, datetime('now', 'localtime') ); insert into order_records (id, year, month, day, customer_name, product_name, unit_price, qty, created_at) values( 3, 2022, 1, 27, 'kaneko', 'orange B', 1.2, 8, datetime('now', 'localtime') ); insert into order_records (id, year, month, day, customer_name, product_name, unit_price, created_at) values( 4, 2022, 1, 28, 'miyamoto', 'Apple L', 3, datetime('now', 'localtime') ); commit;
select * from order_records;
exit
pragma については https://www.sqlite.org/pragma.html
SQLite 3 のキャッシュサイズは,オープンしたデータベースについて,最大どれだけをメモリに保持するか.「-」が付いているときは,単位は1024バイト.
キャッシュサイズの変更.「-500」のように「-」を付けると,単位は 1024 バイト.単純に「512000」のように書くとバイト単位.
現在接続しているデータベースについてのジャーナルモード.ジャーナルは,トランザクションのロールバックのために用いるもの(SQLite 3 の独自用語ではない)
delete, truncate, persiste, memory, wal, off に設定できる.