Solved

ADOQuery and big query

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now