create table users ( id integer primary key,name text )
并使用ExecuteScalar()执行队列:
select ( id ) from users where name = @name
但是,非常奇怪 – 我不能把返回值转换为’int’,只能’long’!为什么这样,’id’字段在数据库中被定义为’integer’,而不是’bigint’?
解决方法
Every row of every SQLite table has a
64-bit signed integer key that is
unique within the same table. This
integer is usually called the “rowid”.
The rowid is the actual key used in
the B-Tree that implements an SQLite
table. Rows are stored in rowid order.
The rowid value can be accessed using
one of the special names “ROWID”,
“OID”,or “ROWID“.If a column is declared to be an
INTEGER PRIMARY KEY,then that column
is not a “real” database column but
instead becomes an alias for the
rowid. Unlike normal SQLite columns,
the rowid must be a non-NULL integer
value. The rowid is not able to hold
floating point values,strings,BLOBs,
or NULLs.An INTEGER PRIMARY KEY column is an
alias for the 64-bit signed integer
rowid.
这是SQLite dynamic typing mechanism的副作用.
在实践中,要回答您的问题,您应该检索该值,并尽可能使用它,如果可能的话,仅使用转换运算符或转换类(如果值适合32位).因为它恰好是一个id,所以您不需要将其转换或转换为32位整数.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。