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 8770079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:29:12+00:00 2026-06-13T17:29:12+00:00

I got bitten my first sql escaping error (it was long overdue) when I

  • 0

I got bitten my first sql escaping error (it was long overdue) when I tried to execute the PostgreSQL query below with a value containing an apostrophe eg. O'Brien, using FreePascal and Lazarus

SQL.Add(format('select * from zones where upper(zn_name) >=  %s and upper(zn_name) < %s order by zn_name',[sQuote(zoneMin), sQuote(zoneMax)]));

In the query above SQuote is a function that wraps a string in single quotes. Is there some standard library for sanitizing SQL query parameters for Lazarus/FreePascal or Delphi for that matter?

  • 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-06-13T17:29:14+00:00Added an answer on June 13, 2026 at 5:29 pm

    Your application is vulnerable to a serious class of security problems called SQL injection. See http://bobby-tables.com/.

    Sure, O'Brian causes an error, but what about ');DROP SCHEMA public;-- ? Or ');DELETE FROM users;-- ? The 1st shouldn’t work because your app should never run as a superuser or the user that owns the tables, but few application designers make the effort to actually do that and often run privileged users in production. The 2nd will work in most applications; see the end of the post for details.

    The easiest and best preventative measure is to use parameterized statements* in your client library. See this example for Delpi:

    To use a prepared statement, do something like this:
    
    query.SQL.Text := 'update people set name=:Name where id=:ID';
    query.Prepare;
    query.ParamByName( 'Name' ).AsString := name;
    query.ParamByName( 'ID' ).AsInteger := id;
    query.ExecSQL;
    

    (I’ve never used Delphi and last wrote Pascal code in 1995; I’m just quoting the example given).

    What you are doing currently is string interpolation of parameters. It is very dangerous. It can be done safely only if you have a robust function for quoting SQL literals, one that doesn’t just bang quotes on each end, but also handles other escapes, quote doubling, etc. It is the approach of last resort; it’s strongly preferable to use a parameterized statement.


    Here’s an expansion of the example I gave above. Say you’re doing a perfectly ordinary insert of a user by username, where ‘Fred’ is an example username input by the client:

    INSERT INTO users ( user_name ) VALUES ('Fred');
    

    Now some unpleasant person sends the username ');DELETE FROM users;--. Suddenly your application is running:

    INSERT INTO users ( user_name ) VALUES ('');DELETE FROM users;--');
    

    which when expanded is:

    INSERT INTO users ( user_name ) VALUES ('');
    DELETE FROM users;
    --');
    

    or in other words an insert that inserts an empty string (though they could just as easily put a perfectly valid username in), followed by a DELETE FROM users; statement – deleting all rows in users – then a comment that does nothing. Splat. There goes your data.


    * Parameterized statemments are sometimes incorrectly referred to as prepared statements. That’s incorrect because a prepared statement isn’t necessarily parameterized, and a parameterized statement isn’t necessarily prepared. The confusion has arisen because the database interfaces of many languages don’t provide a way to use parameterized statements without also using prepared statements.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got the following error when I tried to compile a C application in 64-bit
Got this error message while trying to load view: The model item passed into
Got that error when trying to push updated app to Heroku (probably the same
A friend of mine got bitten by the all too famous 'anonymous functions in
Got this error while trying to get the variables out of a class. Using
Got an error while running snmptranslate -IR sysSwYear * Expected ( (_): At line
Got a bunch of letter buttons in code below: Code: <?php $a = range(A,Z);
Got a bunch of letter buttons in code below: <?php $a = range(A,Z); ?>
Got this error when parsing my html page using XPATH.. i am also using
Got a LinearLayout containing a textview and an edittext. The LinearLayout is inside a

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.