Skip to content

Instantly share code, notes, and snippets.

@Gnafu
Created July 9, 2015 10:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gnafu/f9dac8801aae80e47896 to your computer and use it in GitHub Desktop.
Save Gnafu/f9dac8801aae80e47896 to your computer and use it in GitHub Desktop.
Test Virtual Table CREATE and DROP with Android Spatialite 3.0.1
import jsqlite.*;
[...]
/**
* Tests the creation of a virtual table
*/
public void testVirtualTableCreation() {
final String TAG = "test_VTCreate";
final Context context = getInstrumentation().getTargetContext();
File sdcardDir = Environment.getExternalStorageDirectory();
File spatialDbFile = new File(sdcardDir, SpatialiteUtils.APP_PATH + "/testing.sqlite");
jsqlite.Database spatialiteDatabase = new jsqlite.Database();
// Callback for logging
jsqlite.Callback callback = new Callback() {
@Override
public void columns(String[] coldata) {
for (String s : coldata){
Log.d(TAG, "Column: "+s );
}
}
@Override
public void types(String[] types) {
for (String s : types){
Log.d(TAG, "Type: "+s );
}
}
@Override
public boolean newrow(String[] rowdata) {
for (String s : rowdata){
Log.d(TAG, "Data: "+s );
}
return false;
}
};
try {
spatialiteDatabase.open(spatialDbFile.getAbsolutePath(), Constants.SQLITE_OPEN_READWRITE | Constants.SQLITE_OPEN_CREATE);
} catch (jsqlite.Exception e) {
e.printStackTrace();
Log.e(TAG, e.getMessage());
fail("Error opening the database");
}
assertNotNull(spatialiteDatabase);
try {
// Log versions
Log.d(TAG, "dbVersion() : " + spatialiteDatabase.dbversion());
spatialiteDatabase.exec("SELECT spatialite_version( );", callback);
spatialiteDatabase.exec("SELECT proj4_version( );", callback);
spatialiteDatabase.exec("SELECT geos_version( );", callback);
Log.d(TAG, "Running CREATE");
spatialiteDatabase.exec("CREATE VIRTUAL TABLE idx_test USING rtree(pkid, xmin, xmax, ymin, ymax);", callback);
Log.d(TAG, "Running DROP");
spatialiteDatabase.exec("DROP TABLE idx_test; ", callback);
} catch (jsqlite.Exception e) {
e.printStackTrace();
Log.e(TAG, e.getMessage());
fail("This should not happen");
}
try {
spatialiteDatabase.close();
} catch (jsqlite.Exception e) {
// Ignore
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment