🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.database.ado
Article #1621

Re: Flexible SQL Queries through ADO.

#1621
From: Heinz Ketchup
Date: Wed, 02 Jun 2004 20:36
168 lines
6424 bytes
Whoops:
The Below Statement is wrong
>   QueryOperations->Parameters->ParamBYName("Unit4")->Value = UserDeclared4 = "HY01";

when it should be:

QueryOperations->Parameters->ParamBYName("Unit4")->Value = UserDeclared4;

It was a copy paste mistake into the Post.

Heinz.




"Heinz Ketchup" <heinz_like_the_ketchup@h0tmail.n0spam.c0m.n0spam> wrote:
>
>Hi Mark and Viatcheslav,
>
>Here is my method. It's rather basic, as I was just trying to test your example. So here it is.
>
>
>void TStatus6DatabaseModule::FetchUnitHeatRateDetails(TADOQuery* QueryOperations)
>{
>
>AnsiString FlexibleSQLStatement;
>AnsiString UserDeclared1, UserDeclared2, UserDeclared3, UserDeclared4;
>
>   UserDeclared1 = "GN01";
>   UserDeclared2 = "CB03";
>   UserDeclared3 = "RD09";
>   UserDeclared4 = "HY01";
>
>   QueryOperations->Close();
>   QueryOperations->SQL->Clear();
>
>   FlexibleSQLStatement += "SELECT UNIT, LONGNAME, A, B, C, D ";
>   FlexibleSQLStatement += "FROM emc.allUnits ";
>   FlexibleSQLStatement += "WHERE UNIT = :Unit1 ";
>   FlexibleSQLStatement += "OR UNIT = :Unit2 ";
>   FlexibleSQLStatement += "OR UNIT = :Unit3 ";
>   FlexibleSQLStatement += "OR UNIT = :Unit4 ";
>
>   QueryOperations->Parameters->ParseSQL(FlexibleSQLStatement,true);
>   QueryOperations->Parameters->ParamByName("Unit1")->Value = UserDeclared1;
>   QueryOperations->Parameters->ParamByName("Unit2")->Value = UserDeclared2;
>   QueryOperations->Parameters->ParamByName("Unit3")->Value = UserDeclared3;
>   QueryOperations->Parameters->ParamBYName("Unit4")->Value = UserDeclared4 = "HY01";
>
>   QueryOperations->Open();
>
>}
>
>I hope this helps?
>
>Error Message is:
>Project DataModuleTestingProject.exe raised exception class EOleException with message 'No value give for one or more required parameters'. Process stopped. Use Step or Run to continue.
>
>The error message isn't overly helpful, but I'm assuming that the Variables Unit1, Unit2, Unit3, and Unit4 are not being properly bound?
>
>Thanks for all your help guys.
>
>Heinz
>
>
>
>
>"Mark Guerrieri" <mguerrieri@cmsgrp.com> wrote:
>>Ah yes, I missed that- the column and table names can not be parameters- you
>>need to dynamically add them to your SQL string.
>>
>>Mark
>>
>>"Viatcheslav V. Vassiliev" <support@oledbdirect.com> wrote in message
>>news:40bd7880@newsgroups.borland.com...
>>> SELECT ?, ?
>>>
>>> Most (if not all) DBMS will not allow parameters at this place. Enclose
>>also
>>> column names into quotes - Date is probably keyword. Use TADODataSet and
>>set
>>> CommandText property.
>>>
>>> //------------------------------------------
>>> Regards,
>>> Vassiliev V. V.
>>> http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
>>> ADO.Net
>>> http://www.oledbdirect.com - The fastest way to access MS SQL Server,
>>> MS Jet (Access) and Interbase (through OLEDB)
>>>
>>> "Heinz Ketchup" <heinz_like_the_ketchup@h0tmail.no_spam.c0m.no_spam>
>>> �������/�������� � �������� ���������:
>>> news:40bb4d03$1@newsgroups.borland.com...
>>> >
>>> > Thanks Mark,
>>> >
>>> > The first method works fine for me.
>>> >
>>> > Although I did try your second method, and it didn't seem to work.
>>> > Is there something special that changes in the SQL Query?
>>> >
>>> > i.e.
>>> > C++ Code
>>> > DynamicFlexSQLStmt = "SELECT :Var1, :Var2 ";
>>> > DynamicFlexSQLStmt += "FROM mySQLTable ";
>>> > DynamicFlexSQLStmt += "WHERE Date >= :StartDate ";
>>> > DynamicFlexSQLStmt += "AND Date <= :EndDate ";
>>> >
>>> > TADOQuery1->Parameters->ParseSQL(DynamicFlexSQLStmt, true);
>>> > TADOQuery1->Parameters->ParamByName("Var1")->Value = "Date";
>>> > etc...
>>> >
>>> > Debugging the DynamicFlexSQLStmt
>>> > DynamicFlexSQLStmt = "SELECT ?, ? FROM mySQLTable WHERE Date >= ? AND
>>Date
>>> <= ?"
>>> > It starts when the ParseSQL statement command is executed,
>>> > and remains that way after all the ParamByName statements are called
>>> >
>>> > I get an error "No Value given for one or more required Parameters"
>>> >
>>> > Any thoughts?
>>> > And THANKS A LOT for the your reply!
>>> > You've helped a whole heaps load!
>>> >
>>> > Heinz.
>>> >
>>> >
>>> >
>>> > "Mark Guerrieri" <markg11@comcast.net> wrote:
>>> > >>
>>> > >> AnsiString DynamicFlexSQLStmt = "SELECT Date " + ""... (Whatever I
>>add
>>> for
>>> > >Column Selections)
>>> > >>
>>> > >> I cannont use TADOQuery1->SQL->Add(":MyFlexibleSQLStmt");
>>> > >> TADOQuery1->SQL->Parameters->ParamByName("MyFlexibleSQLStmt")->Value
>>=
>>> > >DynamicFlexSQLStmt;
>>> > >>
>>> > >
>>> > >Try this-
>>> > >
>>> > >AnsiString DynamicFlexSQLStmt = "SELECT Date " + ""... (Whatever I add
>>> for
>>> > >Column Selections)
>>> > >TADOQuery1->SQL->Text = DynamicFlexSQLStmt;
>>> > >
>>> > >I do this all the time and it works fine.  I don't bother with
>>> parameters,
>>> > >I just build the values right into the SQL statement.  If you need
>>> > >parameters, add this:
>>> > >
>>> > >TADOQuery1->Parameters->ParseSQL(DynamicFlexSQLStmt, true);
>>> > >TADOQuery1->Parameters->ParamByName("ParamName")->Value = ParamValue;
>>> > >
>>> > >Mark
>>> > >
>>> > >
>>> >
>>>
>>>
>>
>>
>
Technical Details
Message-ID: <40be3a4f$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <40ba50b3$1@newsgroups.borland.com> <40baa32b$1@newsgroups.borland.com> <40bb4d03$1@newsgroups.borland.com> <40bd7880@newsgroups.borland.com> <40be1ca0$1@newsgroups.borland.com> <40be3902$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 10698b,88aab88ffc95b09
X-Google-Attributes: gid10698b,public
From: "Heinz Ketchup" <heinz_like_the_ketchup@h0tmail.n0spam.c0m.n0spam>
Sender: "Heinz Ketchup" <heinz_like_the_ketchup@h0tmail.n0spam.c0m.n0spam>
Reply-To: "Heinz Ketchup" <heinz_like_the_ketchup@h0tmail.n0spam.c0m.n0spam>
Subject: Re: Flexible SQL Queries through ADO.
Newsgroups: borland.public.cppbuilder.database.ado
X-User-Info: 146.131.120.2     
References: <40ba50b3$1@newsgroups.borland.com> <40baa32b$1@newsgroups.borland.com> <40bb4d03$1@newsgroups.borland.com> <40bd7880@newsgroups.borland.com> <40be1ca0$1@newsgroups.borland.com> <40be3902$1@newsgroups.borland.com>
NNTP-Posting-Host: 207.105.83.66
Message-ID: <40be3a4f$1@newsgroups.borland.com>
Date: 2 Jun 2004 13:36:31 -0700
X-Trace: newsgroups.borland.com 1086208591 207.105.83.66 (2 Jun 2004 13:36:31 -0700)
Lines: 169
Path: arc1-ca.pugleaf.net!controlnews3.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail