如何在Python中保留sqlite3中的單引號?

2024-06-28 10:51:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我的环境:

  • Python 3.6.5版
  • SQLite 3.28.0版

我正在努力在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?。一句话就不提了

如何解决这个问题? `你知道吗


Tags: nameselfdb环境defcommentupdatetwitter
1条回答
网友
1楼 · 发布于 2024-06-28 10:51:51

我用密码破解了这个问题:

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")

相关问题 更多 >