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

  • SEARCH
  • Home
  • 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 6627893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:04:02+00:00 2026-05-25T22:04:02+00:00

I am storing HTML in an SQLite3 database using python. When I go to

  • 0

I am storing HTML in an SQLite3 database using python. When I go to insert some HTML into an SQL table I get an error/problem when I have ‘”‘ characters.

The following example of my problem creates the incorrect SQL statement:

INSERT INTO mytable(id, html, other) VALUE(1, " <img src="images/1.png" alt=""/> ", "some other info")
# it should be something like
INSERT INTO mytable(id, html, other) VALUE(1, " <img src=\"images/1.png\" alt=\"\"/> ", "some other info")

How can I have an SQL statement with ” characters in it?

import sqlite3

HTML       = """ <img src="images/1.png" alt=""/> """ # NOTE the " characters in it
insert_qry = """ INSERT INTO mytable(id, html, other) VALUE(%s, "%s", "%s")"""

conn = sqlite3.connect( GlobalVars.db_path )
cur  = conn.cursor()
res  = cur.execute( insert_qry % (1, HTML, "some other info") )


# THESE FUNCTIONS DONT SOLVE MY PROBLEM:
def format_for_DB( src_code ):
    """ Post: """

    src_code = src_code.replace( '"', '\"' )
    src_code = src_code.replace( "'", "\'" )
    return src_code


def format_for_display( src_code ):
    """ Post: """

    src_code = src_code.replace( '\"', '"' )
    src_code = src_code.replace( "\'", "'" )
    return src_code

def format_for_DB( src_code ):
    """ Post: """

    src_code = src_code.replace( '"', '""' )
    src_code = src_code.replace( "'", "''" )
    return src_code


def format_for_display( src_code ):
    """ Post: """

    src_code = src_code.replace( '""', '"' )
    src_code = src_code.replace( "''", "'" )
    return src_code
  • 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-25T22:04:02+00:00Added an answer on May 25, 2026 at 10:04 pm

    Use a parameterized query:

    query =  """ INSERT INTO mytable(id, html, other) VALUES(?, ?, ?) """
    
    # ...
    
    cur.execute(query, (1, HTML, "some other info"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am storing html of error pages of my site in sql table, i
I'm using CF8 and SQL2000. I'm storing a bunch of HTML in a Text
I have a string containing HTML and I need to replace some words to
I am storing HTML code in my MySQL table column. For inserting records, I
I have Python code that pulls info from a sqlite database and then write
I'm parsing some HTML using Beautiful Soup, and occasionally the HTML it returns includes
Tackling the problem of annotating HTML markup and storing marks in the markup itself,
I'm storing my passwords on a server, and, using nothing but HTML/JavaScript, I need
I tried to insert a base64 encoded string into my SQLite database, but when
I will be storing datetime values in an SQLite database (using Delphi and the

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.