You can list the column names in the SQL INSERT statement.  Leave the
autoincrement column name out of the list and the value will be
generated automatically.

But if you want to get back the generated key value then you must use
the SQLiteDatabase.insert() API method

On Dec 7, 6:27 am, Ederson Ferreira <[email protected]> wrote:
> Hi,
>
> You don't need to pass anything.
> Try to use myDB.insert instead of myDB.execSQL, for instance:
>
> ContentValues values = new ContentValues();
> values.put("field1", "value_for_field1");
> values.put("field2", "value_for_field2");
> myDB.insert(MY_TABLE, null, values);
>
> Realize that you do not need to inform what is the value for your PK field.
> After calling myDB.insert you will get, as return, the PK value used to
> create your record.
>
> You also can find more detailed information 
> onhttp://developer.android.com/reference/android/database/sqlite/SQLite...,
> java.lang.String, android.content.ContentValues)
>
> Éderson
>
> On Mon, Dec 7, 2009 at 12:11 PM, Jags <[email protected]> wrote:
> > i am doing sqlite3
>
> > my tables's pk is auto-increment. What shpuld i pass its value while
> > inserting so that auto increment executes properly ?
>
> >        public void writeRecord(Row rec) {
> >                try {
> >                Object[] bindArgs = new Object[] {-1, rec.name, rec.email};
> >                 myDB.execSQL("INSERT INTO "
>
>                                + MY_TABLE
>
> >                                + " VALUES (?, ?, ?);", bindArgs);
> >                }
> >                catch(Exception e) {
> >                        Log.d("Exception: ", e.getMessage());
> >                }
> >        }
>
> > moreover, i need to extract this newly generated pk value, how can i
> > get that ?
>
> > regards
>
> > --
> > 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]<android-developers%[email protected]>
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en

-- 
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

Reply via email to