天天看点

用lisp语言操作sqlite3数据库

linux环境下,先下载[1]对sqlite3.so的封装库代码。接口文档参考[2], 例子来自[3]。

> (load "sqlite3.sls") ;加载库代码

> (import (sqlite3)) ;引入名字空间

> (define db (open-database "yy.db")) ;创建或打开数据库

> (define stmt (prepare db "CREATE TABLE table1 (x INTEGER, y INTEGER)")) ;定义SQL语句

> (execute stmt) ;执行语句

> (finalize! stmt) ;释放占用的资源

> (define stmt (prepare db "INSERT INTO table1 VALUES(?,?)")) ;再来

> (execute stmt 1 2)

> (finalize! stmt)

> (finalize! db) ;关闭数据库

[1] https://github.com/ovenpasta/thunderchez

[2] http://wiki.call-cc.org/eggref/4/sqlite3

[3] https://www-sop.inria.fr/indes/fp/Bigloo/doc/bigloo-19.html

继续阅读