Browse Source

undefined checks in database transactions

master
GabrielTrettel 4 years ago
parent
commit
585712a25d
  1. 1
      src/app/database/database-connection.js
  2. 2
      src/app/database/database-init.js
  3. 16
      src/app/hooks/selectFromDB.js

1
src/app/database/database-connection.js

@ -3,6 +3,7 @@ import * as SQLite from "expo-sqlite";
function openDatabase() {
const db = SQLite.openDatabase("db.testDb");
// return undefined
return db;
}

2
src/app/database/database-init.js

@ -28,7 +28,7 @@ function createAllTables(db) {
*
*/
function initDatabase(db) {
createAllTables(db);
(db != undefined && db !== null) && createAllTables(db);
}
export default initDatabase;

16
src/app/hooks/selectFromDB.js

@ -140,16 +140,22 @@ function parseResult(db_result, parseRow) {
return warnings;
}
function isAvailable(dataBase) {
return dataBase !== undefined && dataBase !== null;
}
function genericSelect(queriesToParsersMapper, dispatch, isFocused) {
useEffect(() => {
console.log("requesting data");
queriesToParsersMapper.forEach(([query, parser]) => {
global.userDataBase.transaction((tx) => {
tx.executeSql(query, [], (tx, results) => {
dispatch({ increment: parseResult(results, parser) });
if (isAvailable(global.userDataBase)) {
queriesToParsersMapper.forEach(([query, parser]) => {
global.userDataBase.transaction((tx) => {
tx.executeSql(query, [], (tx, results) => {
dispatch({ increment: parseResult(results, parser) });
});
});
});
});
}
}, [isFocused]);
}

Loading…
Cancel
Save