You don't need 'autoincrement', I think it's for MS SQL Server.

Just don't specify a value for the primary key when inserting, and a new
unique value will be generated for you. It is then returned by insert() to
your code, so you can use it in the 'many' table.

--
Kostya Vasilyev -- http://kmansoft.wordpress.com

13.11.2010 11:46 пользователь "pramod.deore" <deore.pramo...@gmail.com>
написал:

Hi, Bibek
  But when I write a command for foreign key then it doesn't give me
any error. And I didn't find any doc which say that foreign key is not
supported in android database.

But when i add autoincrement for foreign key then it gives me error.
My query is

sampleDB.execSQL("CREATE TABLE IF NOT EXISTS " +
                                       SWITCH_TABLE_NAME +
                       " (SwitchID integer autoincrement ,SwitchName
VARCHAR,FOREIGN KEY (SwitchID)REFERENCES roomtable (RoomID));");


and Logcat generate following error :

11-13 14:08:52.892: ERROR/Database(682): Failure 1 (near
"autoincrement": syntax error) on 0x2f95b8 when preparing 'CREATE
TABLE IF NOT EXISTS switchtable (SwitchID integer
autoincrement ,SwitchName VARCHAR,FOREIGN KEY (SwitchID)REFERENCES
roomtable (RoomID));'.
11-13 14:08:52.902: WARN/System.err(682):
android.database.sqlite.SQLiteException: near "autoincrement": syntax
error: CREATE TABLE IF NOT EXISTS switchtable (SwitchID integer
autoincrement ,SwitchName VARCHAR,FOREIGN KEY (SwitchID)REFERENCES
roomtable (RoomID));
11-13 14:08:52.914: WARN/System.err(682):     at
android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
11-13 14:08:52.924: WARN/System.err(682):     at
android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:
1610)
11-13 14:08:52.933: WARN/System.err(682):     at
com.monarch.home.AddSwitch.addSwitchToDatabase(AddSwitch.java:186)
11-13 14:08:52.933: WARN/System.err(682):     at
com.monarch.home.AddSwitch.onCreate(AddSwitch.java:66)
11-13 14:08:52.944: WARN/System.err(682):     at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:
1047)
11-13 14:08:52.953: WARN/System.err(682):     at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:
2459)
11-13 14:08:52.964: WARN/System.err(682):     at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:
2512)
11-13 14:08:52.964: WARN/System.err(682):     at
android.app.ActivityThread.access$2200(ActivityThread.java:119)
11-13 14:08:52.964: WARN/System.err(682):     at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
11-13 14:08:52.983: WARN/System.err(682):     at
android.os.Handler.dispatchMessage(Handler.java:99)
11-13 14:08:52.994: WARN/System.err(682):     at
android.os.Looper.loop(Looper.java:123)
11-13 14:08:53.004: WARN/System.err(682):     at
android.app.ActivityThread.main(ActivityThread.java:4363)
11-13 14:08:53.013: WARN/System.err(682):     at
java.lang.reflect.Method.invokeNative(Native Method)
11-13 14:08:53.013: WARN/System.err(682):     at
java.lang.reflect.Method.invoke(Method.java:521)
11-13 14:08:53.023: WARN/System.err(682):     at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-13 14:08:53.023: WARN/System.err(682):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-13 14:08:53.023: WARN/System.err(682):     at
dalvik.system.NativeStart.main(Native Method)
11-13 14:08:53.614: INFO/ActivityManager(62): Displayed activity
com.monarch.home/.AddSwitch: 981 ms (total 981 ms)


On Nov 13, 12:18 pm, Kumar Bibek <coomar....@gmail.com> wrote:
> Foreign keys are not supported on ...
> On Sat, Nov 13, 2010 at 12:31 PM, pramod.deore <deore.pramo...@gmail.com
>wrote:

>
> > Hi, can we autoincrement the foreign key in sqlite database?
> > Thanks
>
> > --
> > You recei...
> > android-developers+unsubscr...@googlegroups.com<android-developers%2bunsubscr...@googlegroups.com>
<android-developers%2bunsubscr...@googlegroups.com<android-developers%252bunsubscr...@googlegroups.com>
>

> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en...
> Kumar Bibekhttp://techdroid.kbeanie.comhttp://www.kbeanie.com


-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" ...

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to