Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/brodycj/android-sqlite-native-ndk-connector
https://github.com/brodycj/android-sqlite-native-ndk-connector
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/brodycj/android-sqlite-native-ndk-connector
- Owner: brodycj
- License: unlicense
- Created: 2021-03-21T21:52:26.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-14T06:28:13.000Z (over 3 years ago)
- Last Synced: 2024-07-31T00:17:05.887Z (6 months ago)
- Language: Java
- Size: 51.8 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Android SQLite native NDK connector
Java classes with abstract interface layers to provide a simple, easy-to-use Java interface to the NDK library (may be adapted for other Java environments).
With a simple test Android app included.
Based on: [`liteglue / Android-sqlite-connector`](https://github.com/liteglue/Android-sqlite-connector)
by Christopher J. Brody aka Chris Brody mailto:
with some complex API response type enhancements by Luis Silva of OutSystems (luis dot silva at outsystems dot com)
License: UNLICENSE (public domain).
## Dependencies
### Included:
TBD
### Not included
Android NDK library JAR build, from this for example: [`brodybits / android-sqlite-ndk-native-driver`](https://github.com/brodybits/android-sqlite-ndk-native-driver)
## Alternative native library builds
TBD
## Installation
Include the following in your `libs` directory:
- NDK JAR library
- `sqlite-native-ndk-connector.jar`, which is built by simply issuing the `make` command in this project## Testing
There is a simple test project in the `Android-SQLiteConnectorTest` subdirectory. To test:
- Use the `make` command to build the JAR
- Build the NDK JAR
- `cd Android-SQLiteConnectorTest`
- Install the JAR files into the `libs` subdirectory of `Android-SQLiteConnectorTest`
- Use a tool such as Android Studio to build and run (import is needed for newer versions of Android Studio)## Sample API Usage
**IMPORTANT:** Most of the methods described here will throw `java.sql.SQLException` if the sqlite library reports an error or if they detect a problem with the usage.
### First step
Import `io.liteglue` package:
```Java
import io.liteglue.*;
```Get a SQLiteConnector (factory) instance:
```Java
SQLiteConnector myconnector = new SQLiteConnector();
```### Open a database
```Java
File dbfile = new File(getFilesDir(), "my.db");SQLiteConnection mydbc = myconnector.newSQLiteConnection(dbfile.getAbsolutePath(),
SQLiteOpenFlags.READWRITE | SQLiteOpenFlags.CREATE);
```### Prepare and run a simple statement (with no parameters)
```Java
SQLiteStatement mystatement = mydbc.prepareStatement("CREATE TABLE IF NOT EXISTS mytable (text1 TEXT, num1 INTEGER, num2 INTEGER, real1 REAL)");
mystatement.step();
mystatement.dispose();
```**IMPORTANT:** Whenever `SQLiteConnection.prepareStatement()` successfully returns a `SQLiteStatement`, it must be cleaned up using its `dispose()` method.
### Prepare and run a statement with parameter values
```Java
SQLiteStatement mystatement = mydbc.prepareStatement("INSERT INTO mytable (text1, num1, num2, real1) VALUES (?,?,?,?)");mystatement.bindTextNativeString(1, "test");
mystatement.bindInteger(2, 10100);
mystatement.bindLong(3, 0x1230000abcdL);
mystatement.bindDouble(4, 123456.789);mystatement.step();
mystatement.dispose();
```### SELECT data and get row result(s)
```Java
SQLiteStatement mystatement = mydbc.prepareStatement("SELECT * FROM mytable;");boolean keep_going = mystatement.step();
while (keep_going) {
int colcount = colcount = mystatement.getColumnCount();
android.util.Log.e("MySQLiteApp", "Row with " + colcount + " columns");for (int i=0; i