1

I am creating a table inside the DB.I am a successfully created a table and able to insert data on table my issue is that in my table I have two "ID" columns but I only created one .why two ID column generate in table.

Follow this step to generate issue :-

  • Click the bottom right button (enter the text in pop up screen ).Press "add" button .It generate the row in a "cases" table but when you inspect it show two column of "ID" why ?

Here is my code http://codepen.io/anon/pen/OVPgoP

db.transaction(function(tx) {
    tx.executeSql('CREATE  TABLE "Cases" ("ID" INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL , "CaseName" VARCHAR NOT NULL )');
})
Deepesh
  • 8,065
  • 3
  • 28
  • 45
user944513
  • 12,247
  • 49
  • 168
  • 318

2 Answers2

2

It appears that this is the expected behaviour for SQLite, the technology underpinning Web SQL (which is a deprecated technology, btw).

From the docs:

If a table contains a column of type INTEGER PRIMARY KEY, then that column becomes an alias for the ROWID. You can then access the ROWID using any of four different names, the original three names described above or the name given to the INTEGER PRIMARY KEY column. All these names are aliases for one another and work equally well in any context.

Therefore, my guess is that the Chrome devtools are showing the rowid column using its alias (ID), in addition to the alias column explicitly added (ID).

It seems like you don't actually need to explicitly add an ID column with Web SQL/SQLite. It will add one for you, which you can refer to using rowid, _rowid_ or oid in any statement.

EDIT: Here is a fork of your CodePen, with updates and deletes all correctly working.

GregL
  • 37,147
  • 8
  • 62
  • 67
0

Totally new to webSQL, so this answer is very useful to me as well. You can't expect primary keys to work properly with webSQL because internally it tracks something called "rowid" as the primary key. Use unique instead, as seen in a useful example here. You can also use this error code from the spec to figure out if a non-unique column value was inserted.

Hypaethral
  • 1,467
  • 16
  • 22