forked from cemaden-educacao/WPD-MobileApp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
2.4 KiB
100 lines
2.4 KiB
import "../config/globals";
|
|
|
|
function transaction(db, query, values) {
|
|
db.transaction((tx) => {
|
|
tx.executeSql(
|
|
query,
|
|
values,
|
|
(_, results) => {
|
|
console.debug("Values inserted successfully" + results.rowsAffected);
|
|
},
|
|
(_, err) => {
|
|
console.debug("Error while inserting values: " + JSON.stringify(err));
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
function insertFloodZone({ images, description, passable, location }) {
|
|
const query = `INSERT INTO FloodZones(Description, Images, Latitude, Longitude, Passable) VALUES(?, ?, ?, ?, ?);`;
|
|
if (location === undefined) {
|
|
console.debug("undefined location");
|
|
return;
|
|
}
|
|
|
|
const values = [
|
|
description,
|
|
JSON.stringify(images),
|
|
parseFloat(location["latitude"]),
|
|
parseFloat(location["longitude"]),
|
|
parseInt(passable),
|
|
];
|
|
|
|
transaction(global.userDataBase, query, values);
|
|
}
|
|
|
|
function insertPluviometerData({ pluviometer, images, date, location }) {
|
|
const query = `INSERT INTO Pluviometer(Date, Images, Latitude, Longitude, Precipitation) VALUES(?, ?, ?, ?, ?);`;
|
|
|
|
if (location === undefined) {
|
|
console.debug("undefined location");
|
|
return;
|
|
}
|
|
|
|
const values = [
|
|
date,
|
|
JSON.stringify(images),
|
|
parseFloat(location["latitude"]),
|
|
parseFloat(location["longitude"]),
|
|
parseFloat(pluviometer),
|
|
];
|
|
|
|
transaction(global.userDataBase, query, values);
|
|
}
|
|
|
|
function insertRainData({ images, rain, location }) {
|
|
const query = `INSERT INTO RainLevel(RainIdx, Images, Latitude, Longitude) VALUES(?, ?, ?, ?);`;
|
|
|
|
if (location === undefined) {
|
|
console.debug("undefined location");
|
|
return;
|
|
}
|
|
|
|
const values = [
|
|
parseInt(rain),
|
|
JSON.stringify(images),
|
|
parseFloat(location["latitude"]),
|
|
parseFloat(location["longitude"]),
|
|
];
|
|
|
|
console.log(values);
|
|
|
|
transaction(global.userDataBase, query, values);
|
|
}
|
|
|
|
function insertRiverData({ images, riverScale, location }) {
|
|
const query = `INSERT INTO RiverLevel(RiverIdx, Images, Latitude, Longitude) VALUES(?, ?, ?, ?);`;
|
|
|
|
if (location === undefined) {
|
|
console.debug("undefined location");
|
|
return;
|
|
}
|
|
|
|
const values = [
|
|
parseInt(riverScale),
|
|
JSON.stringify(images),
|
|
parseFloat(location["latitude"]),
|
|
parseFloat(location["longitude"]),
|
|
];
|
|
|
|
console.log(values);
|
|
|
|
transaction(global.userDataBase, query, values);
|
|
}
|
|
|
|
export {
|
|
insertFloodZone,
|
|
insertPluviometerData,
|
|
insertRainData,
|
|
insertRiverData,
|
|
};
|