/*
* This file is part of JGrasstools (http://www.jgrasstools.org)
* (C) HydroloGIS - www.hydrologis.com
*
* JGrasstools is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.jgrasstools.dbs.spatialite.android;
import java.io.File;
import org.jgrasstools.dbs.compat.ASpatialDb;
import org.jgrasstools.dbs.compat.IJGTResultSet;
import org.jgrasstools.dbs.compat.IJGTStatement;
import com.vividsolutions.jts.geom.Envelope;
import jsqlite.Database;
/**
* A spatialite database for android.
*
* @author Andrea Antonello (www.hydrologis.com)
*/
public class GPSpatialiteDb extends ASpatialDb {
public boolean open( String dbPath ) throws Exception {
this.mDbPath = dbPath;
boolean dbExists = false;
File dbFile = new File(dbPath);
if (dbFile.exists()) {
if (mPrintInfos)
logInfo("Database exists");
dbExists = true;
}
Database database = new Database();
database.open(dbPath, jsqlite.Constants.SQLITE_OPEN_READWRITE | jsqlite.Constants.SQLITE_OPEN_CREATE);
mConn = new GPConnection(database);
if (mPrintInfos)
try (IJGTStatement stmt = mConn.createStatement()) {
stmt.execute("SELECT sqlite_version()");
IJGTResultSet rs = stmt.executeQuery("SELECT sqlite_version() AS 'SQLite Version';");
while( rs.next() ) {
String sqliteVersion = rs.getString(1);
logInfo("SQLite Version: " + sqliteVersion);
}
}
return dbExists;
}
@Override
public void initSpatialMetadata( String options ) throws Exception {
if (options == null) {
options = "";
}
String sql = "SELECT InitSpatialMetadata(" + options + ")";
try (IJGTStatement stmt = mConn.createStatement()) {
stmt.execute(sql);
}
}
@Override
public Envelope getTableBounds( String tableName ) throws Exception {
throw new RuntimeException("Not implemented yet");
}
@Override
protected void logWarn( String message ) {
// Log.w("SpatialiteDb", message);
}
@Override
protected void logInfo( String message ) {
// Log.i("SpatialiteDb", message);
}
@Override
protected void logDebug( String message ) {
// Log.d("SpatialiteDb", message);
}
}