我有一个函数可以在 expo react 本机项目的 sqlite 数据库中删除一个表。当该表存在于数据库中时,该console.log语句将打印table dropped。但是,如果我连续两次运行相同的函数,我希望它会说no results,因为它之前已经被删除了,但是控制台上没有打印任何内容。
这是为什么?我该如何解决这个问题?我想知道 sqlite 交易是否失败。
db.transaction(tx => {
tx.executeSql(
'DROP TABLE tableName;',
[],
(tx, results) => {
if (results && results.rows && results.rows._array) {
/* do something with the items */
// results.rows._array holds all the results.
console.log(JSON.stringify(results.rows._array));
console.log('table dropped')
}else{
console.log('no results')
}
}
)
});