Git Product home page Git Product logo

sqlite-android's Introduction

Android SQLite support library

Build Status Download

This is an Android specific distribution of the latest versions of SQLite. It contains the latest SQLite version and the Android specific database APIs derived from AOSP packaged as an AAR library distributed on jitpack.

Why?

  • Consistent
  • Faster
  • Up-to-date

Even the latest version of Android is several versions behind the latest version of SQLite. These versions do not have bug fixes, performance improvements, or new features present in current versions of SQLite. This problem is worse the older the version of the OS the device has. Using this library, you can keep up to date with the latest versions of SQLite and provide a consistent version across OS versions and devices.

Use new SQLite features:

Usage

Follow the guidelines from jitpack.io to add the JitPack repository to your build file if you have not.

Typically, this means an edit to your build.gradle file to add a new repository definition in the allprojects block, like this:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Then add the sqlite-android artifact from this repository as a dependency:

dependencies {
    implementation 'com.github.requery:sqlite-android:3.45.0'
}

Then change usages of android.database.sqlite.SQLiteDatabase to io.requery.android.database.sqlite.SQLiteDatabase, similarly extend io.requery.android.database.sqlite.SQLiteOpenHelper instead of android.database.sqlite.SQLiteOpenHelper. Note similar changes maybe required for classes that depended on android.database.sqlite.SQLiteDatabase equivalent APIs are provided in the io.requery.android.database.sqlite package.

If you expose Cursor instances across processes you should wrap the returned cursors in a CrossProcessCursorWrapper for performance reasons the cursors are not a cross process by default.

Support library compatibility

The library implements the SupportSQLite interfaces provided by the support library. Use RequerySQLiteOpenHelperFactory to obtain an implementation of (Support)SQLiteOpenHelper based on a SupportSQLiteOpenHelper.Configuration and SupportSQLiteOpenHelper.Callback.

This also allows you to use sqlite-android with libraries like Room by passing an instance of RequerySQLiteOpenHelperFactory to them.

CPU Architectures

The native library is built for the following CPU architectures:

  • armeabi-v7a ~1.2 MB
  • arm64-v8a ~1.7 MB
  • x86 ~1.7 MB
  • x86_64 ~1.8 MB

However, you may not want to include all binaries in your apk. You can exclude certain variants by using packagingOptions:

android {
    packagingOptions {
        exclude 'lib/armeabi-v7a/libsqlite3x.so'
        exclude 'lib/arm64-v8a/libsqlite3x.so'
        exclude 'lib/x86/libsqlite3x.so'
        exclude 'lib/x86_64/libsqlite3x.so'
    }
}

The size of the artifacts with only the armeabi-v7a binary is ~1.2 MB. In general, you can use armeabi-v7a on the majority of Android devices including Intel Atom which provides a native translation layer, however, performance under the translation layer is worse than using the x86 binary.

Note that starting August 1, 2019, your apps published on Google Play will need to support 64-bit architectures.

Requirements

The min SDK level is API level 19 (KitKat).

Versioning

The library is versioned after the version of SQLite it contains. For changes specific to just the wrapper API, a revision number is added e.g., 3.45.0-X, where X is the revision number.

Acknowledgements

This project is based on the AOSP code and the Android SQLite bindings No official distributions are made from the Android SQLite bindings it, and it has not been updated in a while, this project starts there and makes significant changes:

Changes

  • Fast read performance: The original SQLite bindings filled the CursorWindow using its Java methods from native C++. This was because there is no access to the native CursorWindow native API from the NDK. Unfortunately, this slowed read performance significantly (roughly 2x worse vs the android database API) because of extra JNI roundtrips. This has been rewritten without the JNI to Java calls (so more like the original AOSP code) and also using a local memory CursorWindow.
  • Reuse of android.database.sqlite.*, the original SQLite bindings replicated the entire android.database.sqlite API structure including exceptions & interfaces. This project does not do that, instead it reuses the original classes/interfaces when possible to simplify migration and/or use with existing code.
  • Unit tests added
  • Compile with clang toolchain
  • Compile with FTS3, FTS4, & JSON1 extension
  • Migrate to Gradle build
  • buildscript dynamically fetches and builds the latest sqlite source from sqlite.org
  • Added consumer proguard rules
  • Use androidx-core version of CancellationSignal
  • Fix bug in SQLiteOpenHelper.getDatabaseLocked() wrong path to openOrCreateDatabase
  • Fix removed members in AbstractWindowCursor
  • Made the AOSP code (mostly) warning free but still mergable from source
  • Deprecated classes/methods removed
  • Loadable extension support
  • STL dependency removed

License

Copyright (C) 2017-2024 requery.io
Copyright (C) 2005-2012 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.

sqlite-android's People

Contributors

alexoro avatar ammojamo avatar angusholder avatar arthur-milchior avatar dhleong avatar dimezis avatar ebraminio avatar ericatplangrid avatar falcon4ever avatar gabrielittner avatar georgi-neykov-hub avatar jakewharton avatar kierse avatar kroggen avatar m66b avatar mikehardy avatar misterrager avatar npurushe avatar setiawanp avatar steinerok avatar technoir42 avatar toxicbakery avatar vovkab avatar zacsweers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sqlite-android's Issues

OOM in CursorWindow create

Hi,

I tried this project and I have got a lot of unexpected OOM crashes. The memory usage is not that high, but the CursorWindow allocation just fails (when new CursorWindow()). After switched to Android standard wrapper, OOM is gone. The only change is changing the imports from io.requery.android.database to android.database and also calling one method using reflection because it is not available in stock wrapper

    public static final void callBeginDeffered(SQLiteDatabase db) {
        Reflect.on(db).call("getThreadSession").call("beginTransaction", 0, (SQLiteTransactionListener) null, 1,null);
    }

This is probabality also happens in SQLite Android Binding, because I experienced some OOM this when I use the binding before. I switched to your version because there is x86 so files also you claim performance is different.

My code has a lot of concurrent queries, but the cursor is always closed after the data is read. Any thoughts why this happens?

minsdk 15

Hi is there a specific reason why this library has minsdk 15 and not minsdk 14 or even minsdk 7?

rankfunc - could it be included?

To be able to rank result with FTS after how good a match the result is, we need to include the rankFunc.

The rankFunc to include is defined in the bottom of this documentation page:
https://www.sqlite.org/fts3.html

Right now when I try to use the ranking I the this error:

android.database.sqlite.SQLiteException: no such function: rank (code 1)

I use it like this with a weight for each column:
ORDER BY rank(matchinfo(tableName), 0.0, 0.0, 1.0, 0.8, 0.0, 0.5, 0.0, 0.1, 0.0, 0.1, 0.1, 0.0, 0.1, 0.0, 0.1, 0.0, 0.1, 0.0, 0.0, 0.0, 0.0) DESC

json1 issue

This test does not pass:

@Test
public void queryByField() throws Exception {
    SQLiteDatabase db = SQLiteDatabase.create(null);
    db.execSQL("CREATE TABLE test (data TEXT)");
    db.execSQL("INSERT INTO test (data) VALUES (json(?))",
            new String[]{"{\"id\":1,\"name\":\"Joe\"}"});

    Cursor cursor = db.rawQuery(
            "SELECT data FROM test WHERE json_extract(data, '$.id') == ?",
            new String[]{"1"});
    assertEquals(1, cursor.getCount());
}

What is weird is that it starts working when I replace

            "SELECT data FROM test WHERE json_extract(data, '$.id') == ?",

to

            "SELECT data FROM test WHERE CAST(json_extract(data, '$.id') AS NONE) == ?",

Is it an SQLite issue?

Explicit termination method 'close' not called

Sorry for asking the same question, but it seems you deleted my other issue. Is there a way to stop logging this warning?

A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
java.lang.Throwable: Explicit termination method 'close' not called  

SQLiteConnectionPool issue

Hello.

My code uses multiple thread to access database at a give timeframe. After couple of seconds inserts it stops giving access to db and outputs the following
W/SQLiteConnectionPool: The connection pool for database '/data/user/0/group.infotech.reference.dev/databases/alternative-references.sqlite' has been unable to grant a connection to thread 1778 (RxCachedThreadScheduler-1) with flags 0x2 for 630.01605 seconds. Connections: 0 active, 1 idle, 2 available.

