Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ADOQuery and big query

Posted on 2003-10-29
5
Medium Priority
?
710 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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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 course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

610 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