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

The Archive Base Latest Questions

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

I need to protect an application from SQL injection. Application is connecting to Oracle,

  • 0

I need to protect an application from SQL injection. Application is connecting to Oracle, using ADO, and search for the username and password to make the authentication.

From what I’ve read until now, the best approach is by using parameters, not assigning the entire SQL as string. Something like this:

query.SQL.Text := 'select * from table_name where name=:Name and id=:ID'; 
query.Prepare; 
query.ParamByName( 'Name' ).AsString := name; 
query.ParamByName( 'ID' ).AsInteger := id; 
query.Open;

Also, I’m thinking to verify the input from user, and to delete SQL keywords like delete,insert,select,etc…Any input character different than normal ASCII letters and numbers will be deleted.

This will assure me a minimum of security level?

I do not want to use any other components than Delphi 7 standard and Jedi.

  • 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-22T02:51:16+00:00Added an answer on May 22, 2026 at 2:51 am

    Safe

    query.SQL.Text := 'select * from table_name where name=:Name';
    

    This code is safe because you are using parameters.
    Parameters are always safe from SQL-injection.

    Unsafe

    var Username: string;
    ...
    query.SQL.Text := 'select * from table_name where name='+ UserName;
    

    Is unsafe because Username could be name; Drop table_name;
    Resulting in the following query being executed.

    select * from table_name where name=name; Drop table_name;
    

    Also Unsafe

    var Username: string;
    ...
    query.SQL.Text := 'select * from table_name where name='''+ UserName+'''';
    

    Because it if username is ' or (1=1); Drop Table_name; --
    It will result in the following query:

    select * from table_name where name='' or (1=1); Drop Table_name; -- '
    

    But this code is safe

    var id: integer;
    ...
    query.SQL.Text := 'select * from table_name where id='+IntToStr(id);
    

    Because IntToStr() will only accept integers so no SQL code can be injected into the query string this way, only numbers (which is exactly what you want and thus allowed)

    But I want to do stuff that can’t be done with parameters

    Parameters can only be used for values. They cannot replace field names or table names.
    So if you want to execute this query

    query:= 'SELECT * FROM :dynamic_table '; {doesn't work}
    query:= 'SELECT * FROM '+tableName;      {works, but is unsafe}
    

    The first query fails because you cannot use parameters for table or field names.
    The second query is unsafe but is the only way this this can be done.
    How to you stay safe?

    You have to check the string tablename against a list of approved names.

    Const
      ApprovedTables: array[0..1] of string = ('table1','table2');
    
    procedure DoQuery(tablename: string);
    var
      i: integer;
      Approved: boolean;
      query: string;
    begin
      Approved:= false;
      for i:= lo(ApprovedTables) to hi(ApprovedTables) do begin
        Approved:= Approved or (lowercase(tablename) = ApprovedTables[i]);
      end; {for i}
      if not Approved then exit;
      query:= 'SELECT * FROM '+tablename;
      ...
    

    That’s the only way to do this, that I know of.

    BTW Your original code has an error:

    query.SQL.Text := 'select * from table_name where name=:Name where id=:ID'; 
    

    Should be

    query.SQL.Text := 'select * from table_name where name=:Name and id=:ID'; 
    

    You cannot have two where‘s in one (sub)query

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

Sidebar

Related Questions

I am generating a reports using SQL Reporting services 2005. I need to protect
I have a rather large database exposed to my application using LINQ-to-SQL. I need
I've been looking at how best to protect against sql injection in PHP/mysql beyond
I need to profile a java application for a customer. It's an eclipse/maven project,
I'm working on a new project, a web application, where I need to focus
The Junits I have in my project need to load property files from the
We currently use SQL Server 2005 Enterprise for our fairly large application, that has
I have developed an application as my college project using Visual Studio 2005 and
I need to step through and debug an assembly uploaded to SQL Server. The
I need to create an application that does the following: The application is going

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.