0
votes

I am working on a big project with a lot of forms using BDE and ODBC to connect to MySQL Database.

I can compile it in Delphi 2009 and it works fine. When i compile it in Delphi 2010, nothing works because TQuery can not pass parameter values correctly.

Here is an example :

txtUsername.Text = 'Admin';
Query1.Close;
Query1.SQL.Text = 'Select Count(*) From Tbl_User where Username = :username';
Query1.ParamByName('username').AsString = txtUsername.Text;
Query.Open();

The SQL will be sent to MySQL , looks like this :

Select Count(*) From Tbl_User where Username = 'A'

Only first character of parameter will be sent to the server : 'A' instead of 'Admin'

But if i use

Query1.ParamByName('username').AsAnsiString , then 

it will works fine and parameter will be sent completely:

Select Count(*) From Tbl_User where Username = 'Admin'

There are huge number of TQuery and TTable in project and its not possible to change all calls of AsString to AsAnsiString.

Is there any solution for this? any settings to make it working fine? probably by making it to use Ansi as default instead of Unicode?

I tried finding some setting in compiling option, and changing ODBC parameters but none of them worked.

Any help would be appreciated. Thanks

1
"its not possible to change all calls of AsString to AsAnsiString." Of course it is, if you have the source of your project.MartynA
Sorry for OT, but maybe this is the moment to get rid of the outdated BDE. I know it's a lot of work.bummi
i have the source, but its not affordable , its time consuming and costly and my client wouldn't go for that.there are more than 200 forms and thousands lines of code. On the other hand Sending string parameters is not the only issue. There are many similar issues with string as well.QProgrammer
Ironically, it does work in Delphi XE3!!!! so it could be a Delphi 2010 bug or maybe an update is missing or something.QProgrammer
"but its not affordable": Not sure what you mean if, as you say, you already have the source. In any case, you could always consider copying DB.Pas to your project directory and hack that, though personally I'd rather eat nails.MartynA

1 Answers

0
votes

I understand the pressure for quick and cheap solutions, but sometimes they will be quick and cheap only at the first moment, and then will turn (in a near future) into a monster problem with no solution at all.

So, for the first move, I recomend you to read a post on Regex Replace. Use this to replace all your .AsString by .AsAnsiString and quickly get you application running as expected again.

But don´t get too comfortable with this, you have a long term work ahead of you. My suggestion to give your application a better design is:

  1. Remove your datasets from your forms and put them in a DataModule, so you will not mix persistence and business code with presentation code;
  2. Stop working with specific dataset on your business code, go for TClientDataset, which is better than any other dataset and will give you a better application design and complete database and middleware independence;
  3. Create a new database layer, putting all the database and middleware specifics behind an interface, what will give you a incredible level of database abstraction.

This is a time consuming work, of course, so, not a quick and certainly not a cheap solution, but it will give you a lot of insights and improve your techniques. During the process, your application will evolve as never before.