我的环境:
我正在努力在sqlite3数据库中保存单引号。
import sqlite3
class Database:
def __init__(self):
self.dbpath = 'db.sqlite3'
self.conn = sqlite3.connect(self.dbpath)
self.c = self.conn.cursor()
db = Database()
def update_comment(name, comment='null'):
db.c.execute('update twitter_users set comment = ? where name = ?', (comment, name))
db.conn.commit()
update_comment('Jikkenndesu', "How's day?")
但是,如果我执行select * from twitter_users;
,它将输出Jikkenndesu|Hows day?
。单引号被取消。
如何解决此问题? `
答案 0 :(得分:1)
我通过代码打击解决了这个问题:
import sqlite3
class Database:
def __init__(self):
self.dbpath = 'db.sqlite3'
self.conn = sqlite3.connect(self.dbpath)
self.c = self.conn.cursor()
db = Database()
def update_comment(name, comment='null'):
db.c.execute("""update twitter_users set comment = ? where name = ?""", (comment, name))
db.conn.commit()
update_comment('Jikkenndesu', "It's a bad day today, and I will go to Phillip's")