I want to process two different SQL databases in one application. Unfortunately, DB.filename always returns “local” and - see SQLSample1 btnClear.
Currently, the databases are interfering with each other, even in different applications. Is there a solution? Am I missing something?
Have a look at this document. Under Restrictions, it’s noted that you now can only have one database. (point 2)
The usual workaround is to put the tables from all the databases into a single database.
Oh dear, thanks for the tip.But is there a way to export just one table
to the web server using Ajax and then import it back from the web server
later?With Ajax (…PHP/AjaxPOST.php", “POST”, DBjson, done), the entire
database always arrives. I need only a part of all. Best regards, Paparazzi
Here’s some sample code which dumps a table into a JSON string named res:
let res;
function SQLDumpJSON(DB, table) {
res = "";
datahandler = (transaction, results) => {
res = JSON.stringify(results.rows.rows);
};
sqlList = [];
sqlList.push([`SELECT * from ${table};`, datahandler]);
Sql(DB, sqlList);
console.log("returning from SQLDumpJSON", res);
}
Oh thank you, I’ll try that in Basic
The other way arround is also working?
(in Basic)
The other way around?
I mean the Import …
Okay, thank you, that works now.
Please give me also the part from JSON String bak to the Table in SQLite.
Thank you
That’s not as simple. Since you’re importing outside data, security is a consideration. Here’s the classic XKCD cartoon…
Another thing to worry about is if the table changes.
It’s easy to take an input JSON formatted string and parse into an array. A simple FOR loop through the array will bring up each row. You can then use SQLite’s INSERT command to add the rows to your database.
But how I bring the JSON formatted string from that table back in an Array?
I see only the special format as html.
Do you mean JSON.parse()?
rows = JSON.parse(res)