The command
INSERT OR REPLACE INTO SYSVAL ( CDDEVICE, DTVALINI, DTVALFIM,
SALDO, REALTIME, VALIDADO ) VALUES( '34322910071833580','31-08-2016',
'31-08-2016','10','63714560','S')
works seamlessly in SQLiteStudio, but does not work when run by the application on Android.
Although it does not cause any errors, the table remains empty.
I changed the insertion code to something like this:
Boolean result = false;
ContentValues values = new ContentValues();
values.put("CDDEVICE", valores[0].toString());
values.put("DTVALINI", valores[1].toString());
values.put("DTVALFIM", valores[2].toString());
values.put("SALDO", valores[3].toString());
values.put("REALTIME", valores[4].toString());
values.put("VALIDADO", valores[5].toString());
try{
db.insertOrThrow("SYSVAL", null, values);
result = true;
}
catch(Exception e)
{
Log.e("DB ERROR", e.toString());
e.printStackTrace();
}
And then it worked without problems.
Can anyone tell me why the first command is not working?
The structure of the SYSVAL table is as follows:
sqlString = "CREATE TABLE IF NOT EXISTS SYSVAL (" +
" CDDEVICE VARCHAR (25) NOT NULL," +
" DTVALINI DATE," +
" DTVALFIM DATE," +
" SALDO INT," +
" REALTIME NUMERIC(15)," +
" VALIDADO VARCHAR(1)," +
" CONSTRAINT SYSVAL_PK PRIMARY KEY ( CDDEVICE ) "+
");";
I'm running the command that does not work this way:
public Boolean executacomando( SQLiteDatabase db, String comando )
{
Boolean result = false;
try {
db.rawQuery( comando, null );
result = true;
}
catch (Exception e)
{
Log.e("DB Error", e.toString());
e.printStackTrace();
}
return result;
}
The method returns true normally, but the insert does not happen.