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
Solved

ADOQuery and big query

Posted on 2003-10-29
5
680 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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