//使用命名参数
import sqlite

io.open();

//打开数据库连接
var sqlConnection = sqlite("/testParameters.db")

//创建表 
if( not sqlConnection.existsTable("film") ){  
	sqlConnection.exec( "create table film(title, length, year, starring);")  
}  
 
//可以用@表示命名参数
var command = sqlConnection.prepare("insert into film values (@title,@length,@year, 'Jodie Foster');" )

//绑定命名参数,此函数默认在所有键前前添加@字符
command.bind.parameterByNamesAt(
	title = "标题";
	length = 4;
	year = time.now();
)

//也可以这样写
command.bind.parameterByNames( 
	["@title"] = "标题";
	["@length"] = 4;
	["@year"] = time.now();
);

command.step();
 
//释放命令对象
command.finalize() 

//显示最后插入ID 
io.print("最后插入ID",sqlConnection.last_insert_rowid())

//迭代方式查询数据 
for title, length, year, starring in sqlConnection.each("select * from film") {
	io.print( title, length, year, starring  ) 
}
io.print("------------迭代数据 ok") 

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

execute("pause") //按任意键继续
io.close();//关闭控制台
