TypeError: undefined is not a function(near '...sql.transaction...')
See original GitHub issueI got the error like this:TypeError: undefined is not a function(near ‘…sql.transaction…’) my code is: import SQLite from ‘react-native-sqlite-storage’;
SQLite.DEBUG(true); SQLite.enablePromise(true); var database_name = “test.db”;//数据库文件 var database_version = “1.0”; var database_displayname = “MySQLite”; var database_size = -1; var sql; let tableName = ‘user’;
export default class InitSql { init(){ sql = SQLite.openDatabase( database_name, database_version, database_displayname, database_size, ()=>{ // this._successCB(‘open’); this.createTable(); }, (err)=>{ console.log("SQL Error: " + err); } ); }
create(){
sql.transaction((tx)=>{
tx.executeSql(`CREATE TABLE IF NOT EXISTS ${tableName}(
${UserBean.id} INTEGER PRIMARY KEY AUTOINCREMENT,
${UserBean.num} VARCHAR,
${UserBean.name} VARCHAR)`
, [],_openCB,_errorCB)
});
}
}
when I used ‘create’ to create a table,I got this error.And I tried another way like this: SQLite.openDatabase({name: ‘my.db’, location: ‘default’}, (DB)=>{ sql=DB; }, errorcb); And not work too.
Issue Analytics
- State:
- Created 6 years ago
- Comments:14
解决了吗,我前几天发现修改为
SQLite.enablePromise(false);
就可以了Giving my two cents because I’ve reached this page (even though it’s been three years since the original question, and two years since the last comment)
Seems as though you can do:
SQLite.DEBUG(true);
SQLite.enablePromise(true);
And then use this ‘new promise’ section to handle it: