Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL Statement Problem

Posted on 2006-11-02
12
Medium Priority
?
178 Views
Last Modified: 2010-04-05
hi all
  i am working on delphi7 and backend oracle 8i.
the problem which i am facing is that how to get the query which has been written in SQL.ADD() statement.
eg:
SQL.Add('Insert Into table1 (a,b,c) Values(:a,:b,:c)');
Parambyname('a').ASString := 'XYZ';
Parambyname('b').ASString := 'ABC';
Parambyname('b').ASString := 'DEF';

i wrote statement
   Str := SQL.GetText;
It returned
'Insert Into table1 (a,b,c) Values(:a,:b,:c)'
now what i want is instead of (:a,:b,:c) i want the actual values i.e

'Insert Into table1 (a,b,c) Values('XYZ','ABC','DEF')'

i hope the question is understood.
thank you

0
Comment
Question by:Asmitagoyal
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 9

Expert Comment

by:sun4sunday
ID: 17864717
if you can pass it with out parameters you can do it in other way

var
sqlstring : String;
begin
sqlstring := 'Insert Into table1 (a,b,c) Values (' +''''+ edit2.Text+'''' + ', '+''''+ edit2.Text+  ')' +'''' ;
SHowmessage(sqlstring);

QuotedStr function can use for the quotes

sun4sunday
0
 
LVL 3

Expert Comment

by:jpedef
ID: 17864774
Maybe after Query.Prepared := true; sql shows correct sql.
0
 

Author Comment

by:Asmitagoyal
ID: 17864860
hi
i had thought of the above but the problem is that the count of fields in the tables is very large .
Is there any other solution apart from this .......
and
Query.prepared := true    did not work

thank you
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 17864976
I'm interested too.
I haven't found how to do this, but I could make use of it too.

0
 
LVL 14

Accepted Solution

by:
Pierre Cornelius earned 750 total points
ID: 17866847
Try this:

function GetSQLWithParamValues(SQL: string; Params: TParams):string;
var i,p: integer;
begin
  for i:= 0 to Params.Count-1 do
  begin
    p:= pos(':'+Params[i].Name, sql);
    while p <> 0 do
    begin
      Delete(sql, p, Length(Params[i].name)+1);
      Insert(Params[i].AsString, sql, p);
      p:= pos(':'+Params[i].Name, sql);
    end;
  end;
  result:= sql;
end;


usage example:
==========
ShowMessage(GetSQLWithParamValues(Query1.SQL.Text, Query1.Params));


Regards
Pierre
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 17867283
Hm,

Reading PierreC's comment, I made another function which does basically the same, but only needs a TADOQUery as parameter:

function GetSQLWithParamValues(qry: TADOQuery): String;
var
  i: Integer;
  sTmp: String;
begin
  sTmp := qry.SQL.Text;
  for i:=0 to qry.Parameters.Count-1 do
  begin
    sTmp := StringReplace( sTmp, ':'+qry.Parameters[i].Name, qry.Parameters[i].Value, [] );
  end;
  Result := sTmp;
end;


The function just replaces the parameter-name by its parameter-value.
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 17872536
I would have used the rfReplaceAll flag in the StringReplace function.

The reason I used the SQL and params as parameters is to make the function dataset independant e.g. TADOQuery, TQuery, TZQuery, etc.
0
 
LVL 6

Expert Comment

by:wimmeyvaert
ID: 17879353
Hi PierreC,

You have a point about not using a TADOQuery as a parameter.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 17879881
1. first add params then set SQL Command property
2. You will not get SQL command with params replaced by actual values from ADO components reason is very simple, what if params point to BLOB values how wuld You like it to bo parsed into SQL command?

ziolko.
0
 

Author Comment

by:Asmitagoyal
ID: 17880141
hi PierreC

thank you ..
your code is working fine.
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 17883161
glad to help, but why a B grade?
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 17883197
a quote from the help files:

Grading at Experts Exchange is not like school. It's more like the "10-point Must" system in professional boxing; in other words, an answer is worth an A, unless it doesn't resolve your issue. If it requires you to do a little more research, or figure out one more piece of code, then it's worth a B. If you think it's not worth a B, the custom is to offer the Experts an opportunity to earn a better grade.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question