Closed richard457 closed 3 years ago
Parameters don't seem to work with with live queries, probably by design.
Just use standard query string.
final q = Query(db, 'SELECT * WHERE table="users"');
Also when you add a change listener the query is run automatically, so there's no need to call q.execute()
Edit: I'll do some test and see if I can add a warning when parameters are used in live queries.
I checked on windows and paramaters do work with live queries. It might be an Android specific issue.
I got the query to at least log propper like this Compiling N1QL query: SELECT * WHERE table="users"
but still can not get it to work.
It's actually Flutter.
Add WidgetsFlutterBinding.ensureInitialized();
as the first line of your main() function.
Just a heads up, I renamed the query.setParameters
method to query.paramaters
(which I released as v0.3.1), because it's a setter not a method.
Parameters do work and I could get your code running on Android, the thing with parameters and live queries is that setting the parameters on query once it's being listened to does nothing to the listeners. You need to remove the listener and add it again, I believe to get the new query.
Changed the query to
final q = Query(db, 'SELECT * WHERE table=\$VALUE');
q.parameters = {'VALUE': 'users'};
and added this WidgetsFlutterBinding.ensureInitialized();
as first line in main file
Adding change lister crash the app
q.addChangeListener((List results) {
print('New query results: ');
print(results);
});
I think it might be related to android version we are using.
compileSdkVersion 29
minSdkVersion 22
targetSdkVersion 29
I have the same sdk version, I don't think Android is the issue. Your original code works fine with the Flutter bindings initialized.
I really tried the whole day, I can not get the live query to work here is my project I test on COUCHBASE_LITE_DART EXAMPLE APP by any chance if you can take a look at it, would appreciate, I want to use this plugin for our project that we want to run on mobiles and desktop as future.
Also, I am committed to testing the plugin and share the test code on the above codebase so other people can reference it.
You must call Cbl.init(); to set up the ports between Dart and C, so callbacks can work.
Thank you so much @Rudiksz I got it working and I updated the sample application with Crud operation, will keep updating the example app for anyone to cross reference.
First, thank you for your kind support and I really appreciate this work, I tested all function of the plugin and I can not get a live query to work, it crashes the app completely. please help me, I thank you in advance.