Happens with both writeAheadLogging.

Any tips for me to figure out what exactly happening. Maybe some kind of deadlock?

Encryption support

Thank you for the great effort!

I have just one question if encryption is supported.

Could not open database

I get this error from a couple of users. Do you know anything about this?

Fatal Exception: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
#################################################################
Error Code : 14 (SQLITE_CANTOPEN)
Caused By : Unable to open the database file.
	(unknown error (code 14): Could not open database)
#################################################################
       at io.requery.android.database.sqlite.SQLiteConnection.nativeOpen(SQLiteConnection.java)
       at io.requery.android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:223)
       at io.requery.android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:207)
       at io.requery.android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:467)
       at io.requery.android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:188)
       at io.requery.android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:180)
       at io.requery.android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:827)
       at io.requery.android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:799)
       at io.requery.android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:674)

Failed to open database

I use this in my demo . why it can't create database?

04-19 11:04:58.985 19818-19818/? E/SQLiteLog: (14) cannot open file at line 33279 of [fe7d3b75fe]
04-19 11:04:58.985 19818-19818/? E/SQLiteLog: (14) os_unix.c:33279: (2) open(/data/data/com.weiyun.fastquery/databases/weiyun.db) -
04-19 11:04:58.985 19818-19818/? E/SQLiteDatabase: Failed to open database '/data/data/com.weiyun.fastquery/databases/weiyun.db'.
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database
at io.requery.android.database.sqlite.SQLiteConnection.nativeOpen(Native Method)
at io.requery.android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:221)
at io.requery.android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:205)
at io.requery.android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:468)
at io.requery.android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:189)
at io.requery.android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:181)
at io.requery.android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:835)
at io.requery.android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:820)
at io.requery.android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:726)
at io.requery.android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:245)
at io.requery.android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:174)
at com.weiyun.fastquery.db.UploadDBHelper.insertJob(UploadDBHelper.java:38)
at com.weiyun.fastquery.MainActivity.onCreate(MainActivity.java:33)

A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.

I keep getting this error because I'm not closing the db. But I don't want to close and open it again and again. How can I stop this error from logs.

W/SQLite: A resource was acquired at attached stack trace but never released. See java.io.Closeable for information on avoiding resource leaks.
                                                          java.lang.Throwable: Explicit termination method 'close' not called
                                                              at io.requery.android.database.sqlite.CloseGuard.open(CloseGuard.java:188)
                                                              at io.requery.android.database.sqlite.SQLiteConnection.<init>(SQLiteConnection.java:183)
                                                              at io.requery.android.database.sqlite.SQLiteConnection.open(SQLiteConnection.java:204)
                                                              at io.requery.android.database.sqlite.SQLiteConnectionPool.openConnectionLocked(SQLiteConnectionPool.java:467)
                                                              at io.requery.android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:188)
                                                              at io.requery.android.database.sqlite.SQLiteConnectionPool.open(SQLiteConnectionPool.java:180)
                                                              at io.requery.android.database.sqlite.SQLiteDatabase.openInner(SQLiteDatabase.java:827)
                                                              at io.requery.android.database.sqlite.SQLiteDatabase.open(SQLiteDatabase.java:796)
                                                              at io.requery.android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:699)
                                                              at io.requery.android.database.sqlite.SQLiteOpenHelper.getDatabaseLocked(SQLiteOpenHelper.java:236)
                                                              at io.requery.android.database.sqlite.SQLiteOpenHelper.getWritableDatabase(SQLiteOpenHelper.java:170)

"JNI FatalError called: RegisterNatives failed.."

My app accesses an SQLite Database as soon as it's opened, but as of version 3.13.0-1, it crashes at launch with a very large stacktrace (linked - me.sebj.times.beta is my app's ID), which includes the message:

JNI FatalError called: RegisterNatives failed for 'io/requery/android/database/sqlite/SQLiteConnection'; aborting...

My app is being built for release (with ProGuard enabled) and crashes both in an Android Emulator on 5.0, and on my own 5.1.1 device (probably others).

Downgrading to 3.12.2-2 in my Gradle file, building, and running instantly fixes the problem - the app runs perfectly.

Latest version (13.3.0) gives error when building project with ProGuard enabled

I updated to the latest version and when building for (beta) release with ProGuard enabled, the following messages prevent me from successfully building:

Warning: Exception while processing task java.io.IOException: proguard.ParseException: Unexpected keyword 'io.requery.android.database.**' in line 1 of file 'project path../build/intermediates/exploded-aar/io.requery/sqlite-android/3.13.0/proguard.txt'

Error: Execution failed for task ':app:transformClassesAndResourcesWithProguardForBeta'.
java.io.IOException: proguard.ParseException: Unexpected keyword 'io.requery.android.database.**' in line 1 of file 'project path../build/intermediates/exploded-aar/io.requery/sqlite-android/3.13.0/proguard.txt'

Example

Hello

Can you give an example of adding and getting json records using the io.requery.android.database.sqlite.SQLiteDatabase and io.requery.android.database.sqlite.SQLiteOpenHelper

Thank you
Athan

[QUESTION] Can you provide precompiled libSqliteICU.so?

Can you provide (in github's releases) libSqliteICU.so precompiled for the same architectures as your SQLite-android lib? I'm asking because I'd like to use SQLiteCustomExtension to load ICU extension (as you don't give a direct support for LOCALIZED collation).

Alternatively, can you add a full support for LOCALIZED collator in future releases?
This is very important as BINARY sorting and grouping is not an option for my country locale.

x86_64 support?

I wonder if 64-bit builds will be supported as these are soon becoming mainstream.

Runtime loadable extensions

This will enable a custom extension that is compiled separately to be loaded with sqlite3_load_extension and these extensions can be set from the Java API via SQLiteDatabaseConfiguration (similarly to the way custom functions are registered)

The value of BigDecimal is incorrectly read

Hi, I found a bug with reading BigDecimal values.

I have next class:

@Entity(propertyNameStyle = PropertyNameStyle.FLUENT_BEAN)
public interface IOperation extends Observable, Parcelable, Persistable, Serializable {

    @Key
    int getId();

    IOperation setId(int id);

    @Bindable
    @Column(nullable = false, value = "0")
    BigDecimal getValue();
}

Then I insert one value like this:

    @Override
    public Observable<Iterable<Operation>> call() {
        Set<Operation> operations = new TreeSet<>(this);
        operations.add(new Operation().setId(1).setValue(new BigDecimal("490000.99")));
        return data.insert(operations).toObservable();
    }

Created table in sqlite database:

CREATE TABLE IOperation (id integer primary key not null, value decimal default 0 not null)

with one record with id = 1 and value = 490000.99

But when value read by method io.requery.android.database.CursorWindow#getString(int, int) that use native function nativeGetString then method returns value == 490001, not 490000.99

Is it possible to read the recorded value?

custom functions: local reference table overflow

When using custom functions in the where clause of a query on some devices the app crashes with the following error:

