expo-sqlite 返回 undefined 不是 excuteSql 函数中的对象
Posted
技术标签:
【中文标题】expo-sqlite 返回 undefined 不是 excuteSql 函数中的对象【英文标题】:expo-sqlite returning undefined is not an object in excuteSql function 【发布时间】:2021-05-22 05:56:46 【问题描述】:我有这段代码应该让用户登录
反应原生应用
每次点击
登录按钮
总是显示这个错误
undefined 不是对象(评估 'tx.executeSql("SELECT * FROM Student WHERE email = ? AND password = ?", [student.email, student.password]).then')
这是我写的代码
//The database connection
import * as SQLite from 'expo-sqlite';
//const db = SQLite.openDatabase('db.db');
//import SQLite from "react-native-sqlite-storage";
//SQLite.DEBUG(true);
//SQLite.enablePromise(true);
const database_name = "mySchool.db";
const database_version = "1.0";
const database_displayname = "Biometric attendance base";
const database_size = 200000;
const db = SQLite.openDatabase(database_name, database_version, database_name, database_size)
export default db;
// Import db connection for use
import db from '../Database';
getStudent = () =>
const student =
password: this.state.password,
email: this.state.email,
;
db.transaction((tx) =>
tx.executeSql("SELECT * FROM Student WHERE email = ? AND password = ?", [
student.email,
student.password,
], ).then(([tx, results]) =>
alert(results);
if (results.rows.length > 0)
let row = results.rows.item(0);
this.props.navigation.navigate('StudentLogin', data: row );
//resolve(row);
else
alert('Incorrect email and password comnbination');
);
);
这是我点击登录按钮时将运行的代码
【问题讨论】:
你能console.log(results)
并展示输出吗
并显示您的db
的声明位置
它是在顶部导入的。
好的,然后将db
记录到控制台,然后发布结果
已更新问题。实际上,我正在使用snack.expo.io 来创建应用程序。所以我不知道在哪里可以找到console.log
【参考方案1】:
Referenze
db.transaction((tx) =>
tx.executeSql("SELECT * FROM Student WHERE email = ? AND password = ?", [
student.email,
student.password,
], (tx, results) =>
console.log(result);
)
);
【讨论】:
以上是关于expo-sqlite 返回 undefined 不是 excuteSql 函数中的对象的主要内容,如果未能解决你的问题,请参考以下文章