SQLite中的ROWID是否自动设置? [英] Is ROWID in SQLite automatically set?

查看:88
本文介绍了SQLite中的ROWID是否自动设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我在Ionic上拥有此应用程序,该应用程序使用 SQLite ngCordova插件内部存储器.在其上,我使用以下命令创建表:

  db.executeSql(如果不存在,则创建表Scans_table("+//" id TEXT PRIMARY KEY NOT NULL," id TEXT PRIMARY KEY NOT NULL,"+"名称文本不为空,"+"评论文字"+"文字TEXT NOT NULL,"+" format TEXT NOT NULL,"+" dateTaken TEXT NOT NULL,"+" imgSource TEXT NOT NULL)',...); 

根据,如果我没有的列是主键和一个整数,应将ROWID设置为唯一标识符.

问题是,当我使用简单的 SELECT * ... 查询表时,看到的是我设置的所有行,而不是ROWID.

是否有其他设置/检查ROWID的方法?

解决方案

文档,您的表 有一个内部的 rowid 列.但是,如果表的列列表不包含该列的别名(即INTEGER PRIMARY KEY列),则 rowid 列不包含在 SELECT * 中./p>

您只需在SELECT子句中添加该列:

  SELECT rowid,* FROM Scans_table ... 

但是,如果您实际使用 rowid ,最好有一个明确的INTEGER PRIMARY KEY列.这不仅可以更好地记录表结构,而且可以防止 rowid 值被更改通过VACUUM语句.

So, I have this application on Ionic that uses the SQLite ngCordova plugin for internal storage. On it, I create a table with the following command:

db.executeSql(
    "CREATE TABLE IF NOT EXISTS Scans_table (" +
      //"id         TEXT PRIMARY KEY  NOT NULL," +
      "name       TEXT              NOT NULL," +
      "comment    TEXT, " +
      "text       TEXT              NOT NULL, " +
      "format     TEXT              NOT NULL, " +
      "dateTaken  TEXT              NOT NULL, " +
      "imgSource  TEXT              NOT NULL)", ... );

According to this, if I don't have a column that is a primary key and an integer, a ROWID should be set as a unique identifier.

The problem is, when I query the table with a simple SELECT * ... I see all the rows that I set, and not the ROWID.

Is there a different way to set/check the ROWID?

解决方案

As shown in the documentation, your table does have an internal rowid column. However, if your table's column list does not include an alias for this column (i.e., an INTEGER PRIMARY KEY column), the rowid column is not included in SELECT *.

You can just add the column in the SELECT clause:

SELECT rowid, * FROM Scans_table ...

However, if you actually use the rowid, it is a better idea to have an explicit INTEGER PRIMARY KEY column. This not only documents the table structure better, but also prevents the rowid values from being changed by the VACUUM statement.

这篇关于SQLite中的ROWID是否自动设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