chromium sqlite load_extension not possible - sqlite

Maybe someone has chromium build experience and can help further:
Dynamic module loading with chromium sqlite seems to be not possible.
Imagine you want to load the spatialite sqlite extension via javascript.
What I did:
db = window.openDatabase("test.sqlite", 1, "test.sqlite", 10000000);
db.transaction(function(tx, myArray) {
tx.executeSql("select load_extension('/home/user/tmp/libspatialite.so');", [], function(tx, result) {
console.log("load_extension spatialite");
},
function(tx, err) { console.log(err);}
);
});
But that ends in "could not prepare statement (1 not authorized to use function: load_extension)".
However, I fetched chromium-24.0.1290.0-1.39.1.x86_64.rpm and tried to build chromium with load module extension enabled, without success.
What I did:
extendend /chromium/src/third_party/sqlite/sqlite.gyp with:
'SQLITE_OMIT_AUTHORIZATION',
extendend /chromium/src/third_party/sqlite/google_generate_amalgamation.sh with:
../configure --enable-load-extension=yes
After spending some hours of failing, I made a feature request chromium bug tracker (web database (sqlite) load_extension is not allowed). I guess this feature request will not even be recognized by the developers, due to their workload.

Related

Saving to SQLite from Chrome Extension

There is a new JSWASM approach that allows saving to SQLite (the fast OPFS way) in the browser via a javascript Worker. A sample is here that is (sort of) for a Chrome extension. Ideally, it would allow saving from the background.js, but it's unclear whether a worker can be called from there in MV3 based on this and this. Does anyone have a simple working example closer to my use case, which is saving content from the user's active tab to a SQLite database? Thanks.
The OPFS depends on the createSyncAccessHandle() method, which is exposed in Worker threads. The usual feature detection goes like this:
if (self instanceof WorkerGlobalScope && 'createSyncAccessHandle' in self.FileSystemFileHandle.prototype) {
// OPFS in `Worker` is supported!
}
Now an extension service worker (as currently implemented in Chrome) is an instance of ServiceWorkerGlobalScope, so the API is not supported there.
Unfortunately at the moment the only choice is to open an extension page and then run the OPFS code from there.

How to solve room data integrity error due to identityHash mismatch?

Issue:
Whenever I make changes to the database or the model, I get the following Room data integrity error:
My understanding is that I shouldn't need to increase the version number since I am using .fallbackToDestructiveMigration().
Background:
I using DB Browser for SQLite (v3.12.0) to make changes to the database.
I frequently make changes to my app/database, which is still in development. So, I am using a .fallbackToDestructiveMigration() (see codelab example).
File: RoomDB.java
#Database(entities =
{Note.class, Label.class, Join_ScheduleLabel.class, Schedule.class},
version = 1)
#TypeConverters(DataConverters.class)
public abstract class RoomDB extends androidx.room.RoomDatabase {
public static final String DATABASE_NAME = "vk_prepop.sqlite";
private static RoomDB INSTANCE;
public static RoomDB getInstance(final Context context) {
if (INSTANCE == null) {
synchronized (RoomDB.class) {
if (INSTANCE == null) {
INSTANCE = Room.databaseBuilder(
context.getApplicationContext(),
RoomDB.class,
DATABASE_NAME)
// Source: https://developer.android.com/training/data-storage/room/prepopulate
.createFromAsset(DATABASE_NAME)
// Todo: Remove Destructive Migration
// Wipes and rebuilds instead of migrating if no Migration object.
.fallbackToDestructiveMigration()
.build();
}
}
}
return INSTANCE;
}
public abstract RoomDao getRoomDao();
}
Troubleshooting Steps Taken:
Verifying the entities of the RoomDB.java file match the models and database.
Going into the App Info and tapping "Clear data" (see SO answer).
Uninstalling the app.
Making setting android:allowBackup="false" in the manifest (see SO answer).
Possible Solution:
In live-love's answer he says there may be an identityHash mismatch, but I am not sure how to resolve this using DB Browser for SQLite.
My understanding is that I shouldn't need to increase the version number since I am using .fallbackToDestructiveMigration().
The fallBackToDestructiveMigration only runs if a migration is required and there is no Migration covering the migration.
In your situation the issue is that you have included the room_master_table in the pre-packaged database and hence the identity_hash columns is available for comparison (which would be incorrect if changes were made to the schema that affected how room generates the identity_hash from the schema).
By including the room_master_table you are introducing an unnecessary complexity.
If you omit this table from the pre-packaged database, then it will be created and populated, with the appropriate identity_hash when it is created from the asset (i.e. when the database doesn't exist). As such you then only have to make the appropriate changes to the asset (the pre-packaged database), delete the current database (e.g. uninstall the App or clear the Apps data) and then run the App.
live-love's answer states that there may be an identityHash mismatch. Indeed this was the case. Here is how I resolved the issue using DB Browser for SQLite (v3.12.0).
Step 1: In Android Studio's project panel choose the "Project" view:
Step 2: Then double-click on the json file for your schema:
Step 3: Copy the identityHash in this json file:
Step 4: Open your database in DB Browser for SQLite. Click the "Browse Data" tab. Then from the drop-down menu choose "room_master_table".
Step 5: Compare the identifyHash from the json file in Android Studio to the identityHash in DB Browser for SQLite. If the hashes are different, this can be the cause of you Room data integrity error.
Step 6: So, paste the identityHash from the Android Studio's json file into the identityHash cell in the DB Browser for SQLite.
Step 7: Then press Ctrl+Shift+S to save the database.
Step 8: Click "Close Database".
Step 9: In your app on your phone or emulator go to "App Info" -> "Storage" -> "Clear data".
Step 10: Then in Android Studio press "Run app".
Problem solved... at least for me. If these steps did not help, please review these additional troubleshooting steps.

GetTwinAsync() are not supported in IoT edge Simulator v0.14.10

GetTwinAsync() returns always Twin object with empty properties, all properties of my IoT edge module are null when I run my IoT edge device in Simulator, in my Linux server works everything fine. I should wait also about 20 seconds to get a response from GetTwinAync().
If we look at it, this problem is expected. If you read this Understand and use module twins in IoT Hub document, then you will see that from module app, only has permission to read desired properties and read/write reported properties. If you check this image below you will understand better.
The lifecycle of a module twin is linked to the corresponding module identity. Modules twins are implicitly created and deleted when a module identity is created or deleted in IoT Hub.
To access all module properties, you can do it from solution back end and require the ServiceConnect permission. You will need Microsoft.Azure.Devices V1.16.0-preview-001 or later. The following is a console app code snippet.
...
RegistryManager registryManager = RegistryManager.CreateFromConnectionString(connectionString);
Module module;
try
{
module = await registryManager.AddModuleAsync(new Module(deviceID, moduleID));
}
catch (ModuleAlreadyExistsException)
{
module = await registryManager.GetModuleAsync(deviceID, moduleID);
}
...
For more detailed explanation and example check this Get started with IoT Hub module identity and module twin (.NET). If your issue still persist then you can open an issue on azure-iot-sdk-csharp repository.

Meteor minimongo insert method not working

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.

Phonegap Sqlite Vacuum

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)

Resources