We have an offline capable tablet app using VSNomad (through Phonegap) with Sqlite local database. One thing I've noticed is when we delete all data from tables and drop tables (doing an "app reset") on an iPad it doesn't reflect that space has been opened up.
I've come across "VACUUM" command for Sqlite however I am unsure how/if this can be used with our implementation. When I tried to run it I get an error saying cannot run within a transaction.
Here's examples of how we're implementing
http://docs.phonegap.com/en/2.7.0/cordova_storage_storage.md.html#Storage
app.shared.db().transaction(function (tx) {
tx.executeSql('VACUUM', [], function (tx, results) {
alert('done');
}, function (tx, error) {
alert('error');
alert(error.message);
});
});
Is it possible to run a vacuum like this?
I implemented your code and I get:
E/SQLiteQuery(18724): exception: not an error; query: VACUUM
Searching a bit further I found out that the vacuum sql command can not be given while connected to the database, so cannot be run from the database open and transaction from within javascript nor phonegap. Can only be given from command line.
But there must be another way... (looking in to that).
For now I have a few suggestions for database management:
Make sure you can delete the app and start with a fresh database (see below)
Prevent growing of the database: empty table and not drop table all the time (transaction.executeSql('DELETE FROM tablename;');) Note: don't use the '*' mark
Populate your database if it's the first run, see: http://mebefreelancer.wordpress.com/2012/08/14/phonegap-if-database-exists-do-something-else-populate-database/
Try to set up your app in a way the database is being migrated in a nice way: see enter link description here (a django /south kind of way for migrations)
Related
I have a calculated table that uses a join statement SQL query as its data source. good. Works fine.
But then I'm trying to add in the use of :Parameters and my attempts to create a default if it equals null are not working.
I tried this (In the onLoad client script):
if (app.datasources.Relations.query.parameters.x== null){
console.log("No xfound,using >");
app.datasources.Relations.query.parameters.x= ">";}
It works, but not on the initial load (it appears to apply AFTER the first load).
So I decided to try and bake it into the sql statement that makes the table like this, but all three of these iterations failed with "check your version of mysql" errors.
AND b.CSI_Code REGEXP select if(:x= null, "<",:x)
AND b.CSI_Code REGEXP select if(:x== null, "<",:x)
AND b.CSI_Code REGEXP select if(:x=== null, "<",:x)
I've got a workaround going where I set my parameters to the APP onload rather than the datasource onload,but ultimately I think it would be cleaner if I could get the SQL if nul set to default (">") part working.
If you have access to the Google Cloud Platform where your database is hosted, it lists the database version in the instance information (see picture). Per the FAQ, the options are currently MySQL 5.5, 5.6, or 5.7. If you click into the instance, and go to the Databases tab, each app has its own database with a name like "Wc7cVzeGEvbPjxj4". To confirm which database your app uses, the name should be listed in your Google App Maker app under (Your app in the developer GUI) > Settings Cog Icon > Database > Database Key.
I recently changed some code I have using SQLite via better-sqlite3 to check if a table exists before running certain import queries.
The code and tests all run fine. But the tests don't pass on our build machines or on another developers machine. The tests are using an in-memory database, the problem hasn't occurred on any non-memory databases though it has only been ran on a half-dozen machines. There are tables in the database and code is able to read/write to them.
It turns out that the query I was using to check what tables I can import from was return an empty result. In fact, if I just query anything at all from sql_master in these cases I get an empty result.
// db is a database from better-sqlite3
private async getAllTables() {
var query = connection.db.prepare(`SELECT name, type FROM sqlite_master`).raw();
return query.all();
}
var allTables = await this.getAllTables();
console.log(`all things in sql_master: ${await allTables.join(", ")}.`);
The console has the following logged on the problematic matchines:
All things in sql_master: .
Locally it prints a list of all the things in sql_master as you'd expected. All the other queries my test code is doing is working as expected (reading and writing to tables besides sql_master).
The database was created like:
db = new Connection(":memory:", { memory: true, fileMustExist: true });
I have a CosmosDB collection with a number of different partitions. I want to delete all of the data in one of the partitions so I tried to run the command:
db.myCollection.deleteAll({PartitionKey: 'pop-9q'})
Where PartitionKey is the field that I partition/shard based on. But when I execute this it returns the not very helpful message:
ERROR: An Error has occurred
Why would I be getting this message and how can I either get more details on the cause or find a resolution?
Currently, at this time, you are unable to perform a bulk delete. Please Up Vote and Comment on this functionality: Add the ability to delete ALL data in a partition
Additionally, which API are you consuming? For Gremlin API you could execute something like the following: g.V().drop()
The Microsoft.Azure.Cosmos SDK has added this ability - currently only available as a preview feature (which requires you to opt-in via the portal)
See here for more details:
https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/how-to-delete-by-partition-key?tabs=dotnet-example
Sample code included there:
// Get reference to the container
var container = cosmosClient.GetContainer("DatabaseName", "ContainerName");
// Delete by logical partition key
ResponseMessage deleteResponse = await container.DeleteAllItemsByPartitionKeyStreamAsync(new PartitionKey("Contoso"));
if (deleteResponse.IsSuccessStatusCode) {
Console.WriteLine($"Delete all documents with partition key operation has successfully started");
}
As #Mike said, a "delete all data" feature is not supported yet in Cosmos db SQL API and Mongo API. I notice that you have already added comments in above link. I just provide you with a workaround here that using bulk delete stored procedure for Cosmos db SQL API.
(sample code: https://gist.github.com/deepumi/2a23c5380202bddf0b85e83baf5833be)
For Mongo API, unfortunately, even stored procedure is not supported. You could create an Azure HTTP Trigger Function to execute bulk delete code in the function whenever you want or merge it into your program code.
I am getting this error "QSqlError("5", "Unable to fetch row", "database is locked")"
I have done my research and I think the problem arises from the fact that I am executing an INSERT query while the SELECT query is still active, which locks the database. Now I'd imagine people run into this problem often since it is common to write to a database based on the output of a SELECT query, so I wanted to ask what is the best way to solve this? Would I be able to fetch the query (using query.next()) after closing it with query.finish() to unlock the database? Or should I store the result in a temporary container, close the query then iterate over the temporary container?
Thank you very much in advance
Do you have a database reader on when you run this? I had a similar issue that only occurred when I had DB Browser for SQLite running. Make sure that you don't have any other software that has your database file open. I don't always have this issue with using DB Browser for SQLite but when I do, closing the program fixes it.
It addition, I tend to run query.finish() after each query is complete, to ensure no interaction.
I hope this helps you out!
I was following the meteor tutorial from meteortips and I got to the part where you create a collection in the browser's console. Creating the collection works, but it doesn't let me insert anything into it.(PlayersList = new Meteor.Collection('players');)
Please see below:
PlayersList.insert({ name: 'Alex', score: 42 });
"rpPamgZEZM9opCzHz"
debug.js:41 insert failed: Method not found
What's weirder is that I even get back the hash as if the insert worked.
Typing PlayersList.find().fetch(); returns an empty array :(
I'm using the latest version of Meteor on Windows 8.1 with MongoDB version 2.6
If anybody could help me, I would be very thankful :)
You have defined the collection PlayersList = new Meteor.Collection('players'); on the client but it has not been defined on the server.
If you have something like if(Meteor.isClient) {..} (or in the /client) directory the code won't run on the server. Make sure you also place a PlayersList = new Meteor.Collection('players'); in the if(Meteor.isServer) (or the /server) directory.
The best thing to do is place it outside both in the root directory so it runs on both the client and server.
When you insert the document on the client the message is transmitted to the the server & it tries to insert it into the database. The collection isn't defined on the server side so it rejects it with the message method not found.