反应本地SQLite存储不为Android返回任何东西

时间:2018-10-10 10:09:03

标签: react-native-android

  

在React Native应用程序中,我试图使用sqlite存储。我是   试图执行一个简单的查询,并试图知道   行

     

代码:-

    var SQLite = require('react-native-sqlite-storage')
    var db = SQLite.openDatabase({name:'prabhuji.db',createFromLocation:1},openCB,errorCB)
const errorCB = (err) => {
    console.log("SQL Error: " + err);
  }
  const openCB = () => {
    console.log("Database OPENED");
  }
    class PredefinedLayout extends React.Component{
        constructor(props){
            super(props);
           this.props.navigator.setOnNavigatorEvent(this.onNavigatorEvent);
            this.props.navigator.setStyle({
                navBarTextColor: '#b4b0af'
            });
            db.transaction((tx)=>{
                alert(JSON.stringify(tx));
               tx.executeSql('SELECT * FROM predefinedcart',[],(tx,results)=>{
                    var len = results.rows.length;
                    alert(len);
                })
            })
        }
    }
  

我已经在android / app / src / main / assets文件夹中创建了prabhuji.db。

还尝试更改:-

var db = SQLite.openDatabase({name:'prabhuji.db',createFromLocation:'~prabhuji.db'},openCB,errorCB)

但没有任何显示。你能建议我做错什么吗?

0 个答案:

没有答案