函数:dborder 数据库操作

函数分类:ts.so

函数名称:数据库操作

函数功能:利用 sql 语句对数据库进行操作,支持增删改查操作

iOS 函数方法

dborder(path,order,Binary Parameters)

参数 类型 必填 说明
path 文本型 数据库文件路径
order string sql 语句命令
Binary Parameters table 二进制参数
返回值 类型 说明
status number 1 - 操作成功,0 - 操作失败
result table/string 成功返回操作结果;失败返回值失败原因

Android 函数方法(仅支持 v1.1.1 及其以上版本 ts.so)

dborder(path,order)

参数 类型 必填 说明
path string 数据库文件路径
order string sql 语句命令
返回值 类型 说明
status number 1 - 操作成功,0 - 操作失败
result table/string 成功返回操作结果;失败返回值失败原因

函数用例

--没有二进制参数的命令,无需第三个参数
--含有二进制参数的命令,第三个参数为 table 格式
--注意:order 命令里,涉及到二进制的参数,统一用英文问号(?)代替,然后在第三个参数里填二进制参数,一个问号仅对应一个二进制参数
--iOS 和安卓使用有所差异
local ts = require("ts")--使用扩展库前必须插入这一句
local json = ts.json--使用 JSON 模块前必须插入这一句
a = "https://video.touchsprite.com/%E5%85%AC%E5%BC%80%E5%88%86%E4%BA%AB/1234.db"
code,msg = ts.tsDownload(userPath().."/res/1234.db",a)
if  code == 200 then
    --增加数据,groupList 为表名称,id, groupName, groupMembCnt 为 groupList 的列名称,7,7,0 为列名称对应的需要添加的数据
    local result,msg = ts.dborder(userPath().."/res/1234.db","insert into groupList(id, groupName, groupMembCnt) values(7,7,0)")
    if result == 1 then
        mm = json.encode(msg); 
        dialog("添加成功:"..mm ,0)
    else
        dialog("添加失败:"..msg,0)
    end
    --查询,groupList 为表名称,id 为 groupList 的列名称,7 为列名称对应的数据
    local result,msg = ts.dborder(userPath().."/res/1234.db","select * from groupList where id = 7")
    if result == 1 then
        mm = json.encode(msg);
        dialog("查询成功:"..mm ,0)
    else
        dialog("查询失败:"..msg,0)
    end
    --删除,groupList 为表名称,id 为 groupList 的列名称,7 为列名称对应的数据
    local result,msg = ts.dborder(userPath().."/res/1234.db","delete from groupList where id = 7")
    if result == 1 then
        mm = json.encode(msg);
        dialog("删除成功:"..mm ,0)
    else
        dialog("删除失败:"..msg,0)
    end
else
    dialog(msg)
end

注意事项

  • ts.so Android v1.1.5 版本修复操作失败未返回失败原因的问题,但是返回原因固定为查询出错请检查语句和数据库的位置,失败原因也可能为数据库文件不存在。
Copyright 北京帮你玩科技有限公司 2023 all right reserved,powered by Gitbook该文章修订时间: 2024-03-06 17:50:18

results matching ""

    No results matching ""