Subsonic + Sqlite + Float 数据类型==“无法保存:xxx 超过最大长度 8" [英] Subsonic + Sqlite + Float datatype == "Can't save: xxx exceeds the maximum length of 8"

查看:22
本文介绍了Subsonic + Sqlite + Float 数据类型==“无法保存:xxx 超过最大长度 8"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Subsonic 2.2 构建数据加载器实用程序应用程序(Win 7 64 位、VS 2008、C#、.Net 3.5、Win Forms).
我已经使用 SqlServer 完成了所有工作,现在我需要让它在 Sqlite 3 中工作.我已经解决了一些问题,但有一个我无法解决;
我有 2 列,纬度和经度,它们是 sqlite 中的 FLOAT 数据类型,而 Subsonic 生成为可为空的浮点数.代码生成很好,构建也很好,但是当我尝试运行应用程序时,当对象被保存时,我收到错误消息,无法保存:经度超过 8 的最大长度."
我的猜测是,这是 Subsonic 中的验证问题,因为我的 Sqlite 数据库现在出现了我加载到这些列中的数据的问题.
任何 Subsonic 或 Sqlite 老手都有任何建议,我是 Subsonic 的新手,现在只使用 Sqlite 大约 6 个月.

I'm building a data loader utility application (Win 7 64bit, VS 2008, C#, .Net 3.5, Win Forms) using Subsonic 2.2.
I've gotten everything working using SqlServer and now I need to get it working in Sqlite 3. I've worked through some issues but there is one I cannot resolve;
I have 2 columns, Latitude and Longitude that are FLOAT data types in sqlite and Subsonic generates as nullable floats. The code generation is fine, building is fine but when I attempt to run the application, when the object gets saved I get en error, "Can't save: Longitude exceeds the maximum length of 8."
My guess is that it's a verification issue in Subsonic as my Sqlite db has now issue with the data I have been loading into those columns.
Any Subsonic or Sqlite veterans out there have any suggestions, I am brand new to Subsonic and have only been working with Sqlite for about 6 months now.

谢谢,杰夫

导致错误的值是 -122.41082,超过 8 个字符,但我认为这不是 sqlite 中浮点数的限制.也许我在数据类型方面选择不当?

The value that is causing the error is -122.41082 which is over 8 chars but I don't think that's the limit for a float in sqlite. Maybe I'm choosing poorly when it comes to data types?

推荐答案

这是一个 SQLite 问题,据我了解,SQLite 没有类型"的概念——只有对值的推断:

This is a SQLite issue as, from what I understand, SQLite doesn't have a concept of "types" - only inferences on values:

http://www.sqlite.org/faq.html#q3如何更改 sqlite 列 (iPhone)?

我在这里猜测的是,浮点翻译的推论正在丢失 - 如果您阅读文档,它会说明很多:

What I'm guessing here is that the inference is getting lost on the float translation - if you read up the docs, it says as much:

具有 NUMERIC 亲和性的列可能包含使用所有五个存储的值类.插入文本数据时进入 NUMERIC 列,尝试是将其转换为整数或存储之前的实数.如果转换成功(意思是转换发生时没有信息丢失),然后值使用整数或实数存储存储类.如果转换不能在没有损失的情况下进行信息然后存储值使用 TEXT 存储类

A column with NUMERIC affinity may contain values using all five storage classes. When text data is inserted into a NUMERIC column, an attempt is made to convert it to an integer or real number before it is stored. If the conversion is successful (meaning that the conversion occurs without loss of information), then the value is stored using the INTEGER or REAL storage class. If the conversion cannot be performed without loss of information then the value is stored using the TEXT storage class

所以看起来您传入的值无法存储为 REAL(出于某种原因),并且正在尝试将其调整为 TEXT,长度限制为 8.这也是有道理的,因为它正在计算小数位 - 它不应该(只有在它是文本时才会).

So it looks like the value you're passing in is NOT able to be stored as REAL (for some reason) and is trying to be tweaked to TEXT, with the limitation of a length of 8. This makes sense also because it's counting the decimal place - and it shouldn't (it only would if it's text).

在这里阅读:http://www.sqlite.org/datatype3.html#affinity

看起来这就是您要处理的问题.总而言之,SQLite 是一个ducktyped"数据库,很多人都被它咬过.

It looks like this is the issue you're dealing with. All in all, SQLite is a "ducktyped" database, and many people have been bitten by it.

所以,简而言之,我认为您的答案可能是使用 Math.Round(3) 将值带入 8 个总数 + 小数(和负号)以下,以便将其强制放入列中.

So, in short, I think your answer is probably to use Math.Round(3) to bring the value in under 8 total numbers + decimal (and the negative symbol) so it can be coerced into the column.

这篇关于Subsonic + Sqlite + Float 数据类型==“无法保存:xxx 超过最大长度 8"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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