Note that there are some explanatory texts on larger screens.

plurals
  1. POSQLite DB Issues
    primarykey
    data
    text
    <p>I'm trying to do an insert into this database and i'll getting an error. Any ideas on what i'd doing wrong? It's a null exception error when i try and load this fragment. </p> <p>Helper Class:</p> <pre><code> @Override public void onCreate(SQLiteDatabase db) { db.execSQL( "CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID + " INTEGER AUTOINCREMENT, " + KEY_CHARTING_DATE + " TEXT NOT NULL, " + KEY_NAME + " TEXT, " + KEY_CHARTING_TEMPERATURE + " INTEGER, " + KEY_CHARTING_STAMPS + " INTEGER, " + KEY_CHARTING_FERTILE + " TEXT, " + KEY_CHARTING_NOTES + " TEXT, " + KEY_CHARTING_PROC + ", " + "PRIMARY KEY (" + KEY_ROWID + ", " + KEY_CHARTING_DATE + ") ); " ); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { // TODO Auto-generated method stub db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE + ";"); onCreate(db); } public long createEntry(String date, String temperature, String fertile, String notes) { ContentValues cv = new ContentValues(); cv.put(KEY_CHARTING_DATE, date); cv.put(KEY_CHARTING_TEMPERATURE, temperature); cv.put(KEY_CHARTING_FERTILE, fertile); cv.put(KEY_CHARTING_NOTES, notes); return ourDatabase.insert(DATABASE_TABLE, null, cv); } </code></pre> <p>Update button within another class:</p> <pre><code>@Override public void onClick(View v) { sqlDate = (EditText) getView().findViewById(R.id.dateselected); sqlTemperature = (EditText) getView().findViewById(R.id.tempvalue); sqlFertile = (Switch) getView().findViewById(R.id.fertileswitch); sqlNotes = (EditText) getView().findViewById(R.id.chartingnote); switch (v.getId()) { case R.id.chartingupdate: boolean success = true; try{ String date = sqlDate.getText().toString(); String temperature = sqlTemperature.getText().toString(); String fertile = sqlFertile.getText().toString(); String notes = sqlNotes.getText().toString(); SQLHelper entry = new SQLHelper(getActivity()); entry.open(); entry.createEntry(date, temperature, fertile, notes); entry.close(); } catch (Exception e ) { success = false; String err_msg = e.toString(); Dialog d = new Dialog(getActivity()); d.setTitle("Error Inserting"); TextView tv = new TextView(getActivity()); tv.setText(err_msg); d.setContentView(tv); d.show(); } finally { if (success) { Context context = getActivity(); Toast.makeText(context, "Charting Successful", Toast.LENGTH_LONG).show(); } else { Context context = getActivity(); Toast.makeText(context, "Charting Unsuccessful", Toast.LENGTH_LONG).show(); } } break; case R.id.pickdate: Context context2 = getActivity(); Toast.makeText(context2, "Hello toast 2!", Toast.LENGTH_LONG).show(); break; } } </code></pre> <p>EDIT:</p> <pre><code>public SQLHelper open() throws SQLException{ ourHelper = new DbHelper(ourContext); ourDatabase = ourHelper.getWritableDatabase(); return this; } </code></pre> <p>Error Says: 05-12 19:56:23.218: E/SQLiteLog(791): (1) near "AUTOINCREMENT": syntax error</p> <p>The problem is my table create.... The PK is on two column's. One an AUTOINCREMENT and another a date field. It's not liking it for some reason. If i change the PK to only that one AUTOINCREMENT column it works... Guess i'll have to just set it as the date field.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload