SQLite Android Bindings
Check-in [da94157b9a]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Create a branch that supports API level 15 and up.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | android-studio-15
Files: files | file ages | folders
SHA1: da94157b9ad9f7604d09d2a950c8d271c123e40e
User & Date: dan 2016-05-20 18:40:03
Context
2016-05-20
18:45
Update to Android Studio and gradle build system. Closed-Leaf check-in: f82877032c user: dan tags: api-level-15
18:40
Create a branch that supports API level 15 and up. Closed-Leaf check-in: da94157b9a user: dan tags: android-studio-15
17:31
Update the SQLite version bundled with this module to 3.13.0. Closed-Leaf check-in: c44bb26627 user: dan tags: android-studio
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to sqlite3/build.gradle.

     1      1   apply plugin: 'com.android.library'
     2      2   
     3      3   android {
     4         -    compileSdkVersion 23
            4  +    compileSdkVersion 15
     5      5       buildToolsVersion "23.0.3"
     6         -
     7      6       defaultConfig {
     8         -        minSdkVersion 16
            7  +        minSdkVersion 15
     9      8           targetSdkVersion 23
    10      9           versionCode 1
    11     10           versionName "1.0"
    12     11       }
    13     12       buildTypes {
    14     13           release {
    15     14               minifyEnabled false
    16     15               proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    17     16           }
    18     17       }
    19         -
    20     18       sourceSets.main.jni.srcDirs = [] //disable automatic ndk-build call
    21         -
    22     19       sourceSets.main {
    23     20           jniLibs.srcDir 'src/main/libs'
    24     21       }
    25         -
           22  +    productFlavors {
           23  +    }
    26     24   }
    27     25   
    28     26   dependencies {
    29         -    compile fileTree(dir: 'libs', include: ['*.jar'])
           27  +    compile fileTree(include: ['*.jar'], dir: 'libs')
    30     28       testCompile 'junit:junit:4.12'
    31     29       compile 'com.android.support:appcompat-v7:23.4.0'
    32     30   }

Added sqlite3/src/main/aidl/org/sqlite/os/ICancellationSignal.aidl.

            1  +/*
            2  + * Copyright (C) 2012 The Android Open Source Project
            3  + *
            4  + * Licensed under the Apache License, Version 2.0 (the "License");
            5  + * you may not use this file except in compliance with the License.
            6  + * You may obtain a copy of the License at
            7  + *
            8  + *      http://www.apache.org/licenses/LICENSE-2.0
            9  + *
           10  + * Unless required by applicable law or agreed to in writing, software
           11  + * distributed under the License is distributed on an "AS IS" BASIS,
           12  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           13  + * See the License for the specific language governing permissions and
           14  + * limitations under the License.
           15  + */
           16  +/*
           17  +** Modified to support SQLite extensions by the SQLite developers: 
           18  +** sqlite-dev@sqlite.org.
           19  +*/
           20  +
           21  +package org.sqlite.os;
           22  +
           23  +/**
           24  + * @hide
           25  + */
           26  +interface ICancellationSignal {
           27  +    oneway void cancel();
           28  +}

