説明
SQLiteでテーブル毎にデータを抽出するツールです。
SQLiteの「.dump」を使い、テーブル毎にCREATE
使い方は2種類あって、指定したDBに対して「-a」で全テーブルを抽出、「-f
usage:
unload [-a|-f conf_file] db
-a : unload all tables
-f conf_file : unload specified tables
エラー処理(*1)はきちんとやっていませんが利用シーンを特定して使っている(*2)ので個人的には問題ありません。
(*1)
(*2)
純粋にデータだけ抽出するのもいいのですが、テーブル自体を再作成する必要が出てきた時などに困るので僕は「.dump」のほうが好みです。
コメント
前へ 1 次へ![]()
コメントする
[block]から[/block]までの範囲はブロック表示されます。
部分的に目立たせたい時や、引用などにお使いください。
[code]から[/code]までの範囲は等幅表示されます。
ソースコードや設定ファイルの記述などにお使いください。










使用例です。
sqlite3 test.db .tables purpose test .q
unload -a test.db tables to "test.db-<table>-20080411-1409.dump"
[0001/0003] customer ... done
[0002/0003] purpose ... done
[0003/0003] test ... done
ls -1 *.dump
more test.db-customer-20080411-1409.dump TRANSACTION; TABLE customer( integer, text, text, text); INTO "customer" VALUES(1,'foo','01-234-5789','park'); INTO "customer" VALUES(2,'bar','99-999-9999','apart'); INTO "customer" VALUES(3,'baz',NULL,NULL);
cat <<END > conf
unload -f conf test.db tables to "test.db-<table>-20080411-1412.dump"
[0001/0002] customer ... done
[0002/0002] purpose ... done
%
sqlite>
customer
sqlite>
%
Unload
%
test.db-customer-20080411-1409.dump
test.db-purpose-20080411-1409.dump
test.db-test-20080411-1409.dump
%
BEGIN
CREATE
id
name
tel
address
INSERT
INSERT
INSERT
COMMIT;
%
customer
purpose
END
%
Unload