Question

DISCLAIMER: This is legacy code and I simply can't rewrite everything (trust me, I would like to).

I'm trying to execute a legacy Delphi app which uses BDE and DB2, but I simply can't run parametrized querys.

QueryA.SQL.Text := 'select count (*) from syscat.tables where tabname = ''Foo''';
QueryA.Open; // works as expected

QueryB.SQL.Text := 'select count (*) from syscat.tables where tabname = :name';
QueryB.ParamByName('name').ParamType := ptInput;
QueryB.ParamByName('name').DataType := ftString;
QueryB.ParamByName('name').AsString := 'Foo';
QueryB.Open; // Error: "Operation not applicable"

QueryC.SQL.Text := 'select count (*) from syscat.tables where tabname = :name';
QueryC.ParamByName('name').ParamType := ptInput;
QueryC.ParamByName('name').DataType := ftString;
QueryC.ParamByName('name').Clear;
QueryC.Open; // Surprisingly, no erros here

Now... Why the QueryB sample doesn't work? I've tryed just about anything I could imagine: using Value instead of AsString, calling Prepare and UnPrepare, but nothing seems to work. Any ideas?

IMPORTANT: I'm conecting directly via BDE and not using BDE -> ODBC -> DB2 approach.

EDIT: Environment information:

Delphi Version: 5, UpdatePack 1
BDE: 5.01
OS: Windows 7 SP1, x64

D:\SQLLIB\BIN>db2level
DB21085I  Instance "DB2" uses "32" bits and DB2 code release "SQL09052" with
level identifier "03030107".
Informational tokens are "DB2 v9.5.201.346", "s080911", "WR21421", and Fix Pack "2a".
Product is installed at "D:\SQLLIB" with DB2 Copy Name "DB2COPY1".
Was it helpful?

Solution 4

Well, looks like there's no solution for this issue. As pointer by @TOndrej and @DavidG, this QC issue was never solved an no one seems to know how to work around it.

In my case, I will give up and inform my superiors that we can't support DB2 anymore unless we rewrite the application. Anyhow, thanks to everyone that tried to help me.

OTHER TIPS

There is a defect report http://qc.embarcadero.com/wc/qcmain.aspx?d=12905 for Delphi 7 that seems almost the same. My only thought is what happens if you replace the :name with a question mark."?" In db2 Java parameters use a ? You will need to use the parameters as a position

I would try to inspect and or replace the Params using TQuery.Params . For example, you can call TQuery.Params.Clear to remove all of the parameters, and then call TQuery.Params.CreateParam to create a parameter and see whether that works, and what kind of message you get. Or, you can use the automatic parameter creation, as you are, and check the properties of the TQuery.Params.Items

Also, to help sort this out, you might try replacing the count(*) with just * or the name of one of the fields to see if that is part of the problem.

Not used the BDE, but with ADO queries the parameter type information should be filled in by the database. This only occurs if the connection string has been set though (either directly or by a TADOConnection object). Try removing the ParamType and DataType calls and ensure that the connection has been set.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top