通过db对象执行sql语句
使用说明
| 客户端 |
Android |
iOS |
| 支持说明 |
支持 |
支持 |
import { SqlitePlus } from "@yl/super-jssdk";
SqlitePlus.executeSql(optional);
参数说明
| 参数 |
类型 |
必填 |
作用 |
| optional |
Object |
是 |
必填参数 |
optional
| 参数 |
类型 |
必填 |
作用 |
| sql |
string |
是 |
sql语句 |
| dbName |
string |
否 |
数据库名 |
| parameters |
array |
否 |
sql语句的参数值数组 参数,匹配?符号 |
返回说明
| 参数 |
类型 |
作用 |
| resolve(result) |
Function |
成功回调,result为一个json对象,详情请参照下方result字段说明 |
| reject(err) |
Function |
失败回调,err为详细错误信息,是一个json对象,例如:{"errCode":-1,"errMsg":"出错啦"} |
result字段说明
| 参数 |
类型 |
作用 |
| rows |
json |
用于返回sql查询结果,例如:获取第一条记录:result.rows.item(0) |
| executionTime |
long |
此条sql语句执行时间,单位毫秒 |
| rowsAffected |
int |
有多少记录受到影响 |
| insertId |
int |
最后一条插入的记录的rowid |
代码示例
const sql = "insert into user(id,name,age) values(?,?,?);"
const parameters = ['333', '王五', 20]
SqlitePlus.executeSql({sql, parameters})
.then((res) => {
console.log("success", res);
})
.catch((err) => {
console.log("fail", err);
});