Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why both "real" and "float" get mapped to "Single" instead of "Double"?

I am using System.Data.SQLite 1.0.90 with VS2013 and EntityFramework 5 in Model-First mode (=EDMX).

I created a new SQLite database containing a table:

CREATE TABLE [..]
  [Test1integer] integer,
  [Test2int] int,
  [Test3smallint] smallint,
  [Test4tinyint] tinyint,
  [Test5bigint] bigint,
  [Test6money] money,
  [Test7float] float,
  [Test8real] real,
  [Test9decimal] decimal,
  [Test10numeric18_5] numeric(18,5), [..]

The relevant parts are Test7float and Test8real.

After having executed Update Model from Database... the EDMX now contains this:

SSDL:

      <Property Name="Test1integer" Type="integer" />
      <Property Name="Test2int" Type="int" />
      <Property Name="Test3smallint" Type="smallint" />
      <Property Name="Test4tinyint" Type="tinyint" />
      <Property Name="Test5bigint" Type="integer" />
      <Property Name="Test6money" Type="decimal" Precision="53" Scale="0" />
      <Property Name="Test7float" Type="real" />
      <Property Name="Test8real" Type="real" />
      <Property Name="Test9decimal" Type="decimal" Precision="53" Scale="0" />
      <Property Name="Test10numeric18_5" Type="decimal" Precision="18" Scale="5" />

The relevant parts are Test7float and Test8real.

CSDL:

      <Property Name="Test1integer" Type="Int64" />
      <Property Name="Test2int" Type="Int32" />
      <Property Name="Test3smallint" Type="Int16" />
      <Property Name="Test4tinyint" Type="Byte" />
      <Property Name="Test5bigint" Type="Int64" />
      <Property Name="Test6money" Type="Decimal" Precision="53" Scale="0" />
      <Property Name="Test7float" Type="Single" />
      <Property Name="Test8real" Type="Single" />
      <Property Name="Test9decimal" Type="Decimal" Precision="53" Scale="0" />
      <Property Name="Test10numeric18_5" Type="Decimal" Precision="18" Scale="5" />

The relevant parts are Test7float and Test8real.

Problem

Test7float wrongly became "real" + "Single" -- and the designer also does not allow "Double" here.

The SQLite3 docs ( http://www.sqlite.org/datatype3.html ) clearly state that "real" is a 8-byte IEEE floating point number and "float" is only a synonym for "real" -- so in every case "Double" (8 byte) should be preferred over "Single" (4 byte).

Am I doing something wrong or did I misunderstand something? If not: Where are things going wrong and how can I fix them?

Should I create a bug report for this?

like image 366
springy76 Avatar asked Jan 08 '14 17:01

springy76


People also ask

What is the difference between decimal and float in SQL Server?

Float stores an approximate value and decimal stores an exact value. In summary, exact values like money should use decimal, and approximate values like scientific measurements should use float. When multiplying a non integer and dividing by that same number, decimals lose precision while floats do not.

What is the data type for float in SQL?

The FLOAT data type is an approximate number with floating point data. FLOAT value is approximate which means not all values can be represented exactly. FLOAT(24) is identical to REAL.

What is the difference between float and numeric in SQL Server?

Float is Approximate-number data type, which means that not all values in the data type range can be represented exactly. Decimal/Numeric is Fixed-Precision data type, which means that all the values in the data type range can be represented exactly with precision and scale.


1 Answers

Looks like a bug in the mapping driver.

The type used to declare a column is only used for affinity (you can declare a column as float and store blobs in it if you want).

When reporting a table structure, SQLite merely returns the SQL definition that was used to create its fields (and alter them, if applicable).

Thus your driver only has access to "float" for the field type, and likely maps it to "single" through some generic code, that may not have been written with SQLite in mind (or overridden for SQLite anyway).

like image 112
Eric Grange Avatar answered Sep 21 '22 14:09

Eric Grange