Extended SQLite functionality for Android

Overview

sqlite-provider Download Apache 2.0 Licence

A simplification of database access for Android.

Description

sqlite-provider implements a ContentProvider for you that allows database access using Uris The library is meant to augment the ContentProvider interface to fit SQLite in a more pronounced way. The aim is to set convention on queries via Uris.

Adding to your project

To start using this library, add these lines to the build.gradle of your project:

repositories {
    jcenter()
}

dependencies {
    compile 'com.novoda:sqlite-provider:2.0.0'
}

Upgrading from < 1.0.4

Please note the name change from sqliteprovider-core to sqlite-provider when the version went beyond 1.0.4 (all the way back in 2014!). If you're upgrading from a version that old, don't forget to change the name too!

Simple usage

Simple example source code can be found in this demo module: Android Simple Demo

Advanced queries & source code can be found in this demo module: Android Extended Demo

Links

Here are a list of useful links:

  • We always welcome people to contribute new features or bug fixes, here is how
  • If you have a problem check the Issues Page first to see if we are working on it
  • For further usage or to delve more deeply checkout the Project Wiki
  • Looking for community help, browse the already asked Stack Overflow Questions or use the tag: support-sqlite-provider when posting a new question
Comments
  • Clean Code: Cleaning up the Utils

    Clean Code: Cleaning up the Utils

    Refactors the DBUtils and DatabaseUtils class to make it cleaner, simpler and easier to use:

    • Move DBUtils and DatabaseUtils methods into DatabaseAnalyzer and StatementGenerator
    • Moves the SQL queries from DatabaseAnalyzer into classes that implement the Query interface
    • Moves query execution from DatabaseAnalyzer to QueryExecutor
    • Refactors code in DatabaseAnalyzer: consolidating duplicate code, simplifying methods, adding Column object to replace Map<String, String>
    • Deprecate public methods in DBUtils and DatabaseUtils
    opened by ronocod 12
  • Add bintray release script

    Add bintray release script

    I've added a gradle script that sets some properties that are necessary to publish to bintray and then it uses external scripts that make all the magic.

    This is the first one: https://gist.github.com/hal9002/0772dffbd8a6a81bc176

    This first script uses this other script https://gist.github.com/hal9002/691bbf3340dde3a4591d to generate all the files needed to publish to a maven repo (thanks to @blundell ) and it also sets some basic configuration for bintray and applies the bintray gradle plugin.

    The first gist can be modified to allow more customisation if necessary


    :x: do not merge yet, I need to create an API key for the novoda account in bintray

    But can be reviewed.

    opened by xrigau 12
  • Overhead of insert notifications

    Overhead of insert notifications

    I noticed that multiple notifications are sent when bulkInsert is used. I figured out this because you iterating each ContentValue and run an individual transaction insert on the item.

    @Override
    public int bulkInsert(Uri uri, ContentValues[] values) {
        int numValues = values.length;
        SQLiteDatabase mDb = mOpenHelper.getWritableDatabase();
        mDb.beginTransactionWithListener(this);
        try {
            for (int i = 0; i < numValues; i++) {
                Uri result = insertInTransaction(uri, values[i]);
                if (result != null) {
                    mNotifyChange = true;
                }
                mDb.yieldIfContendedSafely();
            }
            mDb.setTransactionSuccessful();
        } finally {
            mDb.endTransaction();
        }
    
        onEndTransaction();
        return numValues;
    }
    

    I cannot see the reason why you are using insert in favor of bulkInsert. Could you please clarify?

    opened by johnjohndoe 12
  • Fix gradle error

    Fix gradle error

    Problem Gradle fails with the following error:

    Gradle sync failed: Cannot access first() element from an empty List

    Solution This seems to be related a bintray-release issue that was resolved here.

    Nevertheless the bintray-release used in the core project has not been updated. Using latest bintray-release version (0.4.0) solves the issue as expected.

    opened by dnbit 10
  • Bulk insert should notify observers only once

    Bulk insert should notify observers only once

    Problem

    The bulkInsert method was notifying observers for every insert into the database. This is conceptually wrong, bulk insert should only notify once, at the end of the transaction.

    Solution

    We now notify only once, at the end of the transaction.

    Added a demo activity in the app example as well:

    sqlite_provider

    opened by Electryc 9
  • Problems with encodings reading from migrations file

    Problems with encodings reading from migrations file

    Hello,

    I don't really know if I am something wrong,but I have a problem while reading from the migrations file. Maybe can be an encoding problem when reading using the InputStreamReader or then, when executing: SQLFile.statementsFrom(reader); I thought that probably could be malformed chars that I was getting from the server, but when updating the db (I am updating in case hashCodes of the Strings are different), that is after the migrations file is executed for first time, the string is inserted correctly. It's html content.

    This is my sql script (I think that github is going to format this in html, sorry for that ):

    CREATE TABLE 'faq'
        (_id INTEGER PRIMARY KEY AUTOINCREMENT, title TEXT, hash_code INTEGER);
    
    CREATE TABLE 'faq_question'
        (_id INTEGER PRIMARY KEY AUTOINCREMENT,
        question TEXT,
        answer TEXT,
        hash_code INTEGER,
        faq_id INTEGER,
        FOREIGN KEY (faq_id) REFERENCES faq(_id) ON DELETE CASCADE);
    
    CREATE TABLE 'about_the_brand'
        (_id INTEGER PRIMARY KEY AUTOINCREMENT,
        about TEXT,
        hash_code INTEGER);
    
    INSERT INTO 'about_the_brand'
        (about, hash_code) VALUES ("<h2>ANOTHER WORLD LEADER</h2>\r\n\r\n<p>Since 2001, Boards & More has been marketing kites, kiteboards and\r\naccessories under the name North Kiteboarding.</p>\r\n\r\n<p>From the very beginning North Kiteboarding became a leading brand on the market thanks to both the innovative design and high quality.</p>\r\n\r\n<p>The North team strives to create pioneering and high quality products, always one step ahead at the forefront of the kiteboarding industry.</p>\r\n\r\n<p>In order to integrate the latest global trends, our products are tested and developed by our team-riders and designers at the 3 kite hot spots in Tarifa, Gorge and Hawaii.</p>\r\n\r\n<p>North Kiteboarding immediately assimilates new trends and styles, and has set new standards from the very outset, thanks to the high level of both team riders and designers. Amongst these innovations and standards are the patented Fifth-line-system, several security features as well as top-level shapes of kites and boards.</p>\r\n", -1574256766);
    

    //////////////////////// I also attach a couple of pictures as you can see what happens first time when reading from the file, and after loading same string from the server.

    I wish I had some time to research on this and solve the problem (in case it's something wrong with the read encoding) but I have to end up with a sprint, so I'll try to have a look over the weekend more deeply, but I would really appreciate if you can let me know your thoughts.

    Many thanks for your time and excuse me for the inconveniences (probably I am missing something). screenshot_2014-07-03-05-10-19 screenshot_2014-07-03-05-11-39

    opened by jfragosoperez 9
  • Split ExtendedSQLiteOpenHelper into two classes

    Split ExtendedSQLiteOpenHelper into two classes

    This PR splits ExtendedSQLiteOpenHelper into two classes: MigratingSQLiteOpenHelper and SQLiteDatabaseMetaInfo. This separates the concerns and allows to provide customized open helpers.

    While splitting the class the deprecated APIs have not been moved, but removed where possible.

    Tests have not been added or separated to show that all tests still pass.

    This fixes #57

    opened by friedger 8
  • Optional yieldIfContendedSafely() on bulkInsert

    Optional yieldIfContendedSafely() on bulkInsert

    Allowing to specify an optional query parameter for allowing or not yieldIfContendedSafely() during bulk inserts.

    The reasoning behind not wanting the yield is that in case of parallel multithreaded bulkInserts the yield will case ending and starting new transactions and thread context switching in turn causing performance issues.

    In order to keep backwards compatibility and for a more flexible API, we didn't removed the yield completely, but rather let the user choose. By default, the bulkInsert will yield.

    Notice the major increase of performance when not using yield:

    bluk_yield

    opened by Electryc 8
  • Fix handling of multi-column constraints

    Fix handling of multi-column constraints

    Problem

    When inserting into a table an update is tried first to provide upsert functionality. In the WHERE clause of the update, only the first column of any multi-column constraint is used.

    For this table:

    CREATE TABLE IF NOT EXISTS 'superhero' (
            _id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
            name TEXT NOT NULL,
            power TEXT NOT NULL,
            comic_company TEXT NOT NULL,
            UNIQUE (name, comic_company) ON CONFLICT REPLACE
    );
    

    only one entry would be allowed for each name value, when really one entry should be allowed for each combination of name and comic_company values.

    Solution

    Create the WHERE clause using every column in the constraint.

    • Adds a Constraint class which wraps a list of column names
    • Uses this class instead of a single String where needed
    • Deprecates the existing methods that use String instead of Constraint
    opened by ronocod 8
  • Fix issue handling 0 which is a valid row ID

    Fix issue handling 0 which is a valid row ID

    Only -1 indicates a problem according to http://d.android.com/reference/android/database/sqlite/SQLiteDatabase.html#insert(java.lang.String,%20java.lang.String,%20android.content.ContentValues)

    opened by alsutton 8
  • Clarify the relation between SQLiteContentProviderImpl and ExtendedSQLiteOpenHelper

    Clarify the relation between SQLiteContentProviderImpl and ExtendedSQLiteOpenHelper

    This PR clarifies the need of SQLiteContentProviderImpl for an ExtendedSQLiteOpenHelper.

    getDatabaseHelper is overwritten and returns the ExtendedSQLiteOpenHelper.

    opened by friedger 7
Releases(v2.0.0)
Active record style SQLite persistence for Android

ActiveAndroid ActiveAndroid is an active record style ORM (object relational mapper). What does that mean exactly? Well, ActiveAndroid allows you to s

Michael Pardo 4.7k Dec 29, 2022
greenDAO is a light & fast ORM solution for Android that maps objects to SQLite databases.

Check out ObjectBox Check out our new mobile database ObjectBox (GitHub repo). ObjectBox is a superfast object-oriented database with strong relation

Markus Junginger 12.6k Jan 3, 2023
An Android library that makes developers use SQLite database extremely easy.

LitePal for Android 中文文档 LitePal is an open source Android library that allows developers to use SQLite database extremely easy. You can finish most o

Lin Guo 7.9k Dec 31, 2022
Active record style SQLite persistence for Android

ActiveAndroid ActiveAndroid is an active record style ORM (object relational mapper). What does that mean exactly? Well, ActiveAndroid allows you to s

Michael Pardo 4.7k Dec 29, 2022
Android SQLite API based on SQLCipher

Download Source and Binaries The latest AAR binary package information can be here, the source can be found here. Compatibility SQLCipher for Android

SQLCipher 2.6k Dec 31, 2022
SquiDB is a SQLite database library for Android and iOS

Most ongoing development is currently taking place on the dev_4.0 branch. Click here to see the latest changes and try out the 4.0 beta. Introducing S

Yahoo 1.3k Dec 26, 2022
lightweight and minimalist ORM for Java/Android. works with SQLite & MySQL. (not actively maintained)

Description ORMAN is an minimalistic and lightweight ORM framework for Java which can handle your common database usage without writing SQL and strugg

Ahmet Alp Balkan 246 Nov 20, 2022
A Java/Kotlin library for Android platform, to manage bean's persistence in SQLite, SharedPreferences, JSON, XML, Properties, Yaml, CBOR.

Thanks to JetBrains for support Kripton Persistence Library project! Kripton Persistence Library Kripton is a java library, for Android platform, that

xcesco 117 Nov 11, 2022
Compile time processed, annotation driven, no reflection SQLite database layer for Android

SqliteMagic Simple yet powerful SQLite database layer for Android that makes database handling feel like magic. Overview: Simple, intuitive & typesafe

Siim Kinks 118 Dec 22, 2022
android 数据库框架,sqlite database

DBExecutor 主要的功能 1.使用了读写锁,支持多线程操作数据。 2.支持事务 3.支持ORM 4.缓存Sql,缓存表结构 这个类库主要用于android 数据库操作。 始终围绕着一个类对应一个表的概念。 只要创建一个实体类,就不用当心它怎么存储在数据库中,不用重新写增删改查的代码。基本的功

null 77 May 31, 2021
AndroidQuery is an Android ORM for SQLite and ContentProvider which focuses on easy of use and performances thanks to annotation processing and code generation

WARNING: now that Room is out, I no longer maintain that library. If you need a library to easy access to default android ContentProvider, I would may

Frédéric Julian 19 Dec 11, 2021
LiteOrm is a fast, small, powerful ORM framework for Android. LiteOrm makes you do CRUD operarions on SQLite database with a sigle line of code efficiently.

#LiteOrm:Android高性能数据库框架 A fast, small, powerful ORM framework for Android. LiteOrm makes you do CRUD operarions on SQLite database with a sigle line

马天宇 1.5k Nov 19, 2022
lightweight and minimalist ORM for Java/Android. works with SQLite & MySQL. (not actively maintained)

Description ORMAN is an minimalistic and lightweight ORM framework for Java which can handle your common database usage without writing SQL and strugg

Ahmet Alp Balkan 246 Nov 20, 2022
An Android library that makes developers use SQLite database extremely easy.

LitePal for Android 中文文档 LitePal is an open source Android library that allows developers to use SQLite database extremely easy. You can finish most o

Lin Guo 7.9k Jan 4, 2023
Realm is a mobile database: a replacement for SQLite & ORMs

Realm is a mobile database that runs directly inside phones, tablets or wearables. This repository holds the source code for the Java version of Realm

Realm 11.4k Jan 2, 2023
Exercicio praticando o SQLite, Room e Flow

Bus Scheduler App This folder contains the source code for the Bus Scheduler app codelab. Introduction The Bus Scheduler app displays a list of bus st

Lucas Caetano 0 Nov 26, 2021
ORMLite Android functionality used in conjunction with ormlite-core

ORMLite Android This package provides the Android specific functionality. You will also need to download the ormlite-core package as well. Users that

Gray 1.6k Dec 31, 2022
A blazing fast, powerful, and very simple ORM android database library that writes database code for you.

README DBFlow is fast, efficient, and feature-rich Kotlin database library built on SQLite for Android. DBFlow utilizes annotation processing to gener

Andrew Grosner 4.9k Dec 30, 2022
Object-relational mapping for Android

RushOrm Object-relational mapping for Android RushOrm replaces the need for SQL by mapping java classes to SQL tables. What is the aim? The aim is to

Stuart Campbell 172 Nov 11, 2022