I got problem with count

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
anwar5218

I got problem with count

Post by anwar5218 » Sat 18 Jun 2005 11:09

I use this query statement in myQuery component.

"select Id, count(Id) as TotItem from atable"

The result is, If atable contains record, TotItems become LargeInt,
but if atable contains no record, totitems become integer,

Please help.
Thanks

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Tue 21 Jun 2005 11:09

It is MySQL server behaviour. If you would like to get TotItems always as LargeInt you need in the text of the query execute explicit conversion to this type.

w0wbagger
Posts: 7
Joined: Wed 24 Aug 2005 20:23

How, exactly?

Post by w0wbagger » Wed 24 Aug 2005 20:25

Hi Ikar, can you please tell me what the SQL would look like to convert an Integer into a BigInt? From what I can tell, I can't use cast() to do this.

Thanks.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Thu 25 Aug 2005 11:09

Try to ask this question at MySQL AB forums.

Tom

Post by Tom » Wed 21 Sep 2005 19:22

I do have the same problem. Depending on the MySQL Server version that is used, I sometimes get the error that integer was found but a LargeInt was required.

Since I did not find any answer in an MySQL forum, I ask it here again, so maybe someone has a workaround.

I don't think this problem is only due to the MySQL server version. When I used in former times the Zeos Library, this error did not occur.

Well, maybe someone has a tip to deal this problem.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Thu 22 Sep 2005 07:21

Why can't you use "cast"?

Tom

Post by Tom » Thu 22 Sep 2005 09:41

Cast doesn't seem to work when trying to convert a largeint into an integer, unfortunately. At least, I did't find a way.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Thu 22 Sep 2005 15:04

Always try to convert value to largeint

Tom

Post by Tom » Thu 22 Sep 2005 17:00

Cast can only convert to
-signed
-unsigned
-date
-char
-binary

Thats all. Signed is the only int type, but delivers me also a LargeInt, depending on the MySQL version in Delphi. Char works, but I can't calculate with chars. I need an integer.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Fri 23 Sep 2005 07:43

You can try one of following:
- Convert it to char. In your Delphi application use TField.AsInteger.
- Do not create fields at design-time (preferable).

Tom

Post by Tom » Fri 23 Sep 2005 10:54

Ikar wrote:- Convert it to char. In your Delphi application use TField.AsInteger.
That was my first idea too, but Delphi does not allow to cast a TStringField with AsInteger.
Ikar wrote:- Do not create fields at design-time (preferable).
Well, I have to, because I use Calculated fields in Delphi. Once you add a calculted field, you can only access the data fields if you add them in the fieldseditor.

I think I need to work with the char. But this is very unlucky.

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Mon 26 Sep 2005 11:27

> but Delphi does not allow to cast a TStringField with AsInteger

It does, please check it again.

Post Reply