lundi 30 novembre 2015

Android Sqlite Insert syntax error

I can't seem to find out what exactly I did wrong here. Seem to be getting a syntax error in my insert command inside the addCheck method.

Android SQLite Insert Error (Syntax error code 1)

I've added my database code:

public void createNewTable(int _id, boolean _emp){
    SQLiteDatabase db = this.getWritableDatabase();
        Log.v("Database", "Adding Check in table: " + _id);
        String CREATE_TABLE = " CREATE TABLE " + Integer.toString(_id) + "("
                + KEY_DATE + " TEXT," + KEY_TIME_IN + " TEXT," + KEY_TIME_OUT + " TEXT,"
                + KEY_LATITUDE_IN + " REAL," + KEY_LONGITUDE_IN + " REAL," + KEY_LATITUDE_OUT + " REAL,"
                + KEY_LONGITUDE_OUT + " REAL" + ")";
        db.execSQL(CREATE_TABLE);}
public void addCheck(Check check){
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    //values.put(KEY_ID, user.getId());
    values.put(KEY_DATE, check.getDate());
    values.put(KEY_TIME_IN, check.getTimeIn());
    values.put(KEY_TIME_OUT, check.getTimeOut());
    values.put(KEY_LATITUDE_IN, check.getLocIn().getLatitude());
    values.put(KEY_LONGITUDE_IN, check.getLocIn().getLongitude());
    values.put(KEY_LATITUDE_OUT, check.getLocOut().getLatitude());
    values.put(KEY_LONGITUDE_OUT, check.getLocOut().getLongitude());
    // Inserting Row
    db.insert(Integer.toString(check.getId()), null, values);
    db.close();
}

The check class is:

public class Check {
int _id;
String _date;
String _timeIn;
String _timeOut;
Location _locIn;
Location _locOut;

public Check(){}
public Check(int id, String date, String t_in, Location l_in){
    this._id=id;
    this._date=date;
    this._timeIn=t_in;
    this._locIn=l_in;
    this._locOut= new Location("");
    this._timeOut="0";
}

public Check(int id, String date, String t_in, String t_out, Location l_in, Location l_out){
    this._id=id;
    this._date=date;
    this._timeIn=t_in;
    this._timeOut=t_out;
    this._locIn=l_in;
    this._locOut=l_out;
}

public int getId(){return this._id;}
public String getDate(){return this._date;}
public String getTimeIn(){return this._timeIn;}
public String getTimeOut(){return this._timeOut;}
public Location getLocIn(){return this._locIn;}
public Location getLocOut(){return this._locOut;}

public void setId(int id){this._id=id;}
public void setDate(String date){this._date=date;}
public void setTimeIn(String t_in){this._timeIn=t_in;}
public void setTimeOut(String t_out){this._timeOut=t_out;}
public void setLocIn(Location l_in){this._locIn=l_in;}
public void setLocOut(Location l_out){this._locOut=l_out;}}

Finally my logcat error is:

E/SQLiteDatabase﹕ Error inserting latCheckIn=-33.85147605 longCheckOut=0.0 latCheckOut=0.0 timeCheckIn=11:53:49 timeCheckOut=0 longCheckIn=18.647984 date=2015-11-30
android.database.sqlite.SQLiteException: near "1": syntax error (code 1): , while compiling: INSERT INTO 1(latCheckIn,longCheckOut,latCheckOut,timeCheckIn,timeCheckOut,longCheckIn,date) VALUES (?,?,?,?,?,?,?)

I know this is just a syntax error, but I really can't find it. Any help would be appreciated.

Thanks

Aucun commentaire:

Enregistrer un commentaire