评估字符串类型字段中的值
Evaluate value in string-type field
我有以下代码:
1) table "keys" with Field ('kcv', 'string')
2) grid = SQLFORM.grid(db.keys, user_signature=False)
当我尝试在 kcv 字段中编辑或创建值为 9E2 的记录时,我在新记录的 kcv 字段中得到“900”。
如何在不评估的情况下在记录中获取字符串“9E2”?为什么 web2py 试图解释字符串字段中的值?
如果您使用的是 SQLite,您可能最初将字段定义为类型 double
(或 decimal
),后来“迁移”为类型 string
。如前所述 here, such migrations have no effect in SQLite, so SQLite will continue to treat the column as numeric and coerce values to numbers when possible (SQLite does not complain about storing non-numeric strings in the column because it does not have rigid column types -- it simply has type affinities, which determine what types of coercions may happen -- see https://www.sqlite.org/datatype3.html).
您必须重新创建 table,从正确的列类型开始。
我有以下代码:
1) table "keys" with Field ('kcv', 'string')
2) grid = SQLFORM.grid(db.keys, user_signature=False)
当我尝试在 kcv 字段中编辑或创建值为 9E2 的记录时,我在新记录的 kcv 字段中得到“900”。 如何在不评估的情况下在记录中获取字符串“9E2”?为什么 web2py 试图解释字符串字段中的值?
如果您使用的是 SQLite,您可能最初将字段定义为类型 double
(或 decimal
),后来“迁移”为类型 string
。如前所述 here, such migrations have no effect in SQLite, so SQLite will continue to treat the column as numeric and coerce values to numbers when possible (SQLite does not complain about storing non-numeric strings in the column because it does not have rigid column types -- it simply has type affinities, which determine what types of coercions may happen -- see https://www.sqlite.org/datatype3.html).
您必须重新创建 table,从正确的列类型开始。