VisualWorksでSQLiteに接続
わざわざPostgresインストールすんのやだなーとか考えてたら、SQLiteの存在を思い出したのでやってみた。
SQLiteを用意する
1.sqlite3.dllを拾ってくる(手元のやつは3.5.0)。
2.visual.exeかイメージファイルか、多分どっちかと同じディレクトリに入れる(どちらも同じディレクトリに入れてあるから正解は未確認)。
VWを用意する
1.[System]-[Load Parcels Named...]からDLLCCをロードする。
2.[Store]-[Connect to Repository...]でダイアログオープン、[Connection Profile:]は「Cincom Public Repository」を選択、他の値はそのままでConnect。
3.[Store]-[Published Items]でウインドウオープン、左下の一覧から「SQLite3EXDI」「SQLite3EXDI-Preload」を選んで、右上ペインで選択して[Load]。Preloadの方を先にLoadした(逆だとどうなるか知らない)。「SQLite3EXDI」のロード時にDLLCCが要求されるから、上記1.は先に。
4.[Store]-[Disconnect from Cincom Public Repository]。
5.イメージ保存する?
やってみる
とりあえずテーブルとデータを作っておく。
create table aa ( id integer, name string ); insert into aa values (0, 'foo'); insert into aa values (1, 'bar');
別にコードの中からもできるけど。
| con session stream | Transcript clear. con := SQLite3Connection new. con environment: 'test.db'. con connect. session := con getSession. session prepare: 'select * from aa;'. session execute. stream := session answer. [stream atEnd] whileFalse: [ | row | row := stream next. Transcript show: ('id = ', (row at: 1) printString, ', '); show: ('name = ', (row at: 2)); cr. ]. con disconnect. " id = 0, name = foo id = 1, name = bar "
フィールドには名前でアクセスしたいところだけど、rowがan Arrayだったから数値にしといた。