Solved

ADOQuery and big query

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

729 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