Hi there,
I need help. Have been stuck at one point since 2 days. I’m not able to create, save get data from the table using SQLite API provided by Expo. It would be a great help if anyone can help me figure out what is wrong with my project.
I have created the project using create react native boilerplate. Below is the code in my App.js
import * as Expo from "expo";
import React from 'react';
import { View, Text } from 'react-native';
const db = Expo.SQLite.openDatabase('mydb.db');
export default class App extends React.Component {
constructor() {
super();
this.state = {
isPreparingDb: true,
};
}
componentDidMount() {
this.prepareDb();
}
prepareDb() {
db.transaction((tx) => {
tx.executeSql('drop table tabletest;');
tx.executeSql('create table if not exists tabletest (id INTEGER PRIMARY KEY, sym text, name text);');
console.log('table created');
}, null, function () {
console.log('done?.');
});
this.setState({ isPreparingDb: false });
}
render() {
if (this.state.isPreparingDb) {
return (
<View>
<Text>Loading...</Text>
</View>
);
}
return (
<View>
<Text>Loaded, data ready</Text>
</View>
);
}
}
It prints “table created” on the console. It doesn’t print “done” though when I run the project via expo. Above is minimal code, in other file, i make connection again to the same db and run “SELECT * FROM tabletest”, after that I get error, “no such table: tabletest (code 1): , while compiling: SELECT * FROM tabletest”
It clearly seems that table is not created at all. What could be the cause for this API not working?
I have
node:- v8.9.1
npm:- 5.5.1
sdkVersion: 26.0.0
react: 16.3.0-alpha.1
react-native: 0.54.0