create table users ( id integer primary key,name text )
并使用ExecuteScalar()执行队列:
select ( id ) from users where name = @name
但是,非常奇怪 – 我不能把返回值转换为’int’,只能’long’!为什么这样,’id’字段在数据库中被定义为’integer’,而不是’bigint’?
@R_502_323@
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位整数.