You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
add complete java side of sqlite implementation
Mostly taken from https://www.sqlite.org/android which is forked from AOSPs implementation
This commit is contained in:
@@ -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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
/**
|
||||
* An exception that indicates that garbage-collector is finalizing a database object
|
||||
* that is not explicitly closed
|
||||
* @hide
|
||||
*/
|
||||
public class DatabaseObjectNotClosedException extends RuntimeException {
|
||||
private static final String s = "Application did not close the cursor or database object " +
|
||||
"that was opened here";
|
||||
|
||||
public DatabaseObjectNotClosedException() {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
/**
|
||||
* An exception that indicates that the SQLite program was aborted.
|
||||
* This can happen either through a call to ABORT in a trigger,
|
||||
* or as the result of using the ABORT conflict clause.
|
||||
*/
|
||||
public class SQLiteAbortException extends SQLiteException {
|
||||
public SQLiteAbortException() {}
|
||||
|
||||
public SQLiteAbortException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
/**
|
||||
* This exception class is used when sqlite can't access the database file
|
||||
* due to lack of permissions on the file.
|
||||
*/
|
||||
public class SQLiteAccessPermException extends SQLiteException {
|
||||
public SQLiteAccessPermException() {}
|
||||
|
||||
public SQLiteAccessPermException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
/**
|
||||
* Thrown if the the bind or column parameter index is out of range
|
||||
*/
|
||||
public class SQLiteBindOrColumnIndexOutOfRangeException extends SQLiteException {
|
||||
public SQLiteBindOrColumnIndexOutOfRangeException() {}
|
||||
|
||||
public SQLiteBindOrColumnIndexOutOfRangeException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
public class SQLiteBlobTooBigException extends SQLiteException {
|
||||
public SQLiteBlobTooBigException() {}
|
||||
|
||||
public SQLiteBlobTooBigException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
public class SQLiteCantOpenDatabaseException extends SQLiteException {
|
||||
public SQLiteCantOpenDatabaseException() {}
|
||||
|
||||
public SQLiteCantOpenDatabaseException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
112
src/api-impl/android/database/sqlite/SQLiteClosable.java
Normal file
112
src/api-impl/android/database/sqlite/SQLiteClosable.java
Normal file
@@ -0,0 +1,112 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
import java.io.Closeable;
|
||||
|
||||
/**
|
||||
* An object created from a SQLiteDatabase that can be closed.
|
||||
*
|
||||
* This class implements a primitive reference counting scheme for database objects.
|
||||
*/
|
||||
public abstract class SQLiteClosable implements Closeable {
|
||||
private int mReferenceCount = 1;
|
||||
|
||||
/**
|
||||
* Called when the last reference to the object was released by
|
||||
* a call to {@link #releaseReference()} or {@link #close()}.
|
||||
*/
|
||||
protected abstract void onAllReferencesReleased();
|
||||
|
||||
/**
|
||||
* Called when the last reference to the object was released by
|
||||
* a call to {@link #releaseReferenceFromContainer()}.
|
||||
*
|
||||
* @deprecated Do not use.
|
||||
*/
|
||||
@Deprecated
|
||||
protected void onAllReferencesReleasedFromContainer() {
|
||||
onAllReferencesReleased();
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquires a reference to the object.
|
||||
*
|
||||
* @throws IllegalStateException if the last reference to the object has already
|
||||
* been released.
|
||||
*/
|
||||
public void acquireReference() {
|
||||
synchronized(this) {
|
||||
if (mReferenceCount <= 0) {
|
||||
throw new IllegalStateException(
|
||||
"attempt to re-open an already-closed object: " + this);
|
||||
}
|
||||
mReferenceCount++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases a reference to the object, closing the object if the last reference
|
||||
* was released.
|
||||
*
|
||||
* @see #onAllReferencesReleased()
|
||||
*/
|
||||
public void releaseReference() {
|
||||
boolean refCountIsZero = false;
|
||||
synchronized(this) {
|
||||
refCountIsZero = --mReferenceCount == 0;
|
||||
}
|
||||
if (refCountIsZero) {
|
||||
onAllReferencesReleased();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases a reference to the object that was owned by the container of the object,
|
||||
* closing the object if the last reference was released.
|
||||
*
|
||||
* @see #onAllReferencesReleasedFromContainer()
|
||||
* @deprecated Do not use.
|
||||
*/
|
||||
@Deprecated
|
||||
public void releaseReferenceFromContainer() {
|
||||
boolean refCountIsZero = false;
|
||||
synchronized(this) {
|
||||
refCountIsZero = --mReferenceCount == 0;
|
||||
}
|
||||
if (refCountIsZero) {
|
||||
onAllReferencesReleasedFromContainer();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases a reference to the object, closing the object if the last reference
|
||||
* was released.
|
||||
*
|
||||
* Calling this method is equivalent to calling {@link #releaseReference}.
|
||||
*
|
||||
* @see #releaseReference()
|
||||
* @see #onAllReferencesReleased()
|
||||
*/
|
||||
public void close() {
|
||||
releaseReference();
|
||||
}
|
||||
}
|
||||
1525
src/api-impl/android/database/sqlite/SQLiteConnection.java
Normal file
1525
src/api-impl/android/database/sqlite/SQLiteConnection.java
Normal file
File diff suppressed because it is too large
Load Diff
1086
src/api-impl/android/database/sqlite/SQLiteConnectionPool.java
Normal file
1086
src/api-impl/android/database/sqlite/SQLiteConnectionPool.java
Normal file
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
/**
|
||||
* An exception that indicates that an integrity constraint was violated.
|
||||
*/
|
||||
public class SQLiteConstraintException extends SQLiteException {
|
||||
public SQLiteConstraintException() {}
|
||||
|
||||
public SQLiteConstraintException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
@@ -13,17 +13,22 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
// import android.database.AbstractWindowedCursor;
|
||||
// import android.database.CursorWindow;
|
||||
// import android.database.DatabaseUtils;
|
||||
// import android.os.StrictMode;
|
||||
import android.database.Cursor;
|
||||
import android.database.AbstractWindowedCursor;
|
||||
import android.database.CursorWindow;
|
||||
import android.database.DatabaseUtils;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* A Cursor implementation that exposes results from a query on a
|
||||
* {@link SQLiteDatabase}.
|
||||
@@ -31,49 +36,30 @@ import java.util.Map;
|
||||
* SQLiteCursor is not internally synchronized so code using a SQLiteCursor from multiple
|
||||
* threads should perform its own synchronization when using the SQLiteCursor.
|
||||
*/
|
||||
public class SQLiteCursor /*extends AbstractWindowedCursor*/ implements Cursor {
|
||||
public class SQLiteCursor extends AbstractWindowedCursor {
|
||||
static final String TAG = "SQLiteCursor";
|
||||
static final int NO_COUNT = -1;
|
||||
|
||||
/**
|
||||
* The name of the table to edit
|
||||
*/
|
||||
private final String mEditTable = "ZZZ";
|
||||
/** The name of the table to edit */
|
||||
private final String mEditTable;
|
||||
|
||||
/**
|
||||
* The names of the columns in the rows
|
||||
*/
|
||||
private final String[] mColumns = {"AAA"};
|
||||
/** The names of the columns in the rows */
|
||||
private final String[] mColumns;
|
||||
|
||||
/**
|
||||
* The query object for the cursor
|
||||
*/
|
||||
private final SQLiteQuery mQuery = null;
|
||||
/** The query object for the cursor */
|
||||
private final SQLiteQuery mQuery;
|
||||
|
||||
/**
|
||||
* The compiled query this cursor came from
|
||||
*/
|
||||
private final SQLiteCursorDriver mDriver = null;
|
||||
/** The compiled query this cursor came from */
|
||||
private final SQLiteCursorDriver mDriver;
|
||||
|
||||
/**
|
||||
* The number of rows in the cursor
|
||||
*/
|
||||
/** The number of rows in the cursor */
|
||||
private int mCount = NO_COUNT;
|
||||
|
||||
/**
|
||||
* The number of rows that can fit in the cursor window, 0 if unknown
|
||||
*/
|
||||
private int mCursorWindowCapacity = -1;
|
||||
/** The number of rows that can fit in the cursor window, 0 if unknown */
|
||||
private int mCursorWindowCapacity;
|
||||
|
||||
/**
|
||||
* A mapping of column names to column indices, to speed up lookups
|
||||
*/
|
||||
private Map<String, Integer> mColumnNameMap = null;
|
||||
|
||||
/**
|
||||
* Used to find out where a cursor was allocated in case it never got released.
|
||||
*/
|
||||
private final Throwable mStackTrace = null;
|
||||
/** A mapping of column names to column indices, to speed up lookups */
|
||||
private Map<String, Integer> mColumnNameMap;
|
||||
|
||||
/**
|
||||
* Execute a query and provide access to its result set through a Cursor
|
||||
@@ -105,23 +91,16 @@ public class SQLiteCursor /*extends AbstractWindowedCursor*/ implements Cursor {
|
||||
* @param editTable the name of the table used for this query
|
||||
* @param query the {@link SQLiteQuery} object associated with this cursor object.
|
||||
*/
|
||||
public SQLiteCursor(SQLiteCursorDriver driver, String editTable, SQLiteQuery query) { /*
|
||||
if (query == null) {
|
||||
throw new IllegalArgumentException("query object cannot be null");
|
||||
}
|
||||
if (StrictMode.vmSqliteObjectLeaksEnabled()) {
|
||||
mStackTrace = new DatabaseObjectNotClosedException().fillInStackTrace();
|
||||
} else {
|
||||
mStackTrace = null;
|
||||
}
|
||||
mDriver = driver;
|
||||
mEditTable = editTable;
|
||||
mColumnNameMap = null;
|
||||
mQuery = query;
|
||||
public SQLiteCursor(SQLiteCursorDriver driver, String editTable, SQLiteQuery query) {
|
||||
if (query == null) {
|
||||
throw new IllegalArgumentException("query object cannot be null");
|
||||
}
|
||||
mDriver = driver;
|
||||
mEditTable = editTable;
|
||||
mColumnNameMap = null;
|
||||
mQuery = query;
|
||||
|
||||
mColumns = query.getColumnNames();
|
||||
mRowIdColumnIndex = DatabaseUtils.findRowIdColumnIndex(mColumns);
|
||||
*/
|
||||
mColumns = query.getColumnNames();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -132,141 +111,152 @@ public class SQLiteCursor /*extends AbstractWindowedCursor*/ implements Cursor {
|
||||
return mQuery.getDatabase();
|
||||
}
|
||||
|
||||
// @Override
|
||||
public boolean onMove(int oldPosition, int newPosition) { /*
|
||||
// Make sure the row at newPosition is present in the window
|
||||
if (mWindow == null || newPosition < mWindow.getStartPosition() ||
|
||||
newPosition >= (mWindow.getStartPosition() + mWindow.getNumRows())) {
|
||||
fillWindow(newPosition);
|
||||
}
|
||||
@Override
|
||||
public boolean onMove(int oldPosition, int newPosition) {
|
||||
// Make sure the row at newPosition is present in the window
|
||||
if (mWindow == null || newPosition < mWindow.getStartPosition() ||
|
||||
newPosition >= (mWindow.getStartPosition() + mWindow.getNumRows())) {
|
||||
fillWindow(newPosition);
|
||||
}
|
||||
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
// @Override
|
||||
public int getCount() { /*
|
||||
if (mCount == NO_COUNT) {
|
||||
fillWindow(0);
|
||||
}
|
||||
return mCount;*/
|
||||
return 1;
|
||||
@Override
|
||||
public int getCount() {
|
||||
if (mCount == NO_COUNT) {
|
||||
fillWindow(0);
|
||||
}
|
||||
return mCount;
|
||||
}
|
||||
|
||||
private void fillWindow(int requiredPos) { /*
|
||||
clearOrCreateWindow(getDatabase().getPath());
|
||||
|
||||
try {
|
||||
if (mCount == NO_COUNT) {
|
||||
int startPos = DatabaseUtils.cursorPickFillWindowStartPosition(requiredPos, 0);
|
||||
mCount = mQuery.fillWindow(mWindow, startPos, requiredPos, true);
|
||||
mCursorWindowCapacity = mWindow.getNumRows();
|
||||
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||
Log.d(TAG, "received count(*) from native_fill_window: " + mCount);
|
||||
}
|
||||
} else {
|
||||
int startPos = DatabaseUtils.cursorPickFillWindowStartPosition(requiredPos,
|
||||
mCursorWindowCapacity);
|
||||
mQuery.fillWindow(mWindow, startPos, requiredPos, false);
|
||||
}
|
||||
} catch (RuntimeException ex) {
|
||||
// Close the cursor window if the query failed and therefore will
|
||||
// not produce any results. This helps to avoid accidentally leaking
|
||||
// the cursor window if the client does not correctly handle exceptions
|
||||
// and fails to close the cursor.
|
||||
closeWindow();
|
||||
throw ex;
|
||||
}
|
||||
*/
|
||||
/*
|
||||
** The AbstractWindowClass contains protected methods clearOrCreateWindow() and
|
||||
** closeWindow(), which are used by the android.database.sqlite.* version of this
|
||||
** class. But, since they are marked with "@hide", the following replacement
|
||||
** versions are required.
|
||||
*/
|
||||
private void awc_clearOrCreateWindow(String name){
|
||||
CursorWindow win = getWindow();
|
||||
if( win==null ){
|
||||
win = new CursorWindow(name);
|
||||
setWindow(win);
|
||||
}else{
|
||||
win.clear();
|
||||
}
|
||||
}
|
||||
private void awc_closeWindow(){
|
||||
setWindow(null);
|
||||
}
|
||||
|
||||
// @Override
|
||||
public int getColumnIndex(String columnName) { /*
|
||||
// Create mColumnNameMap on demand
|
||||
if (mColumnNameMap == null) {
|
||||
String[] columns = mColumns;
|
||||
int columnCount = columns.length;
|
||||
HashMap<String, Integer> map = new HashMap<String, Integer>(columnCount, 1);
|
||||
for (int i = 0; i < columnCount; i++) {
|
||||
map.put(columns[i], i);
|
||||
}
|
||||
mColumnNameMap = map;
|
||||
}
|
||||
private void fillWindow(int requiredPos) {
|
||||
awc_clearOrCreateWindow(getDatabase().getPath());
|
||||
|
||||
// Hack according to bug 903852
|
||||
final int periodIndex = columnName.lastIndexOf('.');
|
||||
if (periodIndex != -1) {
|
||||
Exception e = new Exception();
|
||||
Log.e(TAG, "requesting column name with table name -- " + columnName, e);
|
||||
columnName = columnName.substring(periodIndex + 1);
|
||||
}
|
||||
|
||||
Integer i = mColumnNameMap.get(columnName);
|
||||
if (i != null) {
|
||||
return i.intValue();
|
||||
} else {
|
||||
return -1;
|
||||
}*/
|
||||
return -1;
|
||||
try {
|
||||
if (mCount == NO_COUNT) {
|
||||
int startPos = DatabaseUtils.cursorPickFillWindowStartPosition(requiredPos, 0);
|
||||
mCount = mQuery.fillWindow(mWindow, startPos, requiredPos, true);
|
||||
mCursorWindowCapacity = mWindow.getNumRows();
|
||||
if (Log.isLoggable(TAG, Log.DEBUG)) {
|
||||
Log.d(TAG, "received count(*) from native_fill_window: " + mCount);
|
||||
}
|
||||
} else {
|
||||
int startPos = DatabaseUtils.cursorPickFillWindowStartPosition(requiredPos,
|
||||
mCursorWindowCapacity);
|
||||
mQuery.fillWindow(mWindow, startPos, requiredPos, false);
|
||||
}
|
||||
} catch (RuntimeException ex) {
|
||||
// Close the cursor window if the query failed and therefore will
|
||||
// not produce any results. This helps to avoid accidentally leaking
|
||||
// the cursor window if the client does not correctly handle exceptions
|
||||
// and fails to close the cursor.
|
||||
awc_closeWindow();
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
@Override
|
||||
public int getColumnIndex(String columnName) {
|
||||
// Create mColumnNameMap on demand
|
||||
if (mColumnNameMap == null) {
|
||||
String[] columns = mColumns;
|
||||
int columnCount = columns.length;
|
||||
HashMap<String, Integer> map = new HashMap<String, Integer>(columnCount, 1);
|
||||
for (int i = 0; i < columnCount; i++) {
|
||||
map.put(columns[i], i);
|
||||
}
|
||||
mColumnNameMap = map;
|
||||
}
|
||||
|
||||
// Hack according to bug 903852
|
||||
final int periodIndex = columnName.lastIndexOf('.');
|
||||
if (periodIndex != -1) {
|
||||
Exception e = new Exception();
|
||||
Log.e(TAG, "requesting column name with table name -- " + columnName, e);
|
||||
columnName = columnName.substring(periodIndex + 1);
|
||||
}
|
||||
|
||||
Integer i = mColumnNameMap.get(columnName);
|
||||
if (i != null) {
|
||||
return i.intValue();
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getColumnNames() {
|
||||
return mColumns;
|
||||
}
|
||||
|
||||
// @Override
|
||||
@Override
|
||||
public void deactivate() {
|
||||
// super.deactivate();
|
||||
super.deactivate();
|
||||
mDriver.cursorDeactivated();
|
||||
}
|
||||
|
||||
// @Override
|
||||
public void close() { /*
|
||||
super.close();
|
||||
synchronized (this) {
|
||||
mQuery.close();
|
||||
mDriver.cursorClosed();
|
||||
}
|
||||
*/
|
||||
@Override
|
||||
public void close() {
|
||||
super.close();
|
||||
synchronized (this) {
|
||||
mQuery.close();
|
||||
mDriver.cursorClosed();
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
public boolean requery() { /*
|
||||
if (isClosed()) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean requery() {
|
||||
if (isClosed()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
synchronized (this) {
|
||||
if (!mQuery.getDatabase().isOpen()) {
|
||||
return false;
|
||||
}
|
||||
synchronized (this) {
|
||||
if (!mQuery.getDatabase().isOpen()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mWindow != null) {
|
||||
mWindow.clear();
|
||||
}
|
||||
mPos = -1;
|
||||
mCount = NO_COUNT;
|
||||
if (mWindow != null) {
|
||||
mWindow.clear();
|
||||
}
|
||||
mPos = -1;
|
||||
mCount = NO_COUNT;
|
||||
|
||||
mDriver.cursorRequeried(this);
|
||||
}
|
||||
mDriver.cursorRequeried(this);
|
||||
}
|
||||
|
||||
try {
|
||||
return super.requery();
|
||||
} catch (IllegalStateException e) {
|
||||
// for backwards compatibility, just return false
|
||||
Log.w(TAG, "requery() failed " + e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
try {
|
||||
return super.requery();
|
||||
} catch (IllegalStateException e) {
|
||||
// for backwards compatibility, just return false
|
||||
Log.w(TAG, "requery() failed " + e.getMessage(), e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
public void setWindow(CursorWindow window) { /*
|
||||
super.setWindow(window);
|
||||
mCount = NO_COUNT;
|
||||
*/
|
||||
@Override
|
||||
public void setWindow(CursorWindow window) {
|
||||
super.setWindow(window);
|
||||
mCount = NO_COUNT;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -279,50 +269,15 @@ public class SQLiteCursor /*extends AbstractWindowedCursor*/ implements Cursor {
|
||||
/**
|
||||
* Release the native resources, if they haven't been released yet.
|
||||
*/
|
||||
// @Override
|
||||
protected void finalize() { /*
|
||||
try {
|
||||
// if the cursor hasn't been closed yet, close it first
|
||||
if (mWindow != null) {
|
||||
if (mStackTrace != null) {
|
||||
String sql = mQuery.getSql();
|
||||
int len = sql.length();
|
||||
StrictMode.onSqliteObjectLeaked(
|
||||
"Finalizing a Cursor that has not been deactivated or closed. " +
|
||||
"database = " + mQuery.getDatabase().getLabel() +
|
||||
", table = " + mEditTable +
|
||||
", query = " + sql.substring(0, (len > 1000) ? 1000 : len),
|
||||
mStackTrace);
|
||||
}
|
||||
close();
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
*/
|
||||
}
|
||||
// ---
|
||||
public boolean moveToFirst() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean moveToNext() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isAfterLast() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public long getLong(int columnIndex) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
public String getString(int columnIndex) {
|
||||
return "BBB";
|
||||
}
|
||||
|
||||
public int getInt(int columnIndex) {
|
||||
return 1;
|
||||
@Override
|
||||
protected void finalize() {
|
||||
try {
|
||||
// if the cursor hasn't been closed yet, close it first
|
||||
if (mWindow != null) {
|
||||
close();
|
||||
}
|
||||
} finally {
|
||||
super.finalize();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
/**
|
||||
* Describes a custom SQL function.
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final class SQLiteCustomFunction {
|
||||
public final String name;
|
||||
public final int numArgs;
|
||||
public final SQLiteDatabase.CustomFunction callback;
|
||||
|
||||
/**
|
||||
* Create custom function.
|
||||
*
|
||||
* @param name The name of the sqlite3 function.
|
||||
* @param numArgs The number of arguments for the function, or -1 to
|
||||
* support any number of arguments.
|
||||
* @param callback The callback to invoke when the function is executed.
|
||||
*/
|
||||
public SQLiteCustomFunction(String name, int numArgs,
|
||||
SQLiteDatabase.CustomFunction callback) {
|
||||
if (name == null) {
|
||||
throw new IllegalArgumentException("name must not be null.");
|
||||
}
|
||||
|
||||
this.name = name;
|
||||
this.numArgs = numArgs;
|
||||
this.callback = callback;
|
||||
}
|
||||
|
||||
// Called from native.
|
||||
@SuppressWarnings("unused")
|
||||
private void dispatchCallback(String[] args) {
|
||||
callback.callback(args);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
* Copyright (C) 2011 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* Describes how to configure a database.
|
||||
* <p>
|
||||
* The purpose of this object is to keep track of all of the little
|
||||
* configuration settings that are applied to a database after it
|
||||
* is opened so that they can be applied to all connections in the
|
||||
* connection pool uniformly.
|
||||
* </p><p>
|
||||
* Each connection maintains its own copy of this object so it can
|
||||
* keep track of which settings have already been applied.
|
||||
* </p>
|
||||
*
|
||||
* @hide
|
||||
*/
|
||||
public final class SQLiteDatabaseConfiguration {
|
||||
// The pattern we use to strip email addresses from database paths
|
||||
// when constructing a label to use in log messages.
|
||||
private static final Pattern EMAIL_IN_DB_PATTERN =
|
||||
Pattern.compile("[\\w\\.\\-]+@[\\w\\.\\-]+");
|
||||
|
||||
/**
|
||||
* Special path used by in-memory databases.
|
||||
*/
|
||||
public static final String MEMORY_DB_PATH = ":memory:";
|
||||
|
||||
/**
|
||||
* The database path.
|
||||
*/
|
||||
public final String path;
|
||||
|
||||
/**
|
||||
* The label to use to describe the database when it appears in logs.
|
||||
* This is derived from the path but is stripped to remove PII.
|
||||
*/
|
||||
public final String label;
|
||||
|
||||
/**
|
||||
* The flags used to open the database.
|
||||
*/
|
||||
public int openFlags;
|
||||
|
||||
/**
|
||||
* The maximum size of the prepared statement cache for each database connection.
|
||||
* Must be non-negative.
|
||||
*
|
||||
* Default is 25.
|
||||
*/
|
||||
public int maxSqlCacheSize;
|
||||
|
||||
/**
|
||||
* The database locale.
|
||||
*
|
||||
* Default is the value returned by {@link Locale#getDefault()}.
|
||||
*/
|
||||
public Locale locale;
|
||||
|
||||
/**
|
||||
* True if foreign key constraints are enabled.
|
||||
*
|
||||
* Default is false.
|
||||
*/
|
||||
public boolean foreignKeyConstraintsEnabled;
|
||||
|
||||
/**
|
||||
* The custom functions to register.
|
||||
*/
|
||||
public final ArrayList<SQLiteCustomFunction> customFunctions =
|
||||
new ArrayList<SQLiteCustomFunction>();
|
||||
|
||||
/**
|
||||
* Creates a database configuration with the required parameters for opening a
|
||||
* database and default values for all other parameters.
|
||||
*
|
||||
* @param path The database path.
|
||||
* @param openFlags Open flags for the database, such as {@link SQLiteDatabase#OPEN_READWRITE}.
|
||||
*/
|
||||
public SQLiteDatabaseConfiguration(String path, int openFlags) {
|
||||
if (path == null) {
|
||||
throw new IllegalArgumentException("path must not be null.");
|
||||
}
|
||||
|
||||
this.path = path;
|
||||
label = stripPathForLogs(path);
|
||||
this.openFlags = openFlags;
|
||||
|
||||
// Set default values for optional parameters.
|
||||
maxSqlCacheSize = 25;
|
||||
locale = Locale.getDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a database configuration as a copy of another configuration.
|
||||
*
|
||||
* @param other The other configuration.
|
||||
*/
|
||||
public SQLiteDatabaseConfiguration(SQLiteDatabaseConfiguration other) {
|
||||
if (other == null) {
|
||||
throw new IllegalArgumentException("other must not be null.");
|
||||
}
|
||||
|
||||
this.path = other.path;
|
||||
this.label = other.label;
|
||||
updateParametersFrom(other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the non-immutable parameters of this configuration object
|
||||
* from the other configuration object.
|
||||
*
|
||||
* @param other The object from which to copy the parameters.
|
||||
*/
|
||||
public void updateParametersFrom(SQLiteDatabaseConfiguration other) {
|
||||
if (other == null) {
|
||||
throw new IllegalArgumentException("other must not be null.");
|
||||
}
|
||||
if (!path.equals(other.path)) {
|
||||
throw new IllegalArgumentException("other configuration must refer to "
|
||||
+ "the same database.");
|
||||
}
|
||||
|
||||
openFlags = other.openFlags;
|
||||
maxSqlCacheSize = other.maxSqlCacheSize;
|
||||
locale = other.locale;
|
||||
foreignKeyConstraintsEnabled = other.foreignKeyConstraintsEnabled;
|
||||
customFunctions.clear();
|
||||
customFunctions.addAll(other.customFunctions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the database is in-memory.
|
||||
* @return True if the database is in-memory.
|
||||
*/
|
||||
public boolean isInMemoryDb() {
|
||||
return path.equalsIgnoreCase(MEMORY_DB_PATH);
|
||||
}
|
||||
|
||||
private static String stripPathForLogs(String path) {
|
||||
/* Strip off all URI parameters. This is in case a SEE database is
|
||||
* opened with the password specified as a URI parameter. We do not
|
||||
* want the password to appear in any log files. */
|
||||
int iIdx = path.indexOf('?');
|
||||
if( iIdx>=0 ){
|
||||
path = (String) path.subSequence(0, iIdx);
|
||||
}
|
||||
|
||||
if (path.indexOf('@') == -1) {
|
||||
return path;
|
||||
}
|
||||
return EMAIL_IN_DB_PATTERN.matcher(path).replaceAll("XX@YY");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
/**
|
||||
* An exception that indicates that the SQLite database file is corrupt.
|
||||
*/
|
||||
public class SQLiteDatabaseCorruptException extends SQLiteException {
|
||||
public SQLiteDatabaseCorruptException() {}
|
||||
|
||||
public SQLiteDatabaseCorruptException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (C) 2010 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
/**
|
||||
* Thrown if the database engine was unable to acquire the
|
||||
* database locks it needs to do its job. If the statement is a [COMMIT]
|
||||
* or occurs outside of an explicit transaction, then you can retry the
|
||||
* statement. If the statement is not a [COMMIT] and occurs within a
|
||||
* explicit transaction then you should rollback the transaction before
|
||||
* continuing.
|
||||
*/
|
||||
public class SQLiteDatabaseLockedException extends SQLiteException {
|
||||
public SQLiteDatabaseLockedException() {}
|
||||
|
||||
public SQLiteDatabaseLockedException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2008 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
public class SQLiteDatatypeMismatchException extends SQLiteException {
|
||||
public SQLiteDatatypeMismatchException() {}
|
||||
|
||||
public SQLiteDatatypeMismatchException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
176
src/api-impl/android/database/sqlite/SQLiteDebug.java
Normal file
176
src/api-impl/android/database/sqlite/SQLiteDebug.java
Normal file
@@ -0,0 +1,176 @@
|
||||
/*
|
||||
* Copyright (C) 2007 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import android.util.Log;
|
||||
import android.util.Printer;
|
||||
|
||||
/**
|
||||
* Provides debugging info about all SQLite databases running in the current process.
|
||||
*
|
||||
* {@hide}
|
||||
*/
|
||||
public final class SQLiteDebug {
|
||||
private static native void nativeGetPagerStats(PagerStats stats);
|
||||
|
||||
/**
|
||||
* Controls the printing of informational SQL log messages.
|
||||
*
|
||||
* Enable using "adb shell setprop log.tag.SQLiteLog VERBOSE".
|
||||
*/
|
||||
public static final boolean DEBUG_SQL_LOG =
|
||||
Log.isLoggable("SQLiteLog", Log.VERBOSE);
|
||||
|
||||
/**
|
||||
* Controls the printing of SQL statements as they are executed.
|
||||
*
|
||||
* Enable using "adb shell setprop log.tag.SQLiteStatements VERBOSE".
|
||||
*/
|
||||
public static final boolean DEBUG_SQL_STATEMENTS =
|
||||
Log.isLoggable("SQLiteStatements", Log.VERBOSE);
|
||||
|
||||
/**
|
||||
* Controls the printing of wall-clock time taken to execute SQL statements
|
||||
* as they are executed.
|
||||
*
|
||||
* Enable using "adb shell setprop log.tag.SQLiteTime VERBOSE".
|
||||
*/
|
||||
public static final boolean DEBUG_SQL_TIME =
|
||||
Log.isLoggable("SQLiteTime", Log.VERBOSE);
|
||||
|
||||
/**
|
||||
* True to enable database performance testing instrumentation.
|
||||
* @hide
|
||||
*/
|
||||
public static final boolean DEBUG_LOG_SLOW_QUERIES = false;
|
||||
|
||||
private SQLiteDebug() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a query should be logged.
|
||||
*
|
||||
* Reads the "db.log.slow_query_threshold" system property, which can be changed
|
||||
* by the user at any time. If the value is zero, then all queries will
|
||||
* be considered slow. If the value does not exist or is negative, then no queries will
|
||||
* be considered slow.
|
||||
*
|
||||
* This value can be changed dynamically while the system is running.
|
||||
* For example, "adb shell setprop db.log.slow_query_threshold 200" will
|
||||
* log all queries that take 200ms or longer to run.
|
||||
* @hide
|
||||
*/
|
||||
public static final boolean shouldLogSlowQuery(long elapsedTimeMillis) {
|
||||
int slowQueryMillis = Integer.parseInt(
|
||||
System.getProperty("db.log.slow_query_threshold", "10000")
|
||||
);
|
||||
return slowQueryMillis >= 0 && elapsedTimeMillis >= slowQueryMillis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Contains statistics about the active pagers in the current process.
|
||||
*
|
||||
* @see #nativeGetPagerStats(PagerStats)
|
||||
*/
|
||||
public static class PagerStats {
|
||||
/** the current amount of memory checked out by sqlite using sqlite3_malloc().
|
||||
* documented at http://www.sqlite.org/c3ref/c_status_malloc_size.html
|
||||
*/
|
||||
public int memoryUsed;
|
||||
|
||||
/** the number of bytes of page cache allocation which could not be sattisfied by the
|
||||
* SQLITE_CONFIG_PAGECACHE buffer and where forced to overflow to sqlite3_malloc().
|
||||
* The returned value includes allocations that overflowed because they where too large
|
||||
* (they were larger than the "sz" parameter to SQLITE_CONFIG_PAGECACHE) and allocations
|
||||
* that overflowed because no space was left in the page cache.
|
||||
* documented at http://www.sqlite.org/c3ref/c_status_malloc_size.html
|
||||
*/
|
||||
public int pageCacheOverflow;
|
||||
|
||||
/** records the largest memory allocation request handed to sqlite3.
|
||||
* documented at http://www.sqlite.org/c3ref/c_status_malloc_size.html
|
||||
*/
|
||||
public int largestMemAlloc;
|
||||
|
||||
/** a list of {@link DbStats} - one for each main database opened by the applications
|
||||
* running on the android device
|
||||
*/
|
||||
public ArrayList<DbStats> dbStats;
|
||||
}
|
||||
|
||||
/**
|
||||
* contains statistics about a database
|
||||
*/
|
||||
public static class DbStats {
|
||||
/** name of the database */
|
||||
public String dbName;
|
||||
|
||||
/** the page size for the database */
|
||||
public long pageSize;
|
||||
|
||||
/** the database size */
|
||||
public long dbSize;
|
||||
|
||||
/** documented here http://www.sqlite.org/c3ref/c_dbstatus_lookaside_used.html */
|
||||
public int lookaside;
|
||||
|
||||
/** statement cache stats: hits/misses/cachesize */
|
||||
public String cache;
|
||||
|
||||
public DbStats(String dbName, long pageCount, long pageSize, int lookaside,
|
||||
int hits, int misses, int cachesize) {
|
||||
this.dbName = dbName;
|
||||
this.pageSize = pageSize / 1024;
|
||||
dbSize = (pageCount * pageSize) / 1024;
|
||||
this.lookaside = lookaside;
|
||||
this.cache = hits + "/" + misses + "/" + cachesize;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return all pager and database stats for the current process.
|
||||
* @return {@link PagerStats}
|
||||
*/
|
||||
public static PagerStats getDatabaseInfo() {
|
||||
PagerStats stats = new PagerStats();
|
||||
nativeGetPagerStats(stats);
|
||||
stats.dbStats = SQLiteDatabase.getDbStats();
|
||||
return stats;
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps detailed information about all databases used by the process.
|
||||
* @param printer The printer for dumping database state.
|
||||
* @param args Command-line arguments supplied to dumpsys dbinfo
|
||||
*/
|
||||
public static void dump(Printer printer, String[] args) {
|
||||
boolean verbose = false;
|
||||
for (String arg : args) {
|
||||
if (arg.equals("-v")) {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
|
||||
SQLiteDatabase.dumpAll(printer, verbose);
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,7 @@ public final class SQLiteDirectCursorDriver implements SQLiteCursorDriver {
|
||||
cursor = factory.newCursor(mDatabase, this, mEditTable, query);
|
||||
}
|
||||
} catch (RuntimeException ex) {
|
||||
// query.close();
|
||||
query.close();
|
||||
throw ex;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
/*
|
||||
** Modified to support SQLite extensions by the SQLite developers:
|
||||
** sqlite-dev@sqlite.org.
|
||||
*/
|
||||
|
||||
package android.database.sqlite;
|
||||
|
||||
/**
|
||||
* An exception that indicates that an IO error occured while accessing the
|
||||
* SQLite database file.
|
||||
*/
|
||||
public class SQLiteDiskIOException extends SQLiteException {
|
||||
public SQLiteDiskIOException() {}
|
||||
|
||||
public SQLiteDiskIOException(String error) {
|
||||
super(error);
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user