database - 反应原生 react-native-sqlite-storage 不工作
问题描述
我在我的项目中使用 react native react-native-sqlite-storage 并创建了 2 个表,但是在选择查询中,此代码不打印任何内容。
import {openDatabase} from "react-native-sqlite-storage";
.
.
.
export function selectAllData() {
const db = openDatabase({name: 'myDb.db'});
db.transaction(function (txn) {
txn.executeSql('SELECT * FROM TABLE_NAME', [], (tx, results) => {
let len = results.rows.length;
console.log('len', len);
for(let i = 0; i < len; i++)
console.log(results.rows.item(i));
});
})
}
我希望这段代码打印表格的所有行,但没有打印。
解决方案
尝试这个
db.transaction(tx => {
tx.executeSql('SELECT * FROM TABLE_NAME', [], (tx, results) => {
var temp = [];
for (let i = 0; i < results.rows.length; ++i) {
temp.push(results.rows.item(i));
}
console.log('TABLE_NAME', temp)
});
});
推荐阅读
- c# - 按属性将对象分组到字典
- python - 如何在条件下加入 XML 标签(Python)?
- google-cloud-platform - 如何在 GCP 控制台中查看所有当前正在运行的计算引擎实例的列表?
- forms - 根据使用google form的选择转到另一个表格
- python - 使用机器学习将两个数字相加的模型
- android - 来自arraylist中多个项目的android autocompletetextview
- mysql - SQL - 将自定义属性表的数据加入 SELECT 中的主表
- java - Java中的双重比较失败
- ios - 如何在 iOS 中使用 Alamofire 和 Decodable 为嵌套 JSON 响应配置模型类
- scilab - 如何绘制函数 4(x)^2 = ((y)^2/(1-y))?