Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7521523
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:15:04+00:00 2026-05-30T02:15:04+00:00

We’ve porting code to Delphi XE2, and need to change our data access components

  • 0

We’ve porting code to Delphi XE2, and need to change our data access components from third party ODBCExpress which is no longer in business, to dbExpress’s TSQLQuery.

We have parametrized SQL query such as:

sSQL :=
  'UPDATE ZTestData SET '+
  ' StringField =?, '+
  ' IntField = ?, '+
  ' DecimalField = ?, '+
  ' BooleanField = ?, '+
  ' DateTimeField = ?, '+
  ' TextField = ? '+
  ' WHERE UniqueID = 3';

if we use the following code:

var
  qry:TSQLQuery;
begin
  qry.Close;
  qry.SQL.Text := sSQL;
  ShowMessage(IntToStr(qry.Params.Count));
end;

It returns 0, so we’re unable to get the bindings working, but if we change sSQL to:

sSQL :=
  'UPDATE ZTestData SET '+
  ' StringField =:Param1, '+
  ' IntField = :Param2, '+
  ' DecimalField = ?, '+
  ' BooleanField = ?, '+
  ' DateTimeField = ?, '+
  ' TextField = ? '+
  ' WHERE UniqueID = 3';

It returns 2.

It’s going to be a big hassle to change all the SQL queries to the new parameter syntax. Is there anyway for the TSQLQuery to recognize the ? syntax?

I see that DBXCommon.TDBXCommand uses the ? syntax:

http://www.andreanolanusse.com/en/parameterized-queries-with-dbexpress-dbx-framework/

But it would mean throwing away our code that uses TSQLQuery. What’s the quickest/easiest way to resolve this? What’s the difference between TSQLQuery and TDBXCommand anyway, in terms of what’s relevant to me?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:15:06+00:00Added an answer on May 30, 2026 at 2:15 am

    I ended up writing a method to convert question marks in the query to :param1 style parameters. Interestingly, Delphi has a DB.TParams.ParseSQL method that converts parameters to question marks. This method is basically a reverse of that.

    function THstmt.AddParamsToSQL(const SQL: String): String;
    var
      LiteralChar: Char;
      CurPos, StartPos, BeginPos: PChar;
      ParamCount:Integer;
    begin
      //Locates the question marks in an SQL statement
      //and replaces them with parameters.
      //i.e. the reverse of DB.TParams.ParseSQL
    
      //This method is base on DB.TParams.ParseSQL
    
      //For example, given the SQL string
      //SELECT * FROM EMPLOYEES WHERE (ID = ?) AND (NAME = ?)
    
      //ParseSQL returns the string
      //SELECT * FROM EMPLOYEES WHERE (ID = :1) AND (NAME = :2)
    
      Result := '';
    
      ParamCount := 0;
      StartPos := PChar(SQL);
      BeginPos := StartPos;
      CurPos := StartPos;
      while True do
      begin
        // Fast forward
        while True do
        begin
          case CurPos^ of
            #0, '?', '''', '"', '`':
              Break;
          end;
          Inc(CurPos);
        end;
    
        case CurPos^ of
          #0: // string end
            Break;
          '''', '"', '`': // literal
          begin
            LiteralChar := CurPos^;
            Inc(CurPos);
            // skip literal, escaped literal chars must not be handled because they
            // end the string and start a new string immediately.
            while (CurPos^ <> #0) and (CurPos^ <> LiteralChar) do
              Inc(CurPos);
            if CurPos^ = #0 then
              Break;
            Inc(CurPos);
          end;
          '?': //parameter
          begin
            Inc(CurPos);
            Inc(ParamCount);
            Result := Result + Copy(SQL, StartPos - BeginPos + 1, CurPos - StartPos - 1) + ':' + IntToStr(ParamCount);
            StartPos := CurPos;
          end;
        end;
      end;
      Result := Result + Copy(SQL, StartPos - BeginPos + 1, CurPos - StartPos);
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.