Android Handy SQLite Helper Library

A library for shipping SQLite databases within application assets and optionally placing them in external storage

Лицензия

Лицензия

Категории

Категории

SQLite Данные Базы данных
Группа

Группа

org.deejdev.database.handysqlite
Идентификатор

Идентификатор

handysqlite
Последняя версия

Последняя версия

1.0
Дата

Дата

Тип

Тип

aar
Описание

Описание

Android Handy SQLite Helper Library
A library for shipping SQLite databases within application assets and optionally placing them in external storage
Ссылка на сайт

Ссылка на сайт

https://github.com/ultimate-deej/Android-Handy-SQLite-Helper
Система контроля версий

Система контроля версий

https://github.com/ultimate-deej/Android-Handy-SQLite-Helper

Скачать handysqlite

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/org.deejdev.database.handysqlite/handysqlite/ -->
<dependency>
    <groupId>org.deejdev.database.handysqlite</groupId>
    <artifactId>handysqlite</artifactId>
    <version>1.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/org.deejdev.database.handysqlite/handysqlite/
implementation 'org.deejdev.database.handysqlite:handysqlite:1.0'
// https://jarcasting.com/artifacts/org.deejdev.database.handysqlite/handysqlite/
implementation ("org.deejdev.database.handysqlite:handysqlite:1.0")
'org.deejdev.database.handysqlite:handysqlite:aar:1.0'
<dependency org="org.deejdev.database.handysqlite" name="handysqlite" rev="1.0">
  <artifact name="handysqlite" type="aar" />
</dependency>
@Grapes(
@Grab(group='org.deejdev.database.handysqlite', module='handysqlite', version='1.0')
)
libraryDependencies += "org.deejdev.database.handysqlite" % "handysqlite" % "1.0"
[org.deejdev.database.handysqlite/handysqlite "1.0"]

Зависимости

Библиотека не имеет зависимостей. Это самодостаточное приложение, которое не зависит ни от каких других библиотек.

Модули Проекта

Данный проект не имеет модулей.

Handy SQLite Helper for Android

A library for shipping SQLite databases within application assets and optionally placing them in external storage

Setup

Maven

<dependency>
    <groupId>org.deejdev.database.handysqlite</groupId>
    <artifactId>handysqlite</artifactId>
    <version>1.0</version>
    <type>aar</type>
</dependency>

Gradle

dependencies {
    ...
    compile 'org.deejdev.database.handysqlite:handysqlite:1.0'
}

Usage

Using the library is similar to using framework's SQLiteOpenHelper. Create a subclass of HandySQLiteHelper as you do when using SQLiteOpenHelper, and pass context, InputStream, destination File and version to constructor.

Examples

Basic usage. Database is read from asset and extracted into standard database directory.

public class OpenHelper extends HandySQLiteHelper {
    private static final int DATABASE_VERSION = 1;
    private static final String DATABASE_NAME = "db.sqlite"; // both asset name and destination file name

    public OpenHelper(Context context, InputStream input, File destinationPath, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, getInput(context), context.getDatabasePath(DATABASE_NAME), null, DATABASE_VERSION);
    }

    private static InputStream getInput(Context context) {
        try {
            AssetManager assets = context.getAssets();
            return assets.open(DATABASE_NAME);
        } catch (IOException e) {
            // Should not happen normally
            throw new HandySQLiteHelperException("Error reading database from assets", e);
        }
    }
}

To place database in external storage specify a corresponding path

public OpenHelper(Context context, InputStream input, File destinationPath, SQLiteDatabase.CursorFactory factory, int version) {
    super(context, getInput(context), new File("/mnt/sdcard/some/random/path"), null, DATABASE_VERSION);
}

If you are developing for Android 2.2, and your database is larger than 1MB, consider splitting it into smaller chunks. See this issue

private static InputStream getInput(Context context) {
    try {
        AssetManager assets = context.getAssets();
        ArrayList<InputStream> chunks = new ArrayList<InputStream>();
        chunks.add(assets.open("database_aa"));
        chunks.add(assets.open("database_ab"));
        chunks.add(assets.open("database_ac"));
        chunks.add(assets.open("database_ad"));
        return new SequenceInputStream(Collections.enumeration(chunks));
    } catch (IOException e) {
        // Should not happen normally
        throw new EmbeddedSQLiteException("Error reading database from assets", e);
    }
}

License

Copyright 2014 Maxim Naumov

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.

Версии библиотеки

Версия
1.0