Created
July 9, 2015 10:12
-
-
Save Gnafu/f9dac8801aae80e47896 to your computer and use it in GitHub Desktop.
Test Virtual Table CREATE and DROP with Android Spatialite 3.0.1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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