0

I created the following table:

CREATE TABLE test (a INT,b INT);

After I inserted some data:

INSERT INTO test VALUES(1,2);

When I execute this SELECT:

SELECT cast(b as real) as x, a * b as y FROM teste

the fields "x" and "y" return with datatype TEXT. I'm using Delphi and SQLiteStudio 2.1.5, and both return the same datatype.

I need that field x being real and y being int.

Someone could help me?

ekostadinov
  • 6,880
  • 3
  • 29
  • 47
MarceloSouza
  • 429
  • 5
  • 10
  • 1
    Unlike other databases, in Sqlite, column types are "recommendations". Delphi comes with a range of functions for converting text representations of numbers into numbers (see e.g. IntToStr, etc in the OLH) and back again, so this quirk of Sqlite shouldn't really restrict what you can do in your Delphi code. – MartynA Sep 02 '14 at 12:34
  • 1
    [Works for me](http://www.sqlfiddle.com/#!5/261a8/1). How do you determine the data type? – CL. Sep 02 '14 at 12:48

2 Answers2

0

For me it's strange that in Sqlite, column types are "recommendations". But analyzing this I changed my program. I created the fields manually with correct type. So the program start to work.

The problem is when you open a query and the Delphi create the columns automatically. In this case, the columns with cast or with mathematical operation are created like text field.

MarceloSouza
  • 429
  • 5
  • 10
0

Sqlite does not have column data type. It is just text. Based on your expression, it will try to do the conversion for you. For your math expression, you need to do a cast to give it is a hint to delphi to create your desired column type.