2

SQLite3 doesn't support stored procedures. Is it possible to write custom function on C/C++ and use it in SQL query?

Something like that

SELECT * FROM table WHERE CUST_FUNCTION(name1, name2) = 1

or

SELECT CUST_FUNCTION(name1, name2) FROM table

Maybe you have some good example how to do that.

xMRi
  • 14,982
  • 3
  • 26
  • 59
user479211
  • 1,544
  • 1
  • 12
  • 13
  • Is this on Android? I don't think you can access sqlite from native code in Android, only from the Java based sdk. – Cheryl Simon Nov 08 '10 at 17:38
  • I don't know. I found the code on C. But I don't know how to attach it to Android project. So I asked if it's possible at all. – user479211 Nov 09 '10 at 09:05

3 Answers3

4

Sadly, it appears you cannot.

I was looking at something like this for calculating distance from within a sqlite query - it was sometimes mentioned as a method for doing this.

sqlite does support something like this, so documentation and other references will suggest that this is possible. However, after looking at various sources, I came to the conclusion that, while you can do it in several places that use sqlite (like iPhone I believe), you can't do it in Android's sqlite (at least I didn't find anyone able to do this way in Android).

Here are a couple of links that I had found suggesting it wasn't possible in Android and unfortunately I couldn't find any counterexamples. But I'd love to find I'm wrong about this ...


Android sqlite sort on calculated column (co-ordinates distance)

  • "The technique you describe does not seem to be applicable to Android, which cannot use sqlite3_create_function(). – CommonsWare Jan 9 '10 at 19:00"

Sqlite on Android: How to create a sqlite dist db function - to be used in the app for distance calculation using lat, long

  • org.sqlite is not an Android API, so that is not relevant. – hackbod Mar 1 '10 at 4:59 1
  • You are correct, org.sqlite is not an Android API. However, you can use it to implement a Content Provider that does what he asked. – Joshua Smith Mar 1 '10 at 12:39
  • Actually, I'm rather skeptical on the approach outlined in the content provider answer you link to. org.sqlite is not in Android, and it is unclear if there exists an org.sqlite implementation that will work in concert with Android's SQLite environment. – Pentium10 Jun 27 '10 at 9:12

Community
  • 1
  • 1
Bert F
  • 85,407
  • 12
  • 106
  • 123
0

Yes it might be possible, but that will not be supported officially on Android. We can do that either by writing our shared object in C and SQLite natively. I think, another way would be to java libraries for SQLite instead on relying on Google's libarries

user210504
  • 1,749
  • 2
  • 17
  • 36
-1

I have not done any Android development , but it certainly is possible on other platforms.

Have a look at the sqlite_create_funciton api http://www.sqlite.org/c3ref/create_function.html

Strahd_za
  • 218
  • 2
  • 11