Meus amigos, segue minha classe DbAdapter para uma tabela, o que preciso fazer para criar outra tabela?
package com.cursoandroid.anotacoes;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
public class DbAdapter {
private static final String DATABASE_NAME = "anotacoes";
private static final int DATABASE_VERSION =1;
private static final String DATABASE_TABLE_ANOTACOES = "notas";
public static final String KEY_ID = "_id";
public static final String KEY_NOME = "nome";
public static final String KEY_ANOTACAO = "descricao";
private static final String DATABASE_CREATE = "create table " + DATABASE_TABLE_ANOTACOES + " ("
+ KEY_ID + " integer primary key autoincrement, "
+ KEY_NOME + " text, "
+ KEY_ANOTACAO + " text);";
private final Context mCtx;
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
public DbAdapter(Context ctx){
this.mCtx = ctx;
}
public DbAdapter open() throws SQLiteException{
if(isClosed()){
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
}
return this;
}
public void close(){
mDbHelper.close();
}
public boolean isClosed(){
return mDb == null || !mDb.isOpen();
}
public Cursor getTodasAnotacoes(){
return mDb.query(DATABASE_TABLE_ANOTACOES, null, null, null, null, null, null);
}
// Cria anotação
public long createAnotacao(String nome, String nota){
ContentValues valores = new ContentValues();
valores.put(KEY_NOME, nome);
valores.put(KEY_ANOTACAO, nota);
return mDb.insert(DATABASE_TABLE_ANOTACOES, null, valores);
}
// Deleta anotação
public boolean deleteAnotacao(long Id){
int qt = mDb.delete(DATABASE_TABLE_ANOTACOES, KEY_ID + "=" + Id, null);
return qt > 0;
}
public Cursor getAnotacao(long Id){
return mDb.query(DATABASE_TABLE_ANOTACOES, null, KEY_ID + "=" + Id, null, null, null, null);
}
//eu que fiz essa
public Cursor getAnotacaoNome(String nomeString){
// return mDb.query(DATABASE_TABLE_ANOTACOES, null, KEY_NOME + "=" + nomeString, null, null, null, null);
String[] selectionArgs = {"%" + nomeString + "%"};
return mDb.rawQuery("SELECT * FROM notas WHERE nome like ?", selectionArgs);
}
public boolean updateAnotacao(long Id, String nome, String nota){
ContentValues valores = new ContentValues();
valores.put(KEY_NOME, nome);
valores.put(KEY_ANOTACAO, nota);
return mDb.update(DATABASE_TABLE_ANOTACOES, valores, KEY_ID + "=" + Id, null) > 0;
}
private class DatabaseHelper extends SQLiteOpenHelper{
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
}