10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] JNI ERROR (app bug): local reference table overflow (max=512) 10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] local reference table dump: 10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] Last 10 entries (of 510): 10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] 509: 0x707d7400 java.lang.String "1" 10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] 508: 0x707d7400 java.lang.String "1" 10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] 507: 0x707d7400 java.lang.String "1" 10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] 506: 0x707d7400 java.lang.String "1" 10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] 505: 0x707d7400 java.lang.String "1" 10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] 504: 0x707d7400 java.lang.String "1" 10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] 503: 0x707d7400 java.lang.String "1" 10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] 502: 0x707d7400 java.lang.String "1" 10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] 501: 0x707d7400 java.lang.String "1" 10-25 16:21:02.207 23312-23590/*** A/art: sart/runtime/indirect_reference_table.cc:113] 500: 0x707d7400 java.lang.String "1"

The devices on which this crash happens are the Samsung S4 (GT-I9505 Android 5.0.1) and the BQ Aquaris X (Android 7.1.1).

Proposal: more flexible Function interface for non-String args

In particular, accessing matchinfo() in a custom rank() function is a bit tricky. I see #39 suggests just writing it in C and I may eventually want to do that, but for now I have a rather hacky workaround:

            val bytes = packed.toByteArray(charset = utf16)
            val buffer = ByteBuffer.wrap(bytes)
            buffer.order(ByteOrder.nativeOrder())

            val longBuf = buffer.asLongBuffer()
            val ns = IntArray(bytes.size / 8) {
                longBuf.get().toInt()
            }

This works, but for each call to rank() it allocates the String, the Byte Array it contains, the String Array to hold the String, the Byte Array copy from the String, and the IntArray that ultimately holds the results. This is because the Int32s from sqlite's matchinfo() get packed into a UTF-16 string. xerial's JDBC client calls into some native functions to access the passed arguments directly, to avoid all those "middle man" allocations.

Now, lacking this sort of implementation on Android I can't benchmark to check if the allocation overhead would be worse than the JNI overhead, but that is my suspicion. A Function2 interface would also be more intuitive for these use cases, and avoids clients having to deal with NDK, which I think fits with the original goals for this project.

My hacky workaround seems to be performing okay for my dataset right now, but I wanted to put up this proposal to test the waters and see how difficult you guys think it'd be, and whether it's something you'd even be interested in. I'd be interesting in working on this myself, but I'm pretty busy with other parts of my project and it's not yet critical for me, so I didn't want to start without a nod of interest, and maybe a nudge in the right direction ;)

About Support R*Tree

hi , i want support R*Tree , so need rebuild *.so file . but i don't know if it will cause an unknown exception , can you rebuild it with '-DSQLITE_ENABLE_RTREE=1' config?

[ENHANCEMENT] Add support for DatabaseUtils class

I was up to migrate my current project to this SQLite library, but I encountered a small problem. You use custom SQLiteDatabase and SQLiteStatement classes which are incompatible with android.database.DatabaseUtils class.

Can you please add your own implementation of DatabaseUtils, so that migration would be easier for those who use this utility class?

Incorrect POM published to jcenter

In build.gradle a dependency on the support lib is specified, and it's resource ids packaged as R.txt into the published AAR. The pom.xml that is published does not declare any dependencies though.

I'm trying to depend on your library in another library project and I get build errors regarding R.txt. I'm not sure if that is caused by the missing dependency, but I think it should be fixed anyway.

Problem with missing class

After updating to version 3.24.0 we have an issue with missing class android.arch.persistence

"class file for android.arch.persistence.db.SupportSQLiteOpenHelper not found"

Native crashes

I am encountering some native crashes in my application. I don't know if this is a problem in the library, SQLite itself, or my own application, so any advice on narrowing this down would be appreciated. I am on release 3.16.0.

In both cases below, data is inserted into the database which is then closed and then opened again shortly after. The crashes occur when trying to open the DB. I've logged two crashes and I can't figure out any pattern to which one I end up with (my reproduction steps are not deterministic).

1

02-16 12:02:22.656 19894-19954/com.ichi2.anki A/libc: Fatal signal 11 (SIGSEGV), code 2, fault addr 0xaef15664 in tid 19954 (AsyncTask #1)
02-16 12:02:22.762 201-201/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-16 12:02:22.762 201-201/? A/DEBUG: Build fingerprint: 'google/hammerhead/hammerhead:6.0.1/M4B30Z/3437181:user/release-keys'
02-16 12:02:22.762 201-201/? A/DEBUG: Revision: '11'
02-16 12:02:22.762 201-201/? A/DEBUG: ABI: 'arm'
02-16 12:02:22.762 201-201/? A/DEBUG: pid: 19894, tid: 19954, name: AsyncTask #1  >>> com.ichi2.anki <<<
02-16 12:02:22.762 201-201/? A/DEBUG: signal 11 (SIGSEGV), code 2 (SEGV_ACCERR), fault addr 0xaef15664
02-16 12:02:22.781 201-201/? A/DEBUG:     r0 94740699  r1 aef15688  r2 000a4dcf  r3 94740000
02-16 12:02:22.781 201-201/? A/DEBUG:     r4 ab4b2de0  r5 aef15688  r6 af05f228  r7 af05f260
02-16 12:02:22.781 201-201/? A/DEBUG:     r8 1303da20  r9 acbd5e00  sl 1303d780  fp 70710558
02-16 12:02:22.781 201-201/? A/DEBUG:     ip aef58b30  sp aef15688  lr aeed53ab  pc aeed62e8  cpsr 800e0030
02-16 12:02:22.783 201-201/? A/DEBUG: backtrace:
02-16 12:02:22.783 201-201/? A/DEBUG:     #00 pc 0000f2e8  /data/app/com.ichi2.anki-1/lib/arm/libsqlite3x.so (_ZNSs20_M_compute_next_sizeEj+55)
02-16 12:02:22.783 201-201/? A/DEBUG:     #01 pc f8dab133  <unknown>
02-16 12:02:23.659 201-201/? A/DEBUG: Tombstone written to: /data/tombstones/tombstone_02
02-16 12:02:23.659 201-201/? E/DEBUG: AM write failed: Broken pipe

2

02-16 11:23:42.523 8556-8778/com.ichi2.anki A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x9c940000 in tid 8778 (AsyncTask #4)
02-16 11:23:42.625 198-198/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
02-16 11:23:42.625 198-198/? A/DEBUG: Build fingerprint: 'google/hammerhead/hammerhead:6.0.1/M4B30Z/3437181:user/release-keys'
02-16 11:23:42.625 198-198/? A/DEBUG: Revision: '11'
02-16 11:23:42.625 198-198/? A/DEBUG: ABI: 'arm'
02-16 11:23:42.625 198-198/? A/DEBUG: pid: 8556, tid: 8778, name: AsyncTask #4  >>> com.ichi2.anki <<<
02-16 11:23:42.625 198-198/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x9c940000
02-16 11:23:42.659 198-198/? A/DEBUG:     r0 92680699  r1 9c935688  r2 000a4dcf  r3 0000003e
02-16 11:23:42.659 198-198/? A/DEBUG:     r4 0000003e  r5 00000002  r6 00000002  r7 00004bce
02-16 11:23:42.659 198-198/? A/DEBUG:     r8 000000e4  r9 000054ed  sl 000054bc  fp 000000e0
02-16 11:23:42.659 198-198/? A/DEBUG:     ip 0000fffd  sp 9c935664  lr 000054ec  pc aec023b0  cpsr 400e0030
02-16 11:23:42.712 198-198/? A/DEBUG: backtrace:
02-16 11:23:42.712 198-198/? A/DEBUG:     #00 pc 0000f3b0  /data/app/com.ichi2.anki-2/lib/arm/libsqlite3x.so (_ZN7android19utf8ToJavaCharArrayEPKcPti+199)
02-16 11:23:42.712 198-198/? A/DEBUG:     #01 pc 0000e3a7  /data/app/com.ichi2.anki-2/lib/arm/libsqlite3x.so
02-16 11:23:42.712 198-198/? A/DEBUG:     #02 pc 00ccdd67  /data/app/com.ichi2.anki-2/oat/arm/base.odex (offset 0x627000) (java.lang.String io.requery.android.database.CursorWindow.nativeGetString(long, int, int)+106)
02-16 11:23:42.712 198-198/? A/DEBUG:     #03 pc 00cceb47  /data/app/com.ichi2.anki-2/oat/arm/base.odex (offset 0x627000) (java.lang.String io.requery.android.database.CursorWindow.getString(int, int)+106)
02-16 11:23:42.712 198-198/? A/DEBUG:     #04 pc 00cccee5  /data/app/com.ichi2.anki-2/oat/arm/base.odex (offset 0x627000) (java.lang.String io.requery.android.database.AbstractWindowedCursor.getString(int)+96)
02-16 11:23:42.712 198-198/? A/DEBUG:     #05 pc 0093d0ff  /data/app/com.ichi2.anki-2/oat/arm/base.odex (offset 0x627000) (void com.ichi2.libanki.Collection.load()+770)
02-16 11:23:42.712 198-198/? A/DEBUG:     #06 pc 0092ee35  /data/app/com.ichi2.anki-2/oat/arm/base.odex (offset 0x627000) (void com.ichi2.libanki.Collection.<init>(android.content.Context, com.ichi2.libanki.DB, java.lang.String, boolean, boolean)+856)
02-16 11:23:42.712 198-198/? A/DEBUG:     #07 pc 009adf8f  /data/app/com.ichi2.anki-2/oat/arm/base.odex (offset 0x627000) (com.ichi2.libanki.Collection com.ichi2.libanki.Storage.Collection(android.content.Context, java.lang.String, boolean, boolean)+634)
02-16 11:23:42.712 198-198/? A/DEBUG:     #08 pc 008b951d  /data/app/com.ichi2.anki-2/oat/arm/base.odex (offset 0x627000) (com.ichi2.libanki.Collection com.ichi2.anki.CollectionHelper.getCol(android.content.Context)+440)
02-16 11:23:42.712 198-198/? A/DEBUG:     #09 pc 008b96d9  /data/app/com.ichi2.anki-2/oat/arm/base.odex (offset 0x627000) (com.ichi2.libanki.Collection com.ichi2.anki.CollectionHelper.getColSafe(android.content.Context)+60)
02-16 11:23:42.713 198-198/? A/DEBUG:     #10 pc 00c7112f  /data/app/com.ichi2.anki-2/oat/arm/base.odex (offset 0x627000) (com.ichi2.async.DeckTask$TaskData com.ichi2.async.DeckTask.doInBackground(com.ichi2.async.DeckTask$TaskData[])+1218)
02-16 11:23:42.713 198-198/? A/DEBUG:     #11 pc 00c72281  /data/app/com.ichi2.anki-2/oat/arm/base.odex (offset 0x627000) (java.lang.Object com.ichi2.async.DeckTask.doInBackground(java.lang.Object[])+92)
02-16 11:23:42.713 198-198/? A/DEBUG:     #12 pc 7355bfb3  /data/dalvik-cache/arm/system@[email protected] (offset 0x1ed6000)
02-16 11:23:43.395 198-198/? A/DEBUG: Tombstone written to: /data/tombstones/tombstone_01
02-16 11:23:43.395 198-198/? E/DEBUG: AM write failed: Broken pipe

About ensureFile

hi , when i read your source code , i found the following clip in line 807 of SQLiteDatabase.java . I think it s superfluous

            if (!mConfigurationLocked.isInMemoryDb()) {
                ensureFile(mConfigurationLocked.path);
            }

ProProguard rules

The bundled ProGuard rules basically keep the entire library, both from shrinking and obfuscation. This is probably too broad, unless there's heavy use of reflection in the lib, so I'd like to request to either remove the generic ProGuard rules or to have more sensible defaults so that apps using this library can still strip and obfuscate parts of the library that they don't use.

Locale Issues: Requery Behaving Differently Than Framework SQLite

While testing CWAC-SafeRoom, I converted a bunch of existing tests for AOSP and SQLCipher for Android into a test suite that exercises the support database API.

When testing Requery, most things work. However, I have two failing tests, ones that work with the official support database implementation (FrameworkSQLiteOpenHelperFactory and kin).

The attached project is a subset of the full test suite that reproduces the two test failures:

RequeryLocale.zip

The icu() test method fails the official implementation on Android 4.4 and older, so I have that test rigged to only fail "for realz" on Android 5.0+. There, the official implementation works, but Requery doesn't. The testLocaleenUS() fails going all the way back to Android 4.1, but the official implementation works.

Both failures are tied to locale:

  • icu() tries to use UPPER in a query to convert a Cyrillic string to uppercase
  • testLocaleenUS() uses setLocale()

I didn't write either test -- these are both from the AOSP, IIRC. But, the framework SQLite implementation is effectively the reference implementation with respect to third-party support database implementations like yours and mine. I wasn't sure if you were aware of this difference in behavior or not, or whether you consider it "different, but working as intended" or not.

(and FWIW, CWAC-SafeRoom fails on these too, so I'll be working with Zetetic to figure out what this means)

Let me know if you need additional information!

can't able use json_each: it gives syntax error

Phone model = OPPO a37f
Sqlite version = 3.8.6.1

Caused by: android.database.sqlite.SQLiteException: near "(": syntax error (code 1): , while compiling: SELECT cl_contacts_cards_email50, cl_contacts_cards_address48 FROM WC_contacts_list, json_each(cl_contacts_cards_email50) as eml, json_each(cl_contacts_cards_address48) as address

Resource conflict with app_name string

Most applications use app_name resource as application name, right now it is conflicting with our resources too.

Usually it is a good idea to use prefixes for library resources to make sure they don't conflict with main application, i.e. use __requery_app_name instead of app_name.

If someone have the same issue, until it is fixed you can use manifest merger option to replace app_label:

<application
  ...
  tools:replace="label"
  >

More details is here: http://developer.android.com/tools/building/manifest-merge.html

no such function: json_extract

no such function: json_extract (code 1): , while compiling: select json_extract(tablename.emails, '$.email') from tablename

ContentProvider notifications is not working

Subj,

is it because all notifications is stripped out from the code or there is something else?

AbstractCursor:
https://github.com/requery/sqlite-android/blob/master/sqlite-android/src/main/java/io/requery/android/database/AbstractCursor.java

    @Override
    public void setNotificationUri(ContentResolver cr, Uri notifyUri) {
    }

    @Override
    public Uri getNotificationUri() {
        return null;
    }

while in original code they have this:
https://github.com/android/platform_frameworks_base/blob/4535e11fb7010f2b104d3f8b3954407b9f330e0f/core/java/android/database/AbstractCursor.java

    @Override
    public void setNotificationUri(ContentResolver cr, Uri notifyUri) {
        setNotificationUri(cr, notifyUri, UserHandle.myUserId());
    }

    /** @hide - set the notification uri but with an observer for a particular user's view */
    public void setNotificationUri(ContentResolver cr, Uri notifyUri, int userHandle) {
        synchronized (mSelfObserverLock) {
            mNotifyUri = notifyUri;
            mContentResolver = cr;
            if (mSelfObserver != null) {
                mContentResolver.unregisterContentObserver(mSelfObserver);
            }
            mSelfObserver = new SelfContentObserver(this);
            mContentResolver.registerContentObserver(mNotifyUri, true, mSelfObserver, userHandle);
            mSelfObserverRegistered = true;
        }
    }

    @Override
    public Uri getNotificationUri() {
        synchronized (mSelfObserverLock) {
            return mNotifyUri;
        }
    }

Add Object[] overload for rawQuery()

Please consider adding an overload for SQLiteDatabase.rawQuery which accepts a plain object array (Object[]) as arguments. Currently the argument array can only be strings.

public Cursor rawQuery(String sql, String[] selectionArgs)

This contrasts with execSQL() which allows a wider range of types to be passed through.

public void execSQL(String sql, Object[] bindArgs)

I appreciate there may be reluctance to break away from the official Android SQLiteDatabase API, but this would fix a particularly stupid restriction. This restriction means that since you can't pass a plain integer into a SQL query, your query has to be rewritten to cast the string to an integer instead. Instead of

WHERE ?1 = 1

we have to write

WHERE CAST(?1 as int) = 1

instead.

[ENHANCEMENT] Add SQLiteDatabase.OPEN_SHAREDCACHE flag

In original Android implementation there's literally no way of opening database with SQLITE_OPEN_SHAREDCACHE flag. Please add this possibility via custom flag for SQLiteDatabase.open(String, SQLiteDatabase.CursorFactory, int) method.

Shared cache is very important when using WAL database transaction between multiple threads with read_uncommitted pragma.

JUnit tests: 'no sqlite3x in java.library.path'

When trying to run JUnit tests in Android project I get the following error for any test touching database classes

java.lang.UnsatisfiedLinkError: no sqlite3x in java.library.path

and after first failure I see this error over and over:

java.lang.NoClassDefFoundError: Could not initialize class io.requery.android.database.sqlite.SQLiteDatabase

Is it possible to use this library in tests?

Android Studio open sqlite-android (error)

Hi, when i was trying to open sqlite-android using android studio, but i have some error about
SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.

Does anyone knows how to fix this problem ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.