Changes to sqlite3/src/main/java/org/sqlite/database/ExtraUtils.java.

    32     32   import org.sqlite.database.sqlite.SQLiteDatabase;
    33     33   import org.sqlite.database.sqlite.SQLiteDatabaseCorruptException;
    34     34   import org.sqlite.database.sqlite.SQLiteDiskIOException;
    35     35   import org.sqlite.database.sqlite.SQLiteException;
    36     36   import org.sqlite.database.sqlite.SQLiteFullException;
    37     37   import org.sqlite.database.sqlite.SQLiteProgram;
    38     38   import org.sqlite.database.sqlite.SQLiteStatement;
    39         -import android.os.OperationCanceledException;
           39  +import org.sqlite.os.OperationCanceledException;
    40     40   import android.os.Parcel;
    41     41   import android.os.ParcelFileDescriptor;
    42     42   import android.text.TextUtils;
    43     43   import android.util.Log;
    44     44   
    45     45   import java.io.FileNotFoundException;
    46     46   import java.io.PrintStream;

Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteConnection.java.

    24     24   import org.sqlite.database.sqlite.CloseGuard;
    25     25   
    26     26   import android.database.Cursor;
    27     27   import android.database.CursorWindow;
    28     28   import android.database.DatabaseUtils;
    29     29   import org.sqlite.database.ExtraUtils;
    30     30   import org.sqlite.database.sqlite.SQLiteDebug.DbStats;
    31         -import android.os.CancellationSignal;
    32         -import android.os.OperationCanceledException;
           31  +import org.sqlite.os.CancellationSignal;
           32  +import org.sqlite.os.OperationCanceledException;
    33     33   import android.os.ParcelFileDescriptor;
    34     34   import android.util.Log;
    35     35   import android.util.LruCache;
    36     36   import android.util.Printer;
    37     37   
    38     38   import java.text.SimpleDateFormat;
    39     39   import java.util.ArrayList;

Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteConnectionPool.java.

    19     19   */
    20     20   
    21     21   package org.sqlite.database.sqlite;
    22     22   
    23     23   import org.sqlite.database.sqlite.CloseGuard;
    24     24   
    25     25   import org.sqlite.database.sqlite.SQLiteDebug.DbStats;
    26         -import android.os.CancellationSignal;
    27         -import android.os.OperationCanceledException;
           26  +import org.sqlite.os.CancellationSignal;
           27  +import org.sqlite.os.OperationCanceledException;
    28     28   import android.os.SystemClock;
    29     29   import android.util.Log;
    30     30   /* import android.util.PrefixPrinter; */
    31     31   import android.util.Printer;
    32     32   
    33     33   import java.io.Closeable;
    34     34   import java.util.ArrayList;

Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteDatabase.java.

    24     24   import android.database.Cursor;
    25     25   import org.sqlite.database.DatabaseErrorHandler;
    26     26   import android.database.DatabaseUtils;
    27     27   import org.sqlite.database.ExtraUtils;
    28     28   import org.sqlite.database.DefaultDatabaseErrorHandler;
    29     29   import org.sqlite.database.SQLException;
    30     30   import org.sqlite.database.sqlite.SQLiteDebug.DbStats;
    31         -import android.os.CancellationSignal;
           31  +import org.sqlite.os.CancellationSignal;
    32     32   import android.os.Looper;
    33         -import android.os.OperationCanceledException;
           33  +import org.sqlite.os.OperationCanceledException;
    34     34   import android.text.TextUtils;
    35     35   import android.util.EventLog;
    36     36   import android.util.Log;
    37     37   import android.util.Pair;
    38     38   import android.util.Printer;
    39     39   
    40     40   import org.sqlite.database.sqlite.CloseGuard;

Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteDirectCursorDriver.java.

    18     18   ** sqlite-dev@sqlite.org.
    19     19   */
    20     20   
    21     21   package org.sqlite.database.sqlite;
    22     22   
    23     23   import android.database.Cursor;
    24     24   import org.sqlite.database.sqlite.SQLiteDatabase.CursorFactory;
    25         -import android.os.CancellationSignal;
           25  +import org.sqlite.os.CancellationSignal;
    26     26   
    27     27   /**
    28     28    * A cursor driver that uses the given query directly.
    29     29    * 
    30     30    * @hide
    31     31    */
    32     32   public final class SQLiteDirectCursorDriver implements SQLiteCursorDriver {

Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteProgram.java.

    17     17   ** Modified to support SQLite extensions by the SQLite developers: 
    18     18   ** sqlite-dev@sqlite.org.
    19     19   */
    20     20   
    21     21   package org.sqlite.database.sqlite;
    22     22   
    23     23   import android.database.DatabaseUtils;
    24         -import android.os.CancellationSignal;
           24  +import org.sqlite.os.CancellationSignal;
    25     25   
    26     26   import java.util.Arrays;
    27     27   
    28     28   /**
    29     29    * A base class for compiled SQLite programs.
    30     30    * <p>
    31     31    * This class is not thread-safe.

Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteQuery.java.

    17     17   ** Modified to support SQLite extensions by the SQLite developers: 
    18     18   ** sqlite-dev@sqlite.org.
    19     19   */
    20     20   
    21     21   package org.sqlite.database.sqlite;
    22     22   
    23     23   import android.database.CursorWindow;
    24         -import android.os.CancellationSignal;
    25         -import android.os.OperationCanceledException;
           24  +import org.sqlite.os.CancellationSignal;
           25  +import org.sqlite.os.OperationCanceledException;
    26     26   import android.util.Log;
    27     27   
    28     28   /**
    29     29    * Represents a query that reads the resulting rows into a {@link SQLiteQuery}.
    30     30    * This class is used by {@link SQLiteCursor} and isn't useful itself.
    31     31    * <p>
    32     32    * This class is not thread-safe.

Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteQueryBuilder.java.

    18     18   ** sqlite-dev@sqlite.org.
    19     19   */
    20     20   
    21     21   package org.sqlite.database.sqlite;
    22     22   
    23     23   import android.database.Cursor;
    24     24   import android.database.DatabaseUtils;
    25         -import android.os.CancellationSignal;
    26         -import android.os.OperationCanceledException;
           25  +import org.sqlite.os.CancellationSignal;
           26  +import org.sqlite.os.OperationCanceledException;
    27     27   import android.provider.BaseColumns;
    28     28   import android.text.TextUtils;
    29     29   import android.util.Log;
    30     30   
    31     31   import java.util.Iterator;
    32     32   import java.util.Map;
    33     33   import java.util.Map.Entry;

Changes to sqlite3/src/main/java/org/sqlite/database/sqlite/SQLiteSession.java.

    18     18   ** sqlite-dev@sqlite.org.
    19     19   */
    20     20   
    21     21   package org.sqlite.database.sqlite;
    22     22   
    23     23   import android.database.CursorWindow;
    24     24   import android.database.DatabaseUtils;
    25         -import android.os.CancellationSignal;
    26         -import android.os.OperationCanceledException;
           25  +import org.sqlite.os.CancellationSignal;
           26  +import org.sqlite.os.OperationCanceledException;
    27     27   import android.os.ParcelFileDescriptor;
    28     28   
    29     29   /**
    30     30    * Provides a single client the ability to use a database.
    31     31    *
    32     32    * <h2>About database sessions</h2>
    33     33    * <p>

Added sqlite3/src/main/java/org/sqlite/os/CancellationSignal.java.

            1  +/*
            2  + * Copyright (C) 2012 The Android Open Source Project
            3  + *
            4  + * Licensed under the Apache License, Version 2.0 (the "License");
            5  + * you may not use this file except in compliance with the License.
            6  + * You may obtain a copy of the License at
            7  + *
            8  + *      http://www.apache.org/licenses/LICENSE-2.0
            9  + *
           10  + * Unless required by applicable law or agreed to in writing, software
           11  + * distributed under the License is distributed on an "AS IS" BASIS,
           12  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           13  + * See the License for the specific language governing permissions and
           14  + * limitations under the License.
           15  + */
           16  +/*
           17  +** Modified to support SQLite extensions by the SQLite developers: 
           18  +** sqlite-dev@sqlite.org.
           19  +*/
           20  +
           21  +package org.sqlite.os;
           22  +
           23  +import org.sqlite.os.ICancellationSignal;
           24  +import android.os.RemoteException;
           25  +
           26  +/**
           27  + * Provides the ability to cancel an operation in progress.
           28  + */
           29  +public final class CancellationSignal {
           30  +    private boolean mIsCanceled;
           31  +    private OnCancelListener mOnCancelListener;
           32  +    private ICancellationSignal mRemote;
           33  +    private boolean mCancelInProgress;
           34  +
           35  +    /**
           36  +     * Creates a cancellation signal, initially not canceled.
           37  +     */
           38  +    public CancellationSignal() {
           39  +    }
           40  +
           41  +    /**
           42  +     * Returns true if the operation has been canceled.
           43  +     *
           44  +     * @return True if the operation has been canceled.
           45  +     */
           46  +    public boolean isCanceled() {
           47  +        synchronized (this) {
           48  +            return mIsCanceled;
           49  +        }
           50  +    }
           51  +
           52  +    /**
           53  +     * Throws {@link OperationCanceledException} if the operation has been canceled.
           54  +     *
           55  +     * @throws OperationCanceledException if the operation has been canceled.
           56  +     */
           57  +    public void throwIfCanceled() {
           58  +        if (isCanceled()) {
           59  +            throw new OperationCanceledException();
           60  +        }
           61  +    }
           62  +
           63  +    /**
           64  +     * Cancels the operation and signals the cancellation listener.
           65  +     * If the operation has not yet started, then it will be canceled as soon as it does.
           66  +     */
           67  +    public void cancel() {
           68  +        final OnCancelListener listener;
           69  +        final ICancellationSignal remote;
           70  +        synchronized (this) {
           71  +            if (mIsCanceled) {
           72  +                return;
           73  +            }
           74  +            mIsCanceled = true;
           75  +            mCancelInProgress = true;
           76  +            listener = mOnCancelListener;
           77  +            remote = mRemote;
           78  +        }
           79  +
           80  +        try {
           81  +            if (listener != null) {
           82  +                listener.onCancel();
           83  +            }
           84  +            if (remote != null) {
           85  +                try {
           86  +                    remote.cancel();
           87  +                } catch (RemoteException ex) {
           88  +                }
           89  +            }
           90  +        } finally {
           91  +            synchronized (this) {
           92  +                mCancelInProgress = false;
           93  +                notifyAll();
           94  +            }
           95  +        }
           96  +    }
           97  +
           98  +    /**
           99  +     * Sets the cancellation listener to be called when canceled.
          100  +     *
          101  +     * This method is intended to be used by the recipient of a cancellation signal
          102  +     * such as a database or a content provider to handle cancellation requests
          103  +     * while performing a long-running operation.  This method is not intended to be
          104  +     * used by applications themselves.
          105  +     *
          106  +     * If {@link CancellationSignal#cancel} has already been called, then the provided
          107  +     * listener is invoked immediately.
          108  +     *
          109  +     * This method is guaranteed that the listener will not be called after it
          110  +     * has been removed.
          111  +     *
          112  +     * @param listener The cancellation listener, or null to remove the current listener.
          113  +     */
          114  +    public void setOnCancelListener(OnCancelListener listener) {
          115  +        synchronized (this) {
          116  +            waitForCancelFinishedLocked();
          117  +
          118  +            if (mOnCancelListener == listener) {
          119  +                return;
          120  +            }
          121  +            mOnCancelListener = listener;
          122  +            if (!mIsCanceled || listener == null) {
          123  +                return;
          124  +            }
          125  +        }
          126  +        listener.onCancel();
          127  +    }
          128  +
          129  +    /**
          130  +     * Sets the remote transport.
          131  +     *
          132  +     * If {@link CancellationSignal#cancel} has already been called, then the provided
          133  +     * remote transport is canceled immediately.
          134  +     *
          135  +     * This method is guaranteed that the remote transport will not be called after it
          136  +     * has been removed.
          137  +     *
          138  +     * @param remote The remote transport, or null to remove.
          139  +     *
          140  +     * @hide
          141  +     */
          142  +    public void setRemote(ICancellationSignal remote) {
          143  +        synchronized (this) {
          144  +            waitForCancelFinishedLocked();
          145  +
          146  +            if (mRemote == remote) {
          147  +                return;
          148  +            }
          149  +            mRemote = remote;
          150  +            if (!mIsCanceled || remote == null) {
          151  +                return;
          152  +            }
          153  +        }
          154  +        try {
          155  +            remote.cancel();
          156  +        } catch (RemoteException ex) {
          157  +        }
          158  +    }
          159  +
          160  +    private void waitForCancelFinishedLocked() {
          161  +        while (mCancelInProgress) {
          162  +            try {
          163  +                wait();
          164  +            } catch (InterruptedException ex) {
          165  +            }
          166  +        }
          167  +    }
          168  +
          169  +    /**
          170  +     * Creates a transport that can be returned back to the caller of
          171  +     * a Binder function and subsequently used to dispatch a cancellation signal.
          172  +     *
          173  +     * @return The new cancellation signal transport.
          174  +     *
          175  +     * @hide
          176  +     */
          177  +    public static ICancellationSignal createTransport() {
          178  +        return new Transport();
          179  +    }
          180  +
          181  +    /**
          182  +     * Given a locally created transport, returns its associated cancellation signal.
          183  +     *
          184  +     * @param transport The locally created transport, or null if none.
          185  +     * @return The associated cancellation signal, or null if none.
          186  +     *
          187  +     * @hide
          188  +     */
          189  +    public static CancellationSignal fromTransport(ICancellationSignal transport) {
          190  +        if (transport instanceof Transport) {
          191  +            return ((Transport)transport).mCancellationSignal;
          192  +        }
          193  +        return null;
          194  +    }
          195  +
          196  +    /**
          197  +     * Listens for cancellation.
          198  +     */
          199  +    public interface OnCancelListener {
          200  +        /**
          201  +         * Called when {@link CancellationSignal#cancel} is invoked.
          202  +         */
          203  +        void onCancel();
          204  +    }
          205  +
          206  +    private static final class Transport extends ICancellationSignal.Stub {
          207  +        final CancellationSignal mCancellationSignal = new CancellationSignal();
          208  +
          209  +        @Override
          210  +        public void cancel() throws RemoteException {
          211  +            mCancellationSignal.cancel();
          212  +        }
          213  +    }
          214  +}

Added sqlite3/src/main/java/org/sqlite/os/OperationCanceledException.java.

            1  +/*
            2  + * Copyright (C) 2012 The Android Open Source Project
            3  + *
            4  + * Licensed under the Apache License, Version 2.0 (the "License");
            5  + * you may not use this file except in compliance with the License.
            6  + * You may obtain a copy of the License at
            7  + *
            8  + *      http://www.apache.org/licenses/LICENSE-2.0
            9  + *
           10  + * Unless required by applicable law or agreed to in writing, software
           11  + * distributed under the License is distributed on an "AS IS" BASIS,
           12  + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           13  + * See the License for the specific language governing permissions and
           14  + * limitations under the License.
           15  + */
           16  +/*
           17  +** Modified to support SQLite extensions by the SQLite developers: 
           18  +** sqlite-dev@sqlite.org.
           19  +*/
           20  +
           21  +package org.sqlite.os;
           22  +
           23  +
           24  +/**
           25  + * An exception type that is thrown when an operation in progress is canceled.
           26  + *
           27  + * @see CancellationSignal
           28  + */
           29  +public class OperationCanceledException extends RuntimeException {
           30  +    public OperationCanceledException() {
           31  +        this(null);
           32  +    }
           33  +
           34  +    public OperationCanceledException(String message) {
           35  +        super(message != null ? message : "The operation has been canceled.");
           36  +    }
           37  +}

Changes to sqlite3test/build.gradle.

     1      1   apply plugin: 'com.android.application'
     2      2   
     3      3   android {
     4         -    compileSdkVersion 23
            4  +    compileSdkVersion 15
     5      5       buildToolsVersion "23.0.3"
     6         -
     7      6       defaultConfig {
     8      7           applicationId "org.sqlite.customsqlitetest"
     9         -        minSdkVersion 16
            8  +        minSdkVersion 15
    10      9           targetSdkVersion 23
    11     10           versionCode 1
    12     11           versionName "1.0"
    13     12       }
    14     13       buildTypes {
    15     14           release {
    16     15               minifyEnabled false
    17     16               proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    18     17           }
           18  +    }
           19  +    productFlavors {
    19     20       }
    20     21   }
    21     22   
    22     23   dependencies {
    23     24       compile fileTree(include: ['*.jar'], dir: 'libs')
    24     25       testCompile 'junit:junit:4.12'
    25     26       compile 'com.android.support:appcompat-v7:23.4.0'
    26     27       compile project(':sqlite3')
    27     28   }

Changes to sqlite3test/src/main/java/org/sqlite/customsqlitetest/MainActivity.java.

   372    372   
   373    373           test_result("see_test_2.5", db_is_encrypted(), "encrypted");
   374    374       }
   375    375   
   376    376       public void run_the_tests(View view){
   377    377           System.loadLibrary("sqliteX");
   378    378           DB_PATH = getApplicationContext().getDatabasePath("test.db");
   379         -        DB_PATH.getParentFile().mkdirs();
          379  +        DB_PATH.mkdirs();
   380    380   
   381    381           myTV.setText("");
   382    382           myNErr = 0;
   383    383           myNTest = 0;
   384    384   
   385    385           try {
   386    386               report_version();