Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.zezoca.listadetarefas.helper;
- import android.content.Context;
- import android.database.sqlite.SQLiteDatabase;
- import android.database.sqlite.SQLiteOpenHelper;
- import android.os.Build;
- import android.util.Log;
- import androidx.annotation.Nullable;
- public class DbHelper extends SQLiteOpenHelper {
- public static int VERSION = 1;
- public static String NOME_DB = "DB_notas";
- public static String TABELA_NOTAS = "notas";
- public DbHelper(@Nullable Context context) {
- super(context, NOME_DB, null, VERSION);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- String sql = "CREATE TABLE IF NOT EXISTS " + TABELA_NOTAS
- + " (id INTEGER PRIMARY KEY AUTOINCREMENT, " +
- "nome TEXT NOT NULL );";
- try {
- db.execSQL(sql);
- Log.i("INFO DB", "Sucesso ao criar a tabela");
- } catch (Exception e) {
- Log.i("INFO DB", "Erro ao criar a tabela" + e.getMessage());
- }
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- String sql = "DROP TABLE IF EXISTS " + TABELA_NOTAS + ";" ;
- try {
- db.execSQL(sql);
- onCreate(db);
- Log.i("INFO DB", "Sucesso ao atualizar App");
- } catch (Exception e) {
- Log.i("INFO DB", "Erro ao atualizar App" + e.getMessage());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement