Hi Guys
I’m using SQLite in my app
i create standalone app… when i close my app and then i get back to app again, SQLite stored data Disappears and i have nothing!
Can you help me to fix this?
Thanks
Hey @mohammadhshmnd,
We’ll need to see all the relevant code to try and help you debug this issue. Can you post a code snippet or more ideally a Snack demonstrating how you are saving the data to SQLite and trying to fetch it on subsequent app launches?
Cheers,
Adam
Hi @adamjnav
create table:
componentDidMount() {
const db = SQLite.openDatabase('consult06.db', 1.2, '', 300);
db.transaction(tx => {
tx.executeSql(
'create table if not exists users (id integer primary key not null, user_guid text,user_mobile text, doctor_guid text, doctor_full_name text, doctor_profile_image text, doctor_speciality text, doctor_summary text);',
[],
() => {
this.CheckUserLogin();
console.log('tx.executeSql')
},
(error) => {console.log(error)}
);
}, (error) => console.log(error), () => {
console.log('this.CheckUserLogin()')
}
);
// this.CheckUserLogin();
}
select data:
CheckUserLogin() {
const db = SQLite.openDatabase('consult06.db', 1.2, '', 300);
db.transaction(
tx => {
tx.executeSql('select count(*) as user_count from users ', [], (_, {rows: {_array}}) => {
let userCountQueryList = JSON.parse(JSON.stringify(_array));
let userCount = userCountQueryList[0].user_count;
if (userCount === 0) {
Actions.reset('authentication');
}
},
((error) => {
console.log(error)
})
);
tx.executeSql('select * from users ', [], (_, {rows}) => {
let allRow = JSON.parse(JSON.stringify(rows._array));
let rowCount = JSON.parse(JSON.stringify(rows.length));
console.log("allRow[0].user_guid:: " + allRow[0].user_guid);
console.log("allRow[0].user_guid:: " + allRow[0].doctor_guid);
if (rowCount > 0) {
this.props.setUser(allRow[0].user_guid, allRow[0].doctor_guid, allRow[0].user_mobile);
// registerForPushNotificationsAsync(allRow[0].user_guid);
this._setToken();
Actions.reset('root');
} else {
Actions.reset('authentication');
}
},
((eror) => {
console.log(eror)
})
);
},
null,
function () {
}
);
}
Create Table and Select Data are at the same page!
insert Data in authenticate page:
const db = SQLite.openDatabase('consult06.db', 1.2, '', 300);
db.transaction(
tx => {
tx.executeSql('insert into users (user_guid,user_mobile,doctor_guid,doctor_full_name,doctor_profile_image,doctor_speciality,doctor_summary) ' +
'values (?, ?, ?, ?, ?, ?, ?)', [userGuid, userMobileNumber, doctorGuid, doctorFullName, doctorProfileImage, doctorSpeciality, doctorSummry]);
},
null,
function () {
//console.log('Login User');
}
);
Thanks For Your Help
From quite a few days I was looking for that and after the solution of that I got to know about the saving the data in the SQLite and I was doing a project for the Dell update bios and I did the same.
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.