question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: undefined is not a function(near '...sql.transaction...')

See original GitHub issue

I 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:closed
  • Created 6 years ago
  • Comments:14

github_iconTop GitHub Comments

4reactions
maxlxqcommented, Dec 12, 2017

解决了吗,我前几天发现修改为SQLite.enablePromise(false);就可以了

2reactions
Amaceliacommented, Feb 24, 2020

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:

    return new Promise((resolve) => {
      db.transaction(function(tx) {
        //get last/most recent table name
        //read last 10 values from table
        tx.executeSql(
          'SELECT name FROM sqlite_master WHERE type="table"',
          [],
          function(tx, results) {
            var currTableNum = results.rows.length - 1;
            var currTableName = results.rows.item(currTableNum);
            console.log('PPM: ...reading last 10 values from table', currTableName);
            this.setState({tableName: currTableName});
          }
        );
        console.log('printing currtablename: ', this.state.tableName);
        tx.executeSql(
          'SELECT * FROM "?" ORDER BY ppm DESC LIMIT 10',
          [this.state.tableName],
          function(tx, results) {
            var total = 0;
            for (let i = 0; i < results.rows.length; i++) {
              total = total + results.rows.item(i);
              console.log('PPM: item to add: ', results.rows.item(i));
            }
            total = total / results.rows.length;
            console.log('PPM: setting ppmVal state: ', total);
            this.setState({ppmVal: total});
          }
        );
      });
    });
  }
Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeError:undefined is not a function ..{near ...db.transacation ...
I just removed 'SQLite.enablePromise (true);' and everything worked. It seems to me that I followed the wrong documentation.
Read more >
'Uncaught TypeError: undefined is not a function' when using ...
Hi, I downloaded PGTest application, which I found from your knoweldge base. I am trying to use SQLitePlugin and cordova.js file; ...
Read more >
Sqlite: db.transaction is not a function - AppStudio
I get this error message in javascript console. Error encountered: Uncaught TypeError: db.transaction is not a function. Url: http://127.0.0.1: ...
Read more >
node-mssql | Microsoft SQL Server client for Node.js
Providing a different connection config to the connect() function will not create a new connection if it is already connected. const sql =...
Read more >
[Solved]-TypeError: store.getState is not a function. (In 'store ...
[Solved]-TypeError: store.getState is not a function. (In 'store.getState()', 'store.getState' is undefined how can i resolve this problem?-React Native.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found