Skip to content
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

How can I create a custom sqlite function in Android? #488

Open
danicomas opened this issue May 25, 2016 · 5 comments
Open

How can I create a custom sqlite function in Android? #488

danicomas opened this issue May 25, 2016 · 5 comments

Comments

@danicomas
Copy link

danicomas commented May 25, 2016

I want to add a function (distance between two points) and I have seen in iOS is more easy. However, in Android I should recompile some c++ connector with ndk. Is this the way? Can someone explain me the correct steps to do my goal? @brodybits @marcucio

@brody4hire
Copy link

brody4hire commented May 25, 2016 via email

@danicomas
Copy link
Author

danicomas commented May 26, 2016

https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/database/sqlite/SQLiteCustomFunction.java uses is discarded for the >= SDK API 17 (4.2) support @brodybits? I think that using this it would be similar as iOS.

@brody4hire
Copy link

In that case you would use androidDatabaseImplementation: 2 when you open the database, and you would modify src/android/io/sqlc/SQLiteAndroidDatabase.java to use your custom function.

@danicomas
Copy link
Author

danicomas commented May 26, 2016

And what do you think about the performance @brodybits? Exist more issues than the classic way?

I have seen this known issue in README.md for example:

INSERT statement that affects multiple rows (due to SELECT cause or using TRIGGER(s), for example) does not report proper rowsAffected on Android in case the built-in Android database used (using the androidDatabaseImplementation option in window.sqlitePlugin.openDatabase)

@brody4hire
Copy link

brody4hire commented May 26, 2016

I think the performance would be better if you rebuild Android-sqlite-native-driver which is built using the Android NDK, but as I said you would have to follow the directions very carefully. The Android-sqlite-native-driver solution was designed to be general-purpose, and it does satisfy the needs of this plugin. I have not done much benchmarking so I cannot draw any definite conclusions.

The easier solution is to use androidDatabaseImplementation: 2 when you open the database and modify src/android/io/sqlc/SQLiteAndroidDatabase.java to use your custom function. This solution would suffer from the known issue if you use an INSERT statement that affects multiple rows. I did not see this issue affect too many users though.

If you need more extensive help I offer priority support packages. Please contact me at brodybits@litehelpers.net or sales@litehelpers.net for more information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants