Solved

ADOQuery and big query

Posted on 2003-10-29
5
679 Views
Last Modified: 2010-04-05
Experts,

I have a SQL query in a AnsiString (because it is more than 255 chars long). How can I pass that query to ADOQuery.SQL ? I can't really use ADOQuery.SQL.Add as the string is to long. I looked at ADOQuery.SQL.SetText but could not get it to work (as i'm **** with pointers).

var
  sBodyInsert, sMessageBody : AnsiString;
begin
  sBodyInsert := 'INSERT INTO BodyText (ID, Size, Body) VALUES (';
  sBodyInsert := sBodyInsert + IntToStr(iBodyID) + ', 0, ';
  sBodyInsert := sBodyInsert + '''' + sMessageBody + ''')';

  with ADOQuery do begin
    SQL.Clear;
    // Here i need to add the SQL from above (in sBodyInsert )
    ExecSQL;
  end;

Cheers,
Marius
0
Comment
Question by:BarCode99
5 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 125 total points
ID: 9641328
Hi,

Try
SQL.Text := sBodyInsert;

Regards, Geo
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9641361
as geo said
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 9641976
Ehm... The Delphi string type isn't limited to 255 characters anymore. And the SQL property of an ADO query is a stringlist, not a string. So Geo is right, again... ;-)

Oh, well, you could also use:
SQL.Clear;
SQL.Add('INSERT INTO BodyText (ID, Size, Body) VALUES (');
SQL.Add(' IntToStr(iBodyID) + ', 0, ');
SQL.Add(''' + sMessageBody + '''');

Which just means you don't need to use a temporary string to build the query...

Btw. What I often do is use a string constant like this:

const sQuery = 'INSERT INTO BodyText (ID, Size, Body) VALUES ('%d, 0, ''%s''';

and then using the Format statement I assign it to the query:

SQL.Text := Format(sQuery, [iBodyID, sMessageBody]);
0
 

Author Comment

by:BarCode99
ID: 9642230
I overcomplicated the f***ing thing. Thanks for putting me straight!

0
 

Expert Comment

by:Kritsadapoj
ID: 9725851
Close;
SQL.Clear;
SQL.Appent(sBodyInsert);
ExecSQL;
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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