|
sqlite库加密很简单,唯一要做的就是:
将 import sqlite 更换为 import sqlite.aes128 (使用 AES-128 加密)
或者将 import sqlite 更换为 import sqlite.aes256 (使用 AES-256 加密)
- import sqlite.aes128
- //打开加密数据库,对于加密数据库,输入错误的密钥, 所面的所有操作都会报错
- var sqlConnection = sqlite.aes128("/dbAes128.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.parameterByNames(
- ["@title"] = "标题";
- ["@length"] = 4;
- ["@year"] = time.now();
- );
- //提交
- command.step();
- //迭代方式查询数据
- io.open()
- for title, length, year, starring in sqlConnection.each("select * from film") {
- io.print( title, length, year, starring )
- }
- execute("pause") //按任意键继续
- io.close();//关闭控制台
复制代码 |
评分
-
查看全部评分
|