/*
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
package org.geohunter.database;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
public class SQLiteDatabaseWrapper implements ISQLiteDatabase {
private final SQLiteDatabase mSQLiteDatabase;
public SQLiteDatabaseWrapper(SQLiteDatabase writableDatabase) {
mSQLiteDatabase = writableDatabase;
}
public void beginTransaction() {
mSQLiteDatabase.beginTransaction();
}
public int countResults(String table, String selection, String... selectionArgs) {
Cursor cursor = mSQLiteDatabase.query(table, null, selection, selectionArgs, null,
null, null, null);
int count = cursor.getCount();
cursor.close();
return count;
}
public void endTransaction() {
mSQLiteDatabase.endTransaction();
}
public void execSQL(String sql) {
//Log.d("geohunter", "SQL: " + sql);
mSQLiteDatabase.execSQL(sql);
}
public void execSQL(String sql, Object... bindArgs) {
//Log.d("geohunter", "SQL: " + sql + ", " + Arrays.toString(bindArgs));
mSQLiteDatabase.execSQL(sql, bindArgs);
}
public Cursor query(String table, String[] columns, String selection, String groupBy,
String having, String orderBy, String limit, String... selectionArgs) {
final Cursor query = mSQLiteDatabase.query(table, columns, selection, selectionArgs,
groupBy, having, orderBy, limit);
//Log.d("geohunter", "limit: " + limit + ", query: " + selection);
return query;
}
public Cursor rawQuery(String sql, String[] selectionArgs) {
return mSQLiteDatabase.rawQuery(sql, selectionArgs);
}
public void setTransactionSuccessful() {
mSQLiteDatabase.setTransactionSuccessful();
}
public void close() {
Log.d("geohunter", "----------closing sqlite------");
mSQLiteDatabase.close();
}
public boolean isOpen() {
return mSQLiteDatabase.isOpen();
}
}
|