-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to run query using REGEXP #151
Comments
Has anyone else from the community tried regex based queries? |
regex does not seem to be a standard function present in SQLite builds - most likely the case for Android and iOS builds. See this |
I see, thank you. Is there any solution ? |
I am trying to found sqlite react native component with support regexp but with no success. I have found cordova phonegap extension that have found solution with Java sqlite connector (Android-sqlite-connector) that supports pcre extension for sqlite instead of default android Database classes. |
builded new .so libs using https://github.com/litehelpers/Android-sqlite-native-driver-regexp-pcre project with latest sqlite version 3.20.1 supporting pcre extension to enable REGEXP function for androind. Integration with android-native : Step 1 - NPM Install npm install --save react-native-sqlite-storage Step 2 - Update Gradle Settings // file: android/settings.gradle ... include ':react-native-sqlite-storage' project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/src/android-native') Step 3 - Update app Gradle Build // file: android/app/build.gradle ... dependencies { ... compile project(':react-native-sqlite-storage') } Step 4 - Register React Package (this should work on React version but if it does not , try the ReactActivity based approach. Note: for version 3.0.0 and below you would have to pass in the instance of your Activity to the SQLitePluginPackage constructor ... import io.liteglue.SQLitePluginPackage; public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { private ReactInstanceManager mReactInstanceManager; private ReactRootView mReactRootView; @OverRide protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setBundleAssetName("index.android.bundle") // this is dependant on how you name you JS files, example assumes index.android.js .setJSMainModuleName("index.android") // this is dependant on how you name you JS files, example assumes index.android.js .addPackage(new MainReactPackage()) .addPackage(new SQLitePluginPackage()) // register SQLite Plugin here .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", null); //change "AwesomeProject" to name of your app setContentView(mReactRootView); } ... Alternative approach on newer versions of React Native (0.18+). Note: for version 3.0.0 and below you would have to pass in the instance of your Activity to the SQLitePluginPackage constructor import io.liteglue.SQLitePluginPackage; public class MainApplication extends Application implements ReactApplication { ...... /** * A list of packages used by the app. If the app uses additional views * or modules besides the default ones, add more packages here. */ @OverRide protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new SQLitePluginPackage(), // register SQLite Plugin here new MainReactPackage()); } } Step 5 - Require and use in Javascript - see full examples (callbacks and Promise) in test directory. // file: index.android.js var React = require('react-native'); var SQLite = require('react-native-sqlite-storage') ...
builded new .so libs using https://github.com/litehelpers/Android-sqlite-native-driver-regexp-pcre project with latest sqlite version 3.20.1 supporting pcre extension to enable REGEXP function for androind. Integration with android-native : Step 1 - NPM Install npm install --save react-native-sqlite-storage Step 2 - Update Gradle Settings // file: android/settings.gradle ... include ':react-native-sqlite-storage' project(':react-native-sqlite-storage').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-sqlite-storage/src/android-native') Step 3 - Update app Gradle Build // file: android/app/build.gradle ... dependencies { ... compile project(':react-native-sqlite-storage') } Step 4 - Register React Package (this should work on React version but if it does not , try the ReactActivity based approach. Note: for version 3.0.0 and below you would have to pass in the instance of your Activity to the SQLitePluginPackage constructor ... import io.liteglue.SQLitePluginPackage; public class MainActivity extends Activity implements DefaultHardwareBackBtnHandler { private ReactInstanceManager mReactInstanceManager; private ReactRootView mReactRootView; @OverRide protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setBundleAssetName("index.android.bundle") // this is dependant on how you name you JS files, example assumes index.android.js .setJSMainModuleName("index.android") // this is dependant on how you name you JS files, example assumes index.android.js .addPackage(new MainReactPackage()) .addPackage(new SQLitePluginPackage()) // register SQLite Plugin here .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); mReactRootView.startReactApplication(mReactInstanceManager, "AwesomeProject", null); //change "AwesomeProject" to name of your app setContentView(mReactRootView); } ... Alternative approach on newer versions of React Native (0.18+). Note: for version 3.0.0 and below you would have to pass in the instance of your Activity to the SQLitePluginPackage constructor import io.liteglue.SQLitePluginPackage; public class MainApplication extends Application implements ReactApplication { ...... /** * A list of packages used by the app. If the app uses additional views * or modules besides the default ones, add more packages here. */ @OverRide protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new SQLitePluginPackage(), // register SQLite Plugin here new MainReactPackage()); } } Step 5 - Require and use in Javascript - see full examples (callbacks and Promise) in test directory. // file: index.android.js var React = require('react-native'); var SQLite = require('react-native-sqlite-storage') ...
Running this query in DB Browser for SQLITE works flawlessly:
SELECT * FROM LSGSAT2 WHERE Texte REGEXP '\b01\b' ORDER BY Livre ASC LIMIT 20
Can't get it to work in the react-native app, I got no results.
Any ideas ?
The text was updated successfully, but these errors were encountered: