Skip to content

Support Cursor.getType() for all Android API versions #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/net/sqlcipher/AbstractCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* This is an abstract cursor class that handles a lot of the common code
* that all cursors need to deal with and is provided for convenience reasons.
*/
public abstract class AbstractCursor implements android.database.CrossProcessCursor {
public abstract class AbstractCursor implements android.database.CrossProcessCursor, net.sqlcipher.Cursor {
private static final String TAG = "Cursor";

DataSetObservable mDataSetObservable = new DataSetObservable();
Expand All @@ -56,9 +56,7 @@ public abstract class AbstractCursor implements android.database.CrossProcessCur
abstract public double getDouble(int column);
abstract public boolean isNull(int column);

public int getType(int column) {
throw new UnsupportedOperationException();
}
abstract public int getType(int column);

// TODO implement getBlob in all cursor types
public byte[] getBlob(int column) {
Expand Down
2 changes: 0 additions & 2 deletions src/net/sqlcipher/CrossProcessCursorWrapper.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package net.sqlcipher;

import android.database.Cursor;
import android.database.CrossProcessCursor;
import android.database.CursorWindow;
import android.database.CursorWrapper;

public class CrossProcessCursorWrapper extends CursorWrapper implements CrossProcessCursor {

Expand Down
62 changes: 62 additions & 0 deletions src/net/sqlcipher/Cursor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2006 The Android Open Source Project
*
* 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 net.sqlcipher;

/**
* Extension of android.database.Cursor to support getType() for API < 11.
*/
public interface Cursor extends android.database.Cursor {
/*
* Values returned by {@link #getType(int)}.
* These should be consistent with the corresponding types defined in CursorWindow.h
*/
/** Value returned by {@link #getType(int)} if the specified column is null */
static final int FIELD_TYPE_NULL = 0;

/** Value returned by {@link #getType(int)} if the specified column type is integer */
static final int FIELD_TYPE_INTEGER = 1;

/** Value returned by {@link #getType(int)} if the specified column type is float */
static final int FIELD_TYPE_FLOAT = 2;

/** Value returned by {@link #getType(int)} if the specified column type is string */
static final int FIELD_TYPE_STRING = 3;

/** Value returned by {@link #getType(int)} if the specified column type is blob */
static final int FIELD_TYPE_BLOB = 4;

/**
* Returns data type of the given column's value.
* The preferred type of the column is returned but the data may be converted to other types
* as documented in the get-type methods such as {@link #getInt(int)}, {@link #getFloat(int)}
* etc.
*<p>
* Returned column types are
* <ul>
* <li>{@link #FIELD_TYPE_NULL}</li>
* <li>{@link #FIELD_TYPE_INTEGER}</li>
* <li>{@link #FIELD_TYPE_FLOAT}</li>
* <li>{@link #FIELD_TYPE_STRING}</li>
* <li>{@link #FIELD_TYPE_BLOB}</li>
*</ul>
*</p>
*
* @param columnIndex the zero-based index of the target column.
* @return column value type
*/
int getType(int columnIndex);
}
1 change: 0 additions & 1 deletion src/net/sqlcipher/CursorWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package net.sqlcipher;

import android.database.CharArrayBuffer;
import android.database.Cursor;

import android.content.res.Resources;
import android.database.sqlite.SQLiteClosable;
Expand Down
35 changes: 35 additions & 0 deletions src/net/sqlcipher/CursorWrapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2006 The Android Open Source Project
*
* 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 net.sqlcipher;

/**
* Extension of android.database.CursorWrapper to support getType() for API < 11.
*/
public class CursorWrapper extends android.database.CursorWrapper implements Cursor {

private final Cursor mCursor;

public CursorWrapper(Cursor cursor) {
super(cursor);
mCursor = cursor;
}

public int getType(int columnIndex) {
return mCursor.getType(columnIndex);
}
}

2 changes: 1 addition & 1 deletion src/net/sqlcipher/database/SQLiteCursorDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface SQLiteCursorDriver {
* null if standard SQLiteCursors should be returned.
* @return a Cursor over the result set
*/
android.database.Cursor query(CursorFactory factory, String[] bindArgs);
Cursor query(CursorFactory factory, String[] bindArgs);

/**
* Called by a SQLiteCursor when it is released.
Expand Down
3 changes: 2 additions & 1 deletion src/net/sqlcipher/database/SQLiteDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package net.sqlcipher.database;

import net.sqlcipher.Cursor;
import net.sqlcipher.CrossProcessCursorWrapper;
import net.sqlcipher.DatabaseUtils;
import net.sqlcipher.SQLException;
Expand Down Expand Up @@ -43,7 +44,7 @@
import android.content.ContentValues;

import android.content.Context;
import android.database.Cursor;

import android.os.Debug;
import android.os.SystemClock;
import android.text.TextUtils;
Expand Down
10 changes: 6 additions & 4 deletions src/net/sqlcipher/database/SQLiteDirectCursorDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

package net.sqlcipher.database;

import net.sqlcipher.Cursor;
import net.sqlcipher.database.SQLiteDatabase.CursorFactory;
import android.database.Cursor;

/**
* A cursor driver that uses the given query directly.
Expand All @@ -27,7 +27,7 @@
public class SQLiteDirectCursorDriver implements SQLiteCursorDriver {
private String mEditTable;
private SQLiteDatabase mDatabase;
private android.database.Cursor mCursor;
private Cursor mCursor;
private String mSql;
private SQLiteQuery mQuery;

Expand All @@ -37,7 +37,7 @@ public SQLiteDirectCursorDriver(SQLiteDatabase db, String sql, String editTable)
mSql = sql;
}

public android.database.Cursor query(CursorFactory factory, String[] selectionArgs) {
public Cursor query(CursorFactory factory, String[] selectionArgs) {
// Compile the query
SQLiteQuery query = new SQLiteQuery(mDatabase, mSql, 0, selectionArgs);

Expand Down Expand Up @@ -76,11 +76,13 @@ public void setBindArguments(String[] bindArgs) {
}
}

@Override
public void cursorDeactivated() {
// Do nothing
}

public void cursorRequeried(Cursor cursor) {
@Override
public void cursorRequeried(android.database.Cursor cursor) {
// Do nothing
}

Expand Down
5 changes: 3 additions & 2 deletions src/net/sqlcipher/database/SQLiteQueryBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

package net.sqlcipher.database;

import net.sqlcipher.*;

import android.provider.BaseColumns;
Expand Down Expand Up @@ -273,7 +274,7 @@ public static void appendColumns(StringBuilder s, String[] columns) {
* @see android.content.ContentResolver#query(android.net.Uri, String[],
* String, String[], String)
*/
public android.database.Cursor query(SQLiteDatabase db, String[] projectionIn,
public Cursor query(SQLiteDatabase db, String[] projectionIn,
String selection, String[] selectionArgs, String groupBy,
String having, String sortOrder) {
return query(db, projectionIn, selection, selectionArgs, groupBy, having, sortOrder,
Expand Down Expand Up @@ -312,7 +313,7 @@ public android.database.Cursor query(SQLiteDatabase db, String[] projectionIn,
* @see android.content.ContentResolver#query(android.net.Uri, String[],
* String, String[], String)
*/
public android.database.Cursor query(SQLiteDatabase db, String[] projectionIn,
public Cursor query(SQLiteDatabase db, String[] projectionIn,
String selection, String[] selectionArgs, String groupBy,
String having, String sortOrder, String limit) {
if (mTables == null) {
Expand Down
5 changes: 3 additions & 2 deletions src/net/sqlcipher/database/SqliteWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;

import net.sqlcipher.*;

import android.net.Uri;
import android.util.Log;
import android.widget.Toast;
Expand Down Expand Up @@ -64,7 +65,7 @@ public static Cursor query(Context context, ContentResolver resolver, Uri uri,
}
}

public static boolean requery(Context context, Cursor cursor) {
public static boolean requery(Context context, android.database.Cursor cursor) {
try {
return cursor.requery();
} catch (SQLiteException e) {
Expand Down