Page 1 of 1

I got problem with count

Posted: Sat 18 Jun 2005 11:09
by anwar5218
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

Posted: Tue 21 Jun 2005 11:09
by Ikar
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.

How, exactly?

Posted: Wed 24 Aug 2005 20:25
by w0wbagger
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.

Posted: Thu 25 Aug 2005 11:09
by Ikar
Try to ask this question at MySQL AB forums.

Posted: Wed 21 Sep 2005 19:22
by Tom
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.

Posted: Thu 22 Sep 2005 07:21
by Ikar
Why can't you use "cast"?

Posted: Thu 22 Sep 2005 09:41
by Tom
Cast doesn't seem to work when trying to convert a largeint into an integer, unfortunately. At least, I did't find a way.

Posted: Thu 22 Sep 2005 15:04
by Ikar
Always try to convert value to largeint

Posted: Thu 22 Sep 2005 17:00
by Tom
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.

Posted: Fri 23 Sep 2005 07:43
by Ikar
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).

Posted: Fri 23 Sep 2005 10:54
by Tom
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.

Posted: Mon 26 Sep 2005 11:27
by Ikar
> but Delphi does not allow to cast a TStringField with AsInteger

It does, please check it again.