Android Open Source - Android-ListView-ContentProvider D B Helper






From Project

Back to project page Android-ListView-ContentProvider.

License

The source code is released under:

MIT License

If you think the Android project Android-ListView-ContentProvider listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.iop.listprovider.helpers;
//from   w ww.j  a va 2s .  com
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * Created by Rafael Iop
 *
 * Classe de conexo e criao do banco de dados
 */

public class DBHelper extends SQLiteOpenHelper {

    // Tag para Log/Debug
    private static String TAG = "banco";

    private static String DB_NAME ="banco.sqlite"; // Nome do arquivo SQLite
    private static int DB_VERSION = 1; // Verso do banco de dados

    public DBHelper(Context context)
    {
        super(context, DB_NAME, null, DB_VERSION);
    }

    // Cria a tabela "nota"
    @Override
    public void onCreate(SQLiteDatabase db) {
        String createQuery = "CREATE TABLE nota (" +
                "_id INTEGER PRIMARY KEY  AUTOINCREMENT, " +
                "prioridade INTEGER DEFAULT '1' NOT NULL, " +
                "data INTEGER NOT NULL, " +
                "titulo VARCHAR(60) NOT NULL UNIQUE, " +
                "descricao VARCHAR(1000));";

        db.execSQL(createQuery);

        //Log
        Log.i(TAG, "Banco de dados criado");
    }

    // Atualiza o banco de dados caso tenha uma nova verso
    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        db.execSQL("DROP TABLE IF EXISTS nota");
        onCreate(db);

        //Log
        Log.i(TAG, "Atualizado: "+oldVersion+" para "+newVersion);
    }
}




Java Source Code List

com.iop.listprovider.MainActivity.java
com.iop.listprovider.NotaActivity.java
com.iop.listprovider.NotaLVAdapter.java
com.iop.listprovider.helpers.DBHelper.java
com.iop.listprovider.helpers.DateHelper.java
com.iop.listprovider.helpers.UIHelper.java
com.iop.listprovider.model.NotaCP.java
com.iop.listprovider.model.Nota.java