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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:57:04+00:00 2026-06-17T18:57:04+00:00

I have to prepare strings to be suitable for queries because these strings will

  • 0

I have to prepare strings to be suitable for queries because these strings will be used in the queries as field values. if they contain a ‘ etc the sql query fails to execute.

I therefore want to replace ‘ with ” I have seen the code to find and replace a substring with a substring. but I guess the problem is a little tricky because replacing string also contains two single quotes ” replacing one quote ‘ so when I have to find the next occurance it would encounter a ‘ which was intentionally replaced.

I am using Sql lite C api and the example query might look like this

 select * from persons where name  = 'John' D'oe'

Since John Doe contain a ‘ the query will fail , so I want all occurances of ‘ in the name to replaced with ”

Any ideas how you guys prepares your field values in query to be used in sql ??? may be it’s a basic thing but I am not too smart in C/C++.

your help would be very helpful

  • 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-17T18:57:05+00:00Added an answer on June 17, 2026 at 6:57 pm

    Use queries with arguments instead of replacing stuff, which could lead to several problems (like SQL injection vulnerabilities).

    MySQL example:

    sql::Connection *con = ...;
    string query = "SELECT * FROM TABLE WHERE ID = ?";
    sql::PreparedStatement *prep_stmt = con->prepareStatement(query);
    prep_stmt->setInt(1, 1); // Replace first argument with 1
    prep_stmt->execute();
    

    This will execute SELECT * FROM TABLE WHERE ID = 1.

    EDIT: more info for SQLite prepared statements here and here.

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

Sidebar

Related Questions

I have this function to prepare variable to be used in a SQL query:
I have the following code: <? $query =$db->prepare(INSERT INTO a_table (id, a_field) VALUES ('',
I'm trying how best to prepare my SQLite SQL strings in PHP. The SQLite3
Have a working SQL statement: my $q_it = $dbh->prepare(SELECT customdata.Field_ID, customdata.Record_ID, customdata.StringValue FROM customdata
I have to prepare a report which is getting some fields data from conf
I have a C++ code and now I am thinking to prepare a UI
In Symfony 2 I have the following code in my Controller: // prepare to
I have this query and I have an error: images = Image.find_by_sql('PREPARE stmt FROM
Does anyone know how to prepare data to plot a CDF (I have a
I have this code, but i cant make it work: images = Image.find_by_sql('PREPARE stmt

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.