None of the notes are created and as such I can't do anything with
them, help would be appreciated. TestCount always returns 0.
package com.real;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class NotesDbAdapter {
public static final String KEY_VALUE = "x";
public static final String KEY_ISROOT = "y";
public static final String KEY_ROWID = "_id";
public static final String KEY_REALROWID = "_ids";
public static final String KEY_ISPOWER = "z";
public static final String KEY_POWERORROOTNUMBER = "b";
public static final String KEY_ISDIVISOR = "a";
public static final String KEY_ISMULTIPLIER = "c";
public static final String KEY_ISADD = "d";
public static final String KEY_ISSUBTRACT = "e";
public static final String KEY_ISPS = "f";
public static final String KEY_ISPE = "g";
private static final String TAG = "NotesDbAdapter";
private DatabaseHelper mDbHelper;
private SQLiteDatabase mDb;
private static final String DATABASE_NAME = "data";
private static final String DATABASE_TABLE = "notes";
private static final int DATABASE_VERSION =20;
private static final String DATABASE_CREATE =
" create table " +DATABASE_TABLE+ " ("
+KEY_VALUE+ " double, "
+KEY_REALROWID+ " integer, "
+KEY_ROWID+ " integer primary key autoincrement, "
+KEY_ISPOWER+ " boolean, "
+KEY_ISDIVISOR+ " boolean, "
+KEY_ISMULTIPLIER+ " boolean, "
+KEY_ISADD+ " boolean, "
+KEY_ISSUBTRACT+ " boolean, "
+KEY_ISPS+ " boolean, "
+KEY_ISPE+ " boolean, "
+KEY_POWERORROOTNUMBER+ " double, "
+KEY_ISROOT+ " boolean);";
private final Context mCtx;
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
try {
db.execSQL(DATABASE_CREATE);
} catch (Exception e) {
Log.e("dbAdapter", e.getMessage().toString());
}
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion
+ " to "
+ newVersion + ", which will destroy all old
data");
db.execSQL("DROP TABLE IF EXISTS notes");
onCreate(db);
}
}
public NotesDbAdapter(Context ctx) {
this.mCtx = ctx;
}
public NotesDbAdapter open() throws SQLException {
mDbHelper = new DatabaseHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
public void close() {
mDbHelper.close();
}
public void createNote(double value, boolean isroot, boolean
ispower, boolean ismultiply, boolean isdivisor, boolean add,
boolean issubtract, double roototpowerval, boolean
paranthaseesend, boolean paranthaseesstart) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_VALUE, value);
initialValues.put(KEY_ISROOT, isroot);
initialValues.put(KEY_ISPOWER, ispower);
initialValues.put(KEY_ISMULTIPLIER, ismultiply);
initialValues.put(KEY_ISDIVISOR, isdivisor);
initialValues.put(KEY_ISADD, add);
initialValues.put(KEY_ISSUBTRACT, issubtract);
initialValues.put(KEY_POWERORROOTNUMBER, roototpowerval);
initialValues.put(KEY_ISPE, paranthaseesend);
initialValues.put(KEY_ISPS, paranthaseesstart);
long r= mDb.insert(DATABASE_TABLE, null, initialValues);
int a = testCount();
ContentValues argsa = new ContentValues();
argsa.put(KEY_VALUE, value);
argsa.put(KEY_ISROOT, isroot);
argsa.put(KEY_ISPOWER, ispower);
argsa.put(KEY_ISMULTIPLIER, ismultiply);
argsa.put(KEY_ISDIVISOR, isdivisor);
argsa.put(KEY_ISADD, add);
argsa.put(KEY_ISSUBTRACT, issubtract);
argsa.put(KEY_POWERORROOTNUMBER, roototpowerval);
argsa.put(KEY_REALROWID, a);
argsa.put(KEY_ISPE, paranthaseesend);
argsa.put(KEY_ISPS, paranthaseesstart);
mDb.update(DATABASE_TABLE, argsa, KEY_ROWID + "=" + r, null);
}
public void deleteNote(long rowId) {
mDb.delete(DATABASE_TABLE, KEY_REALROWID + "=" + rowId, null);
int x = (int) rowId;
int y = testCount();
while(x<y)
{x++;
Cursor note= fetchNote(x);
ContentValues argsan = new ContentValues();
argsan.put(KEY_VALUE,
note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_VALUE)));
argsan.put(KEY_ISROOT,
note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_ISROOT)));
argsan.put(KEY_ISPOWER,
note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_ISPOWER)));
argsan.put(KEY_ISMULTIPLIER,
note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_ISMULTIPLIER)));
argsan.put(KEY_ISDIVISOR,
note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_ISDIVISOR)));
argsan.put(KEY_ISADD,
note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_ISADD)));
argsan.put(KEY_ISSUBTRACT,
note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_ISSUBTRACT)));
argsan.put(KEY_POWERORROOTNUMBER,
note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_POWERORROOTNUMBER)));
argsan.put(KEY_ISPE,
note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_ISPE)));
argsan.put(KEY_ISPS,
note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_ISPS)));
argsan.put(KEY_REALROWID, x-1);
mDb.update(DATABASE_TABLE, argsan, KEY_ROWID + "=" +
Integer.valueOf(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_ROWID))),
null);
}
}
public void deleteAllNotes() { mDb.execSQL("DROP TABLE IF EXISTS
notes");mDb.execSQL(DATABASE_CREATE);}
public Cursor fetchAllNotes() {
return mDb.query(DATABASE_TABLE, new String[]
{KEY_ISPS,KEY_ISPE,KEY_VALUE,KEY_ISROOT,KEY_REALROWID,KEY_ISPOWER,KEY_POWERORROOTNUMBER,KEY_ISDIVISOR,KEY_ISMULTIPLIER,KEY_ISADD,KEY_ISSUBTRACT},
null, null, null, null, null);
}
public Cursor fetchNote(long rowId) throws SQLException {
Cursor mCursor =
mDb.query(true, DATABASE_TABLE, new String[]
{KEY_ISPS,KEY_ISPE,KEY_VALUE,KEY_ISROOT,KEY_REALROWID,KEY_ISPOWER,KEY_POWERORROOTNUMBER,KEY_ISDIVISOR,KEY_ISMULTIPLIER,KEY_ISADD,KEY_ISSUBTRACT},
KEY_REALROWID + "=" + rowId, null,
null, null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
return mCursor;
}
public int testCount() {
Cursor c = mDb.rawQuery("select count(*) from notes", null);
int tst = 0;
if (c.moveToNext()) {
tst = c.getInt(c.getColumnIndex("count(*)"));
}
return tst;
}
public boolean updateNote(double value, boolean isroot, boolean
ispower, boolean ismultiply, boolean isdivisor, boolean add,
boolean issubtract, double roototpowerval, int RowId, boolean
paranthaseesend, boolean paranthaseesstart) {
ContentValues args = new ContentValues();
args.put(KEY_VALUE, value);
args.put(KEY_ISROOT, isroot);
args.put(KEY_ISPOWER, ispower);
args.put(KEY_ISMULTIPLIER, ismultiply);
args.put(KEY_ISDIVISOR, isdivisor);
args.put(KEY_ISADD, add);
args.put(KEY_ISSUBTRACT, issubtract);
args.put(KEY_POWERORROOTNUMBER, roototpowerval);
args.put(KEY_ISPE, paranthaseesend);
args.put(KEY_ISPS, paranthaseesstart);
return mDb.update(DATABASE_TABLE, args, KEY_REALROWID + "=" +
RowId, null) > 0;
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en