You're giving this error, I'd like to know if my DAO is right.
Error:
08-06 14:19:53.304: E/SQLiteLog(16893): (1) no such table: proposta
08-06 14:19:53.334: E/SQLiteDatabase(16893): Error inserting validadebrinde=x validade=cd idusuario=1 brinde=c
08-06 14:19:53.334: E/SQLiteDatabase(16893): android.database.sqlite.SQLiteException: no such table: proposta (code 1): , while compiling: INSERT INTO proposta(validadebrinde,validade,idusuario,brinde) VALUES (?,?,?,?)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:882)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:493)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:588)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:31)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1467)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1339)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at br.com.android.controledevisitas.dao.PropostaDAO.cadastrar(PropostaDAO.java:43)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at br.com.android.controledevisitas.view.CadastrarPropostaActivity.cadastrarProposta(CadastrarPropostaActivity.java:122)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at br.com.android.controledevisitas.view.CadastrarPropostaActivity$2.onClick(CadastrarPropostaActivity.java:78)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.view.View.performClick(View.java:4091)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.view.View$PerformClick.run(View.java:17036)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.os.Handler.handleCallback(Handler.java:615)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.os.Handler.dispatchMessage(Handler.java:92)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.os.Looper.loop(Looper.java:137)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at android.app.ActivityThread.main(ActivityThread.java:5031)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at java.lang.reflect.Method.invokeNative(Native Method)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at java.lang.reflect.Method.invoke(Method.java:511)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:792)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:555)
08-06 14:19:53.334: E/SQLiteDatabase(16893): at dalvik.system.NativeStart.main(Native Method)
My DAO:
package br.com.android.controledevisitas.dao;
import br.com.android.controledevisitas.model.Proposta;
import br.com.android.controledevisitas.util.Dados;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class PropostaDAO extends SQLiteOpenHelper {
private static final String TABELA = "proposta";
private static final Dados dados = new Dados();
public PropostaDAO(Context ctx) {
super(ctx, dados.DATABASE, null, dados.VERSAO);
}
@Override
public void onCreate(SQLiteDatabase db) {
String sql = "create table "
+ TABELA
+ "(id integer primary key, idusuario integer, validade text, brinde text, validadebrinde text);";
db.execSQL(sql);
}
public void onUpgrade(SQLiteDatabase db, int versaoAntiga, int versaoNova) {
String sql = "drop table if exists " + TABELA;
db.execSQL(sql);
onCreate(db);
}
public Boolean cadastrar(Proposta p) {
try {
ContentValues cv = new ContentValues();
cv.put("idusuario", 1);
cv.put("validade", p.getValidade());
cv.put("brinde", p.getBrinde());
cv.put("validadebrinde", p.getValidadeBrinde());
getWritableDatabase().insert(TABELA, null, cv);
return true;
} catch (Exception e) {
Log.e("DAO", e.getMessage());
return false;
}
}
public int getUltimoId() {
Cursor c = getReadableDatabase().rawQuery(
"select max(id) from " + TABELA, null);
if (c.moveToNext()) {
return c.getInt(c.getColumnIndex("id"));
}
return 0;
}
}