Fwd: libjsqlite and C#

43 views
Skip to first unread message

Mark Johnson

unread,
Jun 28, 2015, 9:41:22 PM6/28/15
to spatiali...@googlegroups.com

---------- Forwarded message ----------
From: Jim O'Brien <j...@jgssebl.net>
Date: 2015-06-29 3:01 GMT+02:00
Subject: libjsqlite and C#
To: mj1...@googlemail.com


Mark,
 
I apologize for contacting you directly but Sandro suggested that I do so.
 
I am about the "bite the bullet" and rewrite some of  my personal apps and try to use your libjsqlite and adopt callbacks although I may have to rethink the whole structure of some of my code.
 
 
I see that libjsqlite is a ".so" file.
 
So the key questions are:
 
1. Is there a Jar  file that includes the JNI calls. I ask because Xamarin only handles .so files by way of P/Invoke and that is related the the issue I now have with Marshalling.
 
However, Xamarin can build C# mappings to a jar file which I have done in another situation.
 
Do you have an example or a pointer to an example of a C# program that uses your libjsqlite so I can see what the structure of a C# program is in this case?
 
I only need Open, Close, "Query using Spatialite functions", and associated data extraction from the query results. 
 
I been doing this stuff for 50 years but only worked with Java for about 5 years but switched to C# because it better served my purposes writing m own personal use apps originally on Windows.
 
I switched to Android for a variety of reasons and Xamarin allowed me to convert most of my apps using vanilla Sqlite. 
 
But some of the apps need Spatialite and thus my quandary. 
 
I had something (Spatialite_Net_Examples) which worked sometimes but would fail with stack traces without explanation but I think it had to do with Marshalling strings returned from Sqlite.
 
The most important of those apps is one that tracks my wife (she has Alzheimer's) and she carries a locator that I read through a third party and process to a map and I like the interface that I now use.
 
So, if you can be of any assistance I would greatly appreciate it.
 
Regards,
Jim O'Brien
 

mj10777

unread,
Jun 28, 2015, 11:44:01 PM6/28/15
to spatiali...@googlegroups.com
I have forwarded this note, since I believe it is of general interest who want to get an android c# class working





Mark,
 
I apologize for contacting you directly but Sandro suggested that I do so.
 
I am about the "bite the bullet" and rewrite some of  my personal apps and try to use your libjsqlite and adopt callbacks although I may have to rethink the whole structure of some of my code.
 
 
I see that libjsqlite is a ".so" file.
Yes, because I understood from your first message that you desired a direct interface to the underlining c-api 
 
So the key questions are:
 
1. Is there a Jar  file that includes the JNI calls. I ask because Xamarin only handles .so files by way of P/Invoke and that is related the the issue I now have with Marshalling.
No, no idea 
 
However, Xamarin can build C# mappings to a jar file which I have done in another situation.
 
Do you have an example or a pointer to an example of a C# program that uses your libjsqlite so I can see what the structure of a C# program is in this case?
No, I have not used c# for many years and never with android 
 
I only need Open, Close, "Query using Spatialite functions", and associated data extraction from the query results. 
In the original thread, a second user, seems to have a similar need.
There I have suggested to adapt the 'javasqlite-20120209' portion of the project
- to a C# mapping (as apposed to the present Java mapping)
-- sqlite_jni.c and sqlite_jni.h
--- and does exactly what you want

Let us assume that this c# specific c-source is called 'cs_sqlite' 
-- sqlite_cs.c and sqlite_cs.h
replacing the java-mapping with valid c#-mapping
- retaining the existing sqlite, spatialite and rasterlite2 code found mainly in :
JNIEXPORT void JNICALL
Java_jsqlite_Database__1open4(JNIEnv *env, jobject obj, jstring file, jint mode, jstring vfs, jboolean ver2)
{
}

With an adapted sqlite_jni.c and sqlite_jni.h for c# (as csqlite.mk)
- an 'libcsqlite.so` could be created for an 
Android_CS4.3.0.mk      --> spatialite only
Android_RCS4.3.0.mk   --> spatialite with rasterlite2
Then a c# 'public class Database', using 'libcsqlite.so`
- would define a typical c# Database class (possibly just extending the existing c#-sqlite-driver)

That class would be then an internal c# class.

As stated I have never used c# in android.
But I seem (to vaguely) remember, that a completed c# application is wraped into a something that will run on android
- being an internal c# class, the functionality in a created 'libcsqlite.so` would be taken over

If you look at
geopaparazzispatialitelibrary/src/jsqlite/Database.java

you will see inside the 'open' function
_open4(filename, mode, vfs, ver2);
which inside  libjsqlite.so does everything that following would do:
SELECT load_extension('/usr/local/lib/mod_spatialite');
SELECT load_extension('/usr/local/lib/mod_rasterlite2');

This, very theoretically, would seem to me the cleanest solution
- everything needed for the spatialite/rasterlite2 connection being done in one place (sqlite_cs.c and sqlite_cs.h)
-- with the c# used only opening the connection, after-which any spatial/rasterlite2 sql-query could be executed
--- retrieving the result returned from the query

I would gladly add the result to the 
- libjsqlite-spatialite-android
project, then keeping the compiled results of libjsqlite.so and libssqlite.so
- upto date with the latest spatialite and rasterlite2 versions


 
I been doing this stuff for 50 years but only worked with Java for about 5 years but switched to C# because it better served my purposes writing m own personal use apps originally on Windows.
 
I switched to Android for a variety of reasons and Xamarin allowed me to convert most of my apps using vanilla Sqlite. 
 
But some of the apps need Spatialite and thus my quandary. 
 
I had something (Spatialite_Net_Examples) which worked sometimes but would fail with stack traces without explanation but I think it had to do with Marshalling strings returned from Sqlite.
 
The most important of those apps is one that tracks my wife (she has Alzheimer's) and she carries a locator that I read through a third party and process to a map and I like the interface that I now use.
This, BTW, would also be interesting for geopaparazzi.
One of its major function is a 'help' button, so that in an emergency situation an SMS with position-Information could be sent to pre-defined number
- this (as well as geopaparazzi with maps and fotos of the area) is used by rescuers to find people lost or injured in the alps
So adding such a functionality to find the present position of the injured person being searched for would be useful
- not to forget, that sometimes, the rescuers themselves, need to be rescued
 
So, if you can be of any assistance I would greatly appreciate it.
I hope this helps and will be interested hearing of any result.
 
Regards,
Jim O'Brien
 

Reply all
Reply to author
Forward
0 new messages