Hello,
I'm trying to make an application work with MySql. It
is written in Delphi and uses Delphi's ADO classes to
communicate with databases (e.g. Oracle or MS SQL
server). The problem is that I cannot move to a
dataset which contains empty (NULL) fields. Another
problem is a SELECT statement returning a floating
point calculation as a column.
In MySql I created the following table as an example:
CREATE TABLE TESTTABLE(ICOL Integer, CCOL VARCHAR
(10), FCOL DOUBLE);
INSERT INTO TESTTABLE VALUES(1, 'XYZ', 2.5);
INSERT INTO TESTTABLE VALUES(2, 'ZYX', 5.0);
INSERT INTO TESTTABLE VALUES(3, NULL, 7.5);
INSERT INTO TESTTABLE VALUES(4, '', 10.0);
mysql> desc TESTTABLE;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| ICOL | int(11) | YES | | NULL | |
| CCOL | varchar(10) | YES | | NULL | |
| FCOL | double | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> select * from testtable;
+------+------+------+
| ICOL | CCOL | FCOL |
+------+------+------+
| 1 | XYZ | 2.5 |
| 2 | ZYX | 5 |
| 3 | NULL | 7.5 |
| 4 | NULL | 10 |
+------+------+------+
4 rows in set (0.00 sec)
First problem:
I created a TADOQuery object using the following SQL
statement:
"SELECT ICOL, CCOL FROM TESTTABLE ORDER BY ICOL ASC"
I opened the query, read the two columns and
continued with "query.next" until "query.eof". When
reaching the third dataset, the "next" method threw
an exception something like "A column in which NULL
is not allowed cannot be actualized to NULL" (the
original message was in German).
Second problem:
I created another TADOQuery using:
"SELECT ICOL, 1.3 * ICOL FROM TESTTABLE ORDER BY ICOL
DESC"
When I tried to read "query.Fields[1].AsFloat", I got
an error message like "'5.2' is not a valid floating
point value" (with ',' as decimal separator, typical
German setting). As 4 * 1.3 yields 5.2, the database
returned the correct value, but it could not be
interpreted by the interface.