UnifiedSQL Functions TONUMBER and TOCHAR not working (MySQL)

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Elias Zurschmiede
Posts: 10
Joined: Fri 10 Jun 2011 11:17
Contact:

UnifiedSQL Functions TONUMBER and TOCHAR not working (MySQL)

Post by Elias Zurschmiede » Tue 14 Jun 2011 08:04

Hi

The UnifiedSQL Functions TONUMBER and TOCHAR not working with MySQL (UniDac 3.70.0.17 28-Apr-2011)

Here is my workaround in file "MySQLUniProvider.pas" on line 438 and 439. (works only on MySQL >= 5.0, see below)

Code: Select all

// EZ: changed to DECIMAL according to MySQL manual (http://dev.mysql.com/doc/refman/5.1/en/cast-functions.html)
  MyFunctions.AddObject('TONUMBER', TObject(PChar('CAST(%s AS DECIMAL)')));
// EZ: changed to CHAR according to MySQL manual (http://dev.mysql.com/doc/refman/5.1/en/cast-functions.html)
   MyFunctions.AddObject('TOCHAR', TObject(PChar('CAST(%s AS CHAR)')));
DECIMAL may not working for MySQL < 5.0 (http://dev.mysql.com/doc/refman/4.1/en/ ... tions.html). Looks like its not possible to cast to a decimal in MySQL < 5.0. May you can handle that by checking the server version and cast to SIGNED on MySQL < 5.0.


Best regards
Elias Zurschmiede

AndreyZ

Post by AndreyZ » Tue 14 Jun 2011 13:21

Hello,

Thank you for your inquiry. We will investigate this question.

AndreyZ

Post by AndreyZ » Wed 15 Jun 2011 13:09

We've investigated this question. Macros are global objects, and we cannot change them internally according to server versions. But we will make the MyFunctions variable available from your application - this will allow you to change functions easily in the code. Here is an example:

Code: Select all

MyFunctions.Delete(MyFunctions.IndexOf('TONUMBER'));
MyFunctions.AddObject('TONUMBER', TObject(PChar('CAST(%s AS DECIMAL)')));
UniQuery.SQL.Text := 'select {fn TONUMBER(0)}';
UniQuery.Open;

Elias Zurschmiede
Posts: 10
Joined: Fri 10 Jun 2011 11:17
Contact:

Post by Elias Zurschmiede » Wed 28 Sep 2011 11:45

Hi Andrey

Thanks for your reply. I will implement that as you suggested.

Greetings
Elias

Post Reply