Sqlite CREATE TABLE如果不是EXISTS不工作?

时间:2012-11-28 00:45:59

标签: javascript sqlite

我错过了什么?我可以在Inspector窗口中看到数据库,但是没有表。 我可以在控制台中创建表格并显示,但它们不会自动显示。

这是openDatabase调用:

<script>var newdb = openDatabase('db2', '1.00', 'DB1', (100 * 1024 * 1024));

如果表不存在,则调用创建表:

    newdb.transaction(function (tx) {
      tx.executeSql('CREATE TABLE IF NOT EXISTS LOGS (id unique, log)');
      tx.executeSql('CREATE TABLE IF NOT EXISTS OBSERVATIONS (observation_id unique,     field_id, observation_date, phase_id, magnitude_id, summary)');
      tx.executeSql('INSERT INTO LOGS (id, log) VALUES (1, "Test Field 1")');
      tx.executeSql('INSERT INTO LOGS (id, log) VALUES (2, "Test Field 2")');
      tx.executeSql('INSERT INTO LOGS (id, log) VALUES (4, "Test Field 3")');
      tx.executeSql('INSERT INTO OBSERVATIONS (observation_id, field_id, observation_date, phase_id, magnitude_id, summary, plant_no) VALUES (1, 1, "1/1/2012", 1234, 5678, "This is Observation 1", 100)');
      tx.executeSql('INSERT INTO OBSERVATIONS (observation_id, field_id, observation_date, phase_id, magnitude_id, summary, plant_no) VALUES (2, 1, "1/2/2012", 1234, 5679, "This is Observation 2", 101)');
});

1 个答案:

答案 0 :(得分:3)

唉。我是个白痴。

我在插入观察时有错误的论点。