コードを舐める日々

わからないことがわからないことをしる日々

sqlite3をさわってみた

MySQLとかOracleとかさわってきたけど、簡潔なものを作るためにはSQLiteがいいようなので、使い方とかも知っておかないと。

SQlite接続+hoge.db作成

$ sqlite3 hoge.db

接続後、.helpといれると

.bail ON|OFF           Stop after hitting an error.  Default OFF
.databases             List names and files of attached databases
.dump ?TABLE? ...      Dump the database in an SQL text format
.echo ON|OFF           Turn command echo on or off
.exit                  Exit this program
.explain ON|OFF        Turn output mode suitable for EXPLAIN on or off.
.header(s) ON|OFF      Turn display of headers on or off
.help                  Show this message
.import FILE TABLE     Import data from FILE into TABLE
.indices TABLE         Show names of all indices on TABLE
・
・
・

というようにコマンド一覧などが出てくる。
テーブル作成ならSQL文でできる。

create table hogehoge(id,title,body,created);
insert into hogehoge (id,title,body,created) values (1,'hoge','hoge2','20090511');

とか。