'Getting no response while using react-native-sqlite-storage ,
I am trying to execute update query but in response getting nothing.
const editData = async (no) => {
try {
db.transaction((tx) => {
tx.executeSql(
'UPDATE brief_History set para' +
no +
'=?,where id=?',
[value, 2],
(tx, results) => {
console.log('Results', results.rowsAffected);
if (results.rowsAffected > 0) {
Alert.alert('Record Updated Successfully...');
} else Alert.alert('Error');
},
);
});
} catch (err) {
console.log(err);
}
};
Solution 1:[1]
I was having the same problem, you need to verify if the Database was initialized in App.
Example using Expo
import React, { useEffect, useState } from 'react';
import AppLoading from 'expo-app-loading';
const App = () => {
const [InitializedDatabase, setInitializedDatabase] = useState(false);
useEffect(() => {
let tableValues = { table: "User", column: "Username TEXT, Password TEXT" };
createTable(tableValues).finally(() => setInitializedDatabase(true));
}, []);
if (!InitializedDatabase) {
return <AppLoading />;
}
return (
<View />
);
}
const createTable = (value) =>
new Promise((resolve, reject) =>
db.transaction((tx) =>
tx.executeSql(`CREATE TABLE IF NOT EXISTS ${value.table} (${value.column});`,
[],
(_, { rowsAffected, insertId }) => resolve(insertId),
(_, error) => reject(error)
)));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Guilherme Zanetti |