🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Flexible SQL Queries through ADO.

#1266
From: Nigel
Date: Tue, 07 Sep 2004 15:33
108 lines
3938 bytes
I create a StringList to do this

Try the following command

TSringList *sql = new TSringList;
sql->Add("SELECT * FROM table");
sql->Add("WHERE field = whatever");
ADOQuery->SQL->Assign(sql);
delete sql;

Maybe this help Nigel

"Heinz Ketchup" <heinz_like_the_ketchup@h0tmail.no_spam_.c0m.no_spam> wrote
in message news:40ba50b3$1@newsgroups.borland.com...
>
> Hi,
>
> Is there a clever way of designing a flexible SQL Statement through ADO?
>
> I have a database that is in the shape of the following
> Column 1: Date
> Column 2: DataWhateverColumn1
> Column 3: DataWhateverColumn2
> Column 4: DataWhateverColumn3
> Column 5: DataWhateverColumn4
> Column 6: DataWhateverColumn5
> etc...
> Up to 30
>
> <To Break Things Down Simplistically>
> I'm using a TDataModule.
> I Have a TADOQuery Associated with a TDatasource.
>
> The SQL Statement TString in the TADOQuery is:
> Select *
> From mySQLTableData
> Where Date>=:InputStartDate and Date<=:InputEndDate
>
> The corresponding TParameter(s) are
> InputStartDate
> InputEndDate
>
> My problem comes in where:
> 1. I need only certain data columns ("X" Combinations)
>
> So my SQL Query could look like
> Select Date, DataWhateverColumn1
> From mySQLTableData
> Where Date>=:InputStartDate and Date<=:InputEndDate
>
> or
> Select Date, DataWhateverColumn2
> From mySQLTableData
> Where Date>=:InputStartDate and Date<=:InputEndDate
>
> or
> Select Date, DataWhateverColumn1, DataWhateverColumn2
> From mySQLTableData
> Where Date>=:InputStartDate and Date<=:InputEndDate
>
> I Use the Following Method:
>
> TADOQuery1->Close();
> TADOQuery1->SQL->Clear();
>
> TADOQuery1->SQL->ADD("Select Date, DataWhateverColumn1 ")
> TADOQuery1->SQL->ADD("From mySQLTableData ");
> TADOQuery1->SQL->ADD("Where Date>=:InputStartDate ");
> TADOQuery1->SQL->ADD("and Date<=:InputEndDate ");
>
> TADOQuery1->SQL->Parameters->ParamByName("InputStartDate")->Value =
HappyStartDate;
> TADOQuery1->SQL->Parameters->ParamByName("InputEndDate")->Value =
HappyEndDate;
>
> TADOQuery1->Open();
>
> Unfortunately, I discovered that it is not possible to design a flexible
SELECT statement.
>
> AnsiString DynamicFlexSQLStmt = "SELECT Date " + ""... (Whatever I add for
Column Selections)
>
> I cannont use TADOQuery1->SQL->Add(":MyFlexibleSQLStmt");
> TADOQuery1->SQL->Parameters->ParamByName("MyFlexibleSQLStmt")->Value =
DynamicFlexSQLStmt;
>
> There must be a way where I can dynamically bind a SQL SELECT Statement to
an ADOQuery? Shouldn't there be one? Other than the SQL->ADD() method which
is rather limited.
>
> Is there something even more advanced that I should do?
>
> The alternative is a frightenly large set of switch statements.
> case whatever:
>    SQL->Add("Select This")
> next case:
>    SQL->Add("Select That")
> next case:
>    SQL->ADD("Select This, That")
> ... more combinations
>
> But being a programmer... it's obvious that there's a better way, but I
just don't know what it is yet.
>
>
> Thanks,
> Heinz.
Technical Details
Message-ID: <413dd3f2@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.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>

Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,88aab88ffc95b09
X-Google-Attributes: gid10698b,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Nigel" <nhussey@gltame.com>
Newsgroups: borland.public.cppbuilder.database.ado
References: <40ba50b3$1@newsgroups.borland.com>
Subject: Re: Flexible SQL Queries through ADO.
Date: Tue, 7 Sep 2004 17:33:54 +0200
Lines: 110
Organization: Grinaker - LTA
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1437
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441
NNTP-Posting-Host: 196.38.60.194
Message-ID: <413dd3f2@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1094570994 196.38.60.194 (7 Sep 2004 08:29:54 -0700)
Path: arc1-ca.pugleaf.net!g2news1.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