作者:AngryFox 分类: Uncategorized July 19th, 2014 暂无评论
import sqlite
import console;

//创建数据库
var db = sqlite("/test-sqlite.db")

//创建表
if( not db.existsTable("film") ){
	db.exec( "create table film(title, length, year, starring);")
}  

for(i=1;9;1){
	//增 - 使用命名参数示例
	var command = db.prepare("replace into film values (@title,@length,@year, 'Angryfox.com');" )
	command.step(
		title = "Gopher" + i;
		length = 4 + i;
		year = time.now();
	)
}

//删 - 执行SQL语句示例
db.exec("DELETE FROM [%s] where length=%d;","film",999)

//改 - 执行SQL语句示例,SQL语句后面可以添加任意个格式化参数
db.exec("UPDATE film SET title = '%s',length=%d WHERE title = '%s';"
	,"新的标题",#"新的标题","标题");

//查 - 返回首行数据
var result = db.stepQuery("SELECT * FROM [film]"
	,{ title = "新的标题"} //可选使用表对象指定where条件参数
	) 

//查 - 迭代器
for rowid,title, length, year, starring in db.each("select rowid,* from film") {
	console.log( rowid,title, length, year, starring  )
}

//查 - 返回数据表
var dataTable = db.getTable("SELECT * FROM [film] "
	,{ title = "新的标题"} //可选使用表对象指定where条件参数
	)
//console.varDump( dataTable )

//删除表
db.exec("drop table film" );

console.pause();
console.close()