I simply can't see how to get at this for a newly created record. What I had hoped for was the newly created Record ID. I note that the revExecuteSQL command simply returns the number of affected rows/records, a 0 or an ERR. Is there a way for me to get the DB_ID, that SQLite just created/inserted, rather than having to send my user back to a full list of DB records and expect them to fin and then select the record they've just entered ? The SQLITESEQUENCE table is created and initialized automatically whenever a normal table that contains an AUTOINCREMENT column is created. I can now UPDATE a record BUT cannot for the life of me see how to get my new DB_ID value back out so of my newly created / INSERTed record. SQLite keeps track of the largest ROWID that a table has ever held using the special SQLITESEQUENCE table. Integer PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUEĬREATE TABLE DBProperties (PID integer PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE. When I created the table in my DB ( CREATE TABLE.), I set the first field/column of that Table to be : tPositiveButton("Delete", new DialogInterface.I've gotten to the stage where I am now want to INSERT a record into my SQLite database LinearLayout layout = new LinearLayout(AndroidSQLite.this) = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT) ĭialogC1_id.setLayoutParams(dialogC1_idLayoutParams) įinal EditText dialogC2_id = new EditText(AndroidSQLite.this) ĭialogC2_id.setLayoutParams(dialogC2_idLayoutParams) = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT) ĭialogTxt_id.setLayoutParams(dialogTxt_idLayoutParams) ĭialogTxt_id.setText("#" + String.valueOf(item_id)) įinal EditText dialogC1_id = new EditText(AndroidSQLite.this) TextView dialogTxt_id = new TextView(AndroidSQLite.this) = new AlertDialog.Builder(AndroidSQLite.this) String item_content2 = cursor.getString(cursor.getColumnIndex(SQLiteAdapter.KEY_CONTENT2)) String item_content1 = cursor.getString(cursor.getColumnIndex(SQLiteAdapter.KEY_CONTENT1)) = new void onItemClick(AdapterView parent, View view, int position,Ĭursor cursor = (Cursor) parent.getItemAtPosition(position) įinal int item_id = cursor.getInt(cursor.getColumnIndex(SQLiteAdapter.KEY_ID)) I have one table which contains one field.StudentFname and that application is working fine with Android 2.3.1 and now if I add another field then my application is not working properly. Private ListView.OnItemClickListener listContentOnItemClickListener I have one problem with Android SQLite database. Example: CREATE TABLE Cats ( CatId INTEGER PRIMARY KEY, CatName ) In this table, the CatId column is an autoincrement column. By default, when you define a column as INTEGER PRIMARY KEY, it will auto-increment whenever you insert NULL into that column. Just use NULL value instead of id during insert and probably you shouldnt declare it as NOT NULL. Automatically Create an Auto-Increment Column. Then you can just insert a NULL value, or omit the column from the INSERT statement. String data2 = inputContent2.getText().toString() īutton.OnClickListener buttonDeleteAllOnClickListener To get an autoincrementing column, you need to declare it as INTEGER PRIMARY KEY (not INT ). String data1 = inputContent1.getText().toString() New SimpleCursorAdapter(AndroidSQLite.this, R.layout.row, cursor, from, to) īutton.OnClickListener buttonAddOnClickListener Public SQLiteAdapter openToRead() throws + KEY_ID + " integer primary key autoincrement, " "create table " + MYDATABASE_TABLE + " (" Private static final String SCRIPT_CREATE_DATABASE = create table MY_DATABASE (ID integer primary key, Content text not null) Public static final String KEY_CONTENT2 = "Content2" Public static final String KEY_CONTENT1 = "Content1" Public static final String KEY_ID = "_id" Public static final int MYDATABASE_VERSION = 1 Public static final String MYDATABASE_TABLE = "MY_TABLE" Public static final String MYDATABASE_NAME = "MY_DATABASE" The keyword AUTOINCREMENT can be used with INTEGER field only. We can auto increment a field value by using AUTOINCREMENT keyword when creating a table with specific column name to auto increment. Modify SQLiteAdapter.java to add method queueAll_SortBy_CONTENT1(), simple call sqLiteDatabase.query(MYDATABASE_TABLE, columns, null, null, null, null, KEY_CONTENT1) indirectly. SQLite AUTOINCREMENT is a keyword used for auto incrementing a value of a field in the table. Modify main.xml to add two key, sortbyDefault and sortby1. Modify to have option to quary order by default, adn to quary order by KEY_CONTENT1. Work on last exercise, " Edit row in SQLite database using SQLiteDatabase.update()".
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |