{"id":1141308,"date":"2025-01-08T22:29:45","date_gmt":"2025-01-08T14:29:45","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1141308.html"},"modified":"2025-01-08T22:29:47","modified_gmt":"2025-01-08T14:29:47","slug":"python%e5%a6%82%e4%bd%95%e6%9b%b4%e6%96%b0%e6%96%87%e4%bb%b6%e6%95%b0%e6%8d%ae%e5%ba%93%e8%a1%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1141308.html","title":{"rendered":"python\u5982\u4f55\u66f4\u65b0\u6587\u4ef6\u6570\u636e\u5e93\u8868"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25104044\/21cf9b17-8e6d-4a31-b1ec-b8ad8a55f38a.webp\" alt=\"python\u5982\u4f55\u66f4\u65b0\u6587\u4ef6\u6570\u636e\u5e93\u8868\" \/><\/p>\n<p><p> <strong>Python\u66f4\u65b0\u6587\u4ef6\u6570\u636e\u5e93\u8868\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528SQLAlchemy\u3001\u4f7f\u7528Pandas\u3001\u4f7f\u7528SQLite\u3001\u4f7f\u7528PyMySQL\u7b49\u3002<\/strong>\u672c\u6587\u5c06\u8be6\u7ec6\u8bb2\u89e3\u5982\u4f55\u5229\u7528\u8fd9\u4e9b\u65b9\u6cd5\u5728Python\u4e2d\u66f4\u65b0\u6587\u4ef6\u6570\u636e\u5e93\u8868\uff0c\u5e76\u5206\u4eab\u4e00\u4e9b\u5177\u4f53\u7684\u4ee3\u7801\u793a\u4f8b\u548c\u6700\u4f73\u5b9e\u8df5\u3002<\/p>\n<\/p>\n<h2><strong>\u4e00\u3001\u4f7f\u7528SQLAlchemy<\/strong><\/h2>\n<p><p>SQLAlchemy\u662fPython\u4e2d\u4e00\u4e2a\u975e\u5e38\u5f3a\u5927\u7684SQL\u5de5\u5177\u5305\u548c\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\u5668\uff08ORM\uff09\u3002\u5b83\u5141\u8bb8\u7528\u6237\u4f7f\u7528Python\u7c7b\u6765\u8868\u793a\u6570\u636e\u5e93\u8868\uff0c\u5e76\u80fd\u591f\u8f7b\u677e\u5730\u67e5\u8be2\u548c\u66f4\u65b0\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h2>1.1 \u5b89\u88c5\u548c\u8bbe\u7f6eSQLAlchemy<\/h2>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5SQLAlchemy\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528pip\u6765\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install sqlalchemy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u9700\u8981\u5b9a\u4e49\u4e00\u4e2a\u6570\u636e\u5e93\u8fde\u63a5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u8fde\u63a5SQLite\u6570\u636e\u5e93\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sqlalchemy import create_engine<\/p>\n<p>from sqlalchemy.ext.declarative import declarative_base<\/p>\n<p>from sqlalchemy.orm import sessionmaker<\/p>\n<p>DATABASE_URL = &quot;sqlite:\/\/\/.\/test.db&quot;<\/p>\n<p>engine = create_engine(DATABASE_URL)<\/p>\n<p>SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)<\/p>\n<p>Base = declarative_base()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>1.2 \u5b9a\u4e49\u6a21\u578b<\/h2>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5b9a\u4e49\u4e00\u4e2a\u6a21\u578b\u6765\u8868\u793a\u6570\u636e\u5e93\u8868\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u7528\u6237\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sqlalchemy import Column, Integer, String<\/p>\n<p>class User(Base):<\/p>\n<p>    __tablename__ = &quot;users&quot;<\/p>\n<p>    id = Column(Integer, primary_key=True, index=True)<\/p>\n<p>    name = Column(String, index=True)<\/p>\n<p>    em<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>l = Column(String, unique=True, index=True)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>1.3 \u66f4\u65b0\u6570\u636e<\/h2>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528SQLAlchemy\u7684\u4f1a\u8bdd\u6765\u67e5\u8be2\u548c\u66f4\u65b0\u6570\u636e\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sqlalchemy.orm import Session<\/p>\n<p>def update_user(db: Session, user_id: int, new_email: str):<\/p>\n<p>    user = db.query(User).filter(User.id == user_id).first()<\/p>\n<p>    if user:<\/p>\n<p>        user.email = new_email<\/p>\n<p>        db.commit()<\/p>\n<p>        db.refresh(user)<\/p>\n<p>    return user<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u67e5\u8be2\u7528\u6237\uff0c\u7136\u540e\u66f4\u65b0\u4ed6\u4eec\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740\uff0c\u6700\u540e\u63d0\u4ea4\u66f4\u6539\u3002<\/p>\n<\/p>\n<h2><strong>\u4e8c\u3001\u4f7f\u7528Pandas<\/strong><\/h2>\n<p><p>Pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5de5\u5177\u5e93\uff0c\u5b83\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u4e0e\u5404\u79cd\u7c7b\u578b\u7684\u6587\u4ef6\u548c\u6570\u636e\u5e93\u8fdb\u884c\u4ea4\u4e92\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Pandas\u8bfb\u53d6\u6570\u636e\u5e93\u8868\u5e76\u66f4\u65b0\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h2>2.1 \u5b89\u88c5Pandas<\/h2>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5b89\u88c5Pandas\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>2.2 \u8bfb\u53d6\u548c\u66f4\u65b0\u6570\u636e<\/h2>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528Pandas\u4eceSQLite\u6570\u636e\u5e93\u8bfb\u53d6\u6570\u636e\u5e76\u66f4\u65b0\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>import sqlite3<\/p>\n<h2><strong>\u8fde\u63a5\u5230\u6570\u636e\u5e93<\/strong><\/h2>\n<p>conn = sqlite3.connect(&#39;test.db&#39;)<\/p>\n<h2><strong>\u8bfb\u53d6\u6570\u636e\u5e93\u8868<\/strong><\/h2>\n<p>df = pd.read_sql_query(&quot;SELECT * FROM users&quot;, conn)<\/p>\n<h2><strong>\u66f4\u65b0\u6570\u636e<\/strong><\/h2>\n<p>df.loc[df[&#39;id&#39;] == 1, &#39;email&#39;] = &#39;new_email@example.com&#39;<\/p>\n<h2><strong>\u5c06\u66f4\u65b0\u540e\u7684\u6570\u636e\u5199\u56de\u6570\u636e\u5e93<\/strong><\/h2>\n<p>df.to_sql(&#39;users&#39;, conn, if_exists=&#39;replace&#39;, index=False)<\/p>\n<h2><strong>\u5173\u95ed\u8fde\u63a5<\/strong><\/h2>\n<p>conn.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u8bfb\u53d6\u6574\u4e2a\u7528\u6237\u8868\uff0c\u7136\u540e\u66f4\u65b0\u7279\u5b9a\u7528\u6237\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740\uff0c\u6700\u540e\u5c06\u66f4\u65b0\u540e\u7684\u6570\u636e\u5199\u56de\u6570\u636e\u5e93\u3002<\/p>\n<\/p>\n<h2><strong>\u4e09\u3001\u4f7f\u7528SQLite<\/strong><\/h2>\n<p><p>SQLite\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684\u5d4c\u5165\u5f0f\u6570\u636e\u5e93\uff0c\u5b83\u975e\u5e38\u9002\u5408\u7528\u4e8e\u5c0f\u578b\u9879\u76ee\u548c\u5355\u7528\u6237\u5e94\u7528\u3002Python\u5185\u7f6e\u4e86SQLite\u652f\u6301\uff0c\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h2>3.1 \u4f7f\u7528SQLite\u66f4\u65b0\u6570\u636e<\/h2>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528SQLite\u5728Python\u4e2d\u66f4\u65b0\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sqlite3<\/p>\n<h2><strong>\u8fde\u63a5\u5230\u6570\u636e\u5e93<\/strong><\/h2>\n<p>conn = sqlite3.connect(&#39;test.db&#39;)<\/p>\n<p>cursor = conn.cursor()<\/p>\n<h2><strong>\u66f4\u65b0\u6570\u636e<\/strong><\/h2>\n<p>cursor.execute(&quot;UPDATE users SET email = ? WHERE id = ?&quot;, (&#39;new_email@example.com&#39;, 1))<\/p>\n<h2><strong>\u63d0\u4ea4\u66f4\u6539<\/strong><\/h2>\n<p>conn.commit()<\/p>\n<h2><strong>\u5173\u95ed\u8fde\u63a5<\/strong><\/h2>\n<p>conn.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff0c\u7136\u540e\u6267\u884c\u4e00\u4e2aUPDATE\u8bed\u53e5\u6765\u66f4\u65b0\u7279\u5b9a\u7528\u6237\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740\uff0c\u6700\u540e\u63d0\u4ea4\u66f4\u6539\u5e76\u5173\u95ed\u8fde\u63a5\u3002<\/p>\n<\/p>\n<h2><strong>\u56db\u3001\u4f7f\u7528PyMySQL<\/strong><\/h2>\n<p><p>PyMySQL\u662f\u4e00\u4e2a\u7eafPython\u7684MySQL\u5ba2\u6237\u7aef\u5e93\u3002\u5b83\u5141\u8bb8\u4f60\u901a\u8fc7Python\u7a0b\u5e8f\u4e0eMySQL\u6570\u636e\u5e93\u8fdb\u884c\u4ea4\u4e92\u3002<\/p>\n<\/p>\n<p><h2>4.1 \u5b89\u88c5PyMySQL<\/h2>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5b89\u88c5PyMySQL\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pymysql<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>4.2 \u66f4\u65b0\u6570\u636e<\/h2>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528PyMySQL\u5728Python\u4e2d\u66f4\u65b0\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pymysql.cursors<\/p>\n<h2><strong>\u8fde\u63a5\u5230\u6570\u636e\u5e93<\/strong><\/h2>\n<p>connection = pymysql.connect(host=&#39;localhost&#39;,<\/p>\n<p>                             user=&#39;user&#39;,<\/p>\n<p>                             password=&#39;passwd&#39;,<\/p>\n<p>                             database=&#39;test&#39;,<\/p>\n<p>                             cursorclass=pymysql.cursors.DictCursor)<\/p>\n<p>try:<\/p>\n<p>    with connection.cursor() as cursor:<\/p>\n<p>        # \u66f4\u65b0\u6570\u636e<\/p>\n<p>        sql = &quot;UPDATE users SET email = %s WHERE id = %s&quot;<\/p>\n<p>        cursor.execute(sql, (&#39;new_email@example.com&#39;, 1))<\/p>\n<p>    # \u63d0\u4ea4\u66f4\u6539<\/p>\n<p>    connection.commit()<\/p>\n<p>finally:<\/p>\n<p>    connection.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u8fde\u63a5\u5230MySQL\u6570\u636e\u5e93\uff0c\u7136\u540e\u6267\u884c\u4e00\u4e2aUPDATE\u8bed\u53e5\u6765\u66f4\u65b0\u7279\u5b9a\u7528\u6237\u7684\u7535\u5b50\u90ae\u4ef6\u5730\u5740\uff0c\u6700\u540e\u63d0\u4ea4\u66f4\u6539\u5e76\u5173\u95ed\u8fde\u63a5\u3002<\/p>\n<\/p>\n<h2><strong>\u4e94\u3001\u6700\u4f73\u5b9e\u8df5<\/strong><\/h2>\n<p><p>\u65e0\u8bba\u4f60\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u66f4\u65b0\u6570\u636e\u5e93\u8868\u7684\u6700\u4f73\u5b9e\u8df5\uff1a<\/p>\n<\/p>\n<p><h2>5.1 \u4f7f\u7528\u4e8b\u52a1<\/h2>\n<\/p>\n<p><p>\u4e8b\u52a1\u53ef\u4ee5\u786e\u4fdd\u4f60\u7684\u6570\u636e\u4e00\u81f4\u6027\u3002\u5982\u679c\u5728\u66f4\u65b0\u8fc7\u7a0b\u4e2d\u53d1\u751f\u9519\u8bef\uff0c\u4e8b\u52a1\u53ef\u4ee5\u8ba9\u4f60\u56de\u6eda\u5230\u4e4b\u524d\u7684\u72b6\u6001\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">try:<\/p>\n<p>    with connection.cursor() as cursor:<\/p>\n<p>        sql = &quot;UPDATE users SET email = %s WHERE id = %s&quot;<\/p>\n<p>        cursor.execute(sql, (&#39;new_email@example.com&#39;, 1))<\/p>\n<p>    connection.commit()<\/p>\n<p>except:<\/p>\n<p>    connection.rollback()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>5.2 \u6570\u636e\u9a8c\u8bc1<\/h2>\n<\/p>\n<p><p>\u5728\u66f4\u65b0\u6570\u636e\u4e4b\u524d\uff0c\u786e\u4fdd\u5bf9\u8f93\u5165\u6570\u636e\u8fdb\u884c\u9a8c\u8bc1\u3002\u4f8b\u5982\uff0c\u68c0\u67e5\u7535\u5b50\u90ae\u4ef6\u5730\u5740\u7684\u683c\u5f0f\u662f\u5426\u6b63\u786e\u3002<\/p>\n<\/p>\n<p><h2>5.3 \u65e5\u5fd7\u8bb0\u5f55<\/h2>\n<\/p>\n<p><p>\u8bb0\u5f55\u6240\u6709\u7684\u6570\u636e\u5e93\u64cd\u4f5c\uff0c\u4ee5\u4fbf\u5728\u51fa\u73b0\u95ee\u9898\u65f6\u53ef\u4ee5\u8fdb\u884c\u8c03\u8bd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import logging<\/p>\n<p>logging.basicConfig(level=logging.INFO)<\/p>\n<p>logger = logging.getLogger(__name__)<\/p>\n<p>try:<\/p>\n<p>    with connection.cursor() as cursor:<\/p>\n<p>        sql = &quot;UPDATE users SET email = %s WHERE id = %s&quot;<\/p>\n<p>        cursor.execute(sql, (&#39;new_email@example.com&#39;, 1))<\/p>\n<p>    connection.commit()<\/p>\n<p>    logger.info(&quot;Updated user with id 1&quot;)<\/p>\n<p>except Exception as e:<\/p>\n<p>    connection.rollback()<\/p>\n<p>    logger.error(&quot;Failed to update user: %s&quot;, e)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>5.4 \u4f7f\u7528\u53c2\u6570\u5316\u67e5\u8be2<\/h2>\n<\/p>\n<p><p>\u4f7f\u7528\u53c2\u6570\u5316\u67e5\u8be2\u53ef\u4ee5\u9632\u6b62SQL\u6ce8\u5165\u653b\u51fb\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">sql = &quot;UPDATE users SET email = %s WHERE id = %s&quot;<\/p>\n<p>cursor.execute(sql, (&#39;new_email@example.com&#39;, 1))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<h2><strong>\u516d\u3001\u603b\u7ed3<\/strong><\/h2>\n<p><p>\u5728Python\u4e2d\u66f4\u65b0\u6587\u4ef6\u6570\u636e\u5e93\u8868\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528SQLAlchemy\u3001Pandas\u3001SQLite\u548cPyMySQL\u7b49\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u70b9\u548c\u9002\u7528\u573a\u666f\u3002<strong>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6839\u636e\u9879\u76ee\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u5e76\u9075\u5faa\u6700\u4f73\u5b9e\u8df5<\/strong>\uff0c\u53ef\u4ee5\u786e\u4fdd\u4f60\u7684\u6570\u636e\u5e93\u64cd\u4f5c\u9ad8\u6548\u3001\u5b89\u5168\u548c\u53ef\u9760\u3002<\/p>\n<\/p>\n<p><p>\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u5e2e\u52a9\u4f60\u7406\u89e3\u5982\u4f55\u5728Python\u4e2d\u66f4\u65b0\u6587\u4ef6\u6570\u636e\u5e93\u8868\uff0c\u5e76\u4e3a\u4f60\u5728\u5b9e\u9645\u9879\u76ee\u4e2d\u63d0\u4f9b\u4e00\u4e9b\u53c2\u8003\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u8fde\u63a5\u5230\u6587\u4ef6\u6570\u636e\u5e93\uff1f<\/strong><br \/>\u8981\u4f7f\u7528Python\u8fde\u63a5\u5230\u6587\u4ef6\u6570\u636e\u5e93\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528SQLite\u5e93\uff0c\u5b83\u662fPython\u5185\u7f6e\u7684\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u6570\u636e\u5e93\u3002\u9996\u5148\uff0c\u60a8\u9700\u8981\u5bfc\u5165sqlite3\u6a21\u5757\uff0c\u5e76\u4f7f\u7528<code>sqlite3.connect(&#39;your_database.db&#39;)<\/code>\u65b9\u6cd5\u8fde\u63a5\u5230\u6570\u636e\u5e93\u6587\u4ef6\u3002\u786e\u4fdd\u60a8\u7684\u6570\u636e\u5e93\u6587\u4ef6\u5b58\u5728\uff0c\u6216\u8005\u7a0b\u5e8f\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u66f4\u65b0\u6587\u4ef6\u6570\u636e\u5e93\u8868\u7684\u5e38\u7528\u65b9\u6cd5\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528SQL\u7684<code>UPDATE<\/code>\u8bed\u53e5\u6765\u66f4\u65b0\u6587\u4ef6\u6570\u636e\u5e93\u8868\u7684\u8bb0\u5f55\u3002\u60a8\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u6e38\u6807\u5bf9\u8c61\uff0c\u901a\u8fc7\u6e38\u6807\u6267\u884cSQL\u8bed\u53e5\u3002\u4f7f\u7528<code>cursor.execute(&quot;UPDATE table_name SET column_name = new_value WHERE condition&quot;)<\/code>\u6765\u66f4\u65b0\u7279\u5b9a\u7684\u8bb0\u5f55\uff0c\u63a5\u7740\u4f7f\u7528<code>connection.commit()<\/code>\u6765\u4fdd\u5b58\u66f4\u6539\u3002<\/p>\n<p><strong>\u5982\u4f55\u786e\u4fdd\u5728\u66f4\u65b0\u6587\u4ef6\u6570\u636e\u5e93\u8868\u65f6\u6570\u636e\u5b89\u5168\uff1f<\/strong><br \/>\u5728\u66f4\u65b0\u6587\u4ef6\u6570\u636e\u5e93\u8868\u65f6\uff0c\u786e\u4fdd\u6570\u636e\u5b89\u5168\u7684\u4e00\u4e2a\u597d\u65b9\u6cd5\u662f\u4f7f\u7528\u4e8b\u52a1\u5904\u7406\u3002\u901a\u8fc7\u5728\u6267\u884c\u66f4\u65b0\u64cd\u4f5c\u4e4b\u524d\u8c03\u7528<code>connection.begin()<\/code>\u6765\u5f00\u59cb\u4e00\u4e2a\u4e8b\u52a1\uff0c\u5b8c\u6210\u540e\u4f7f\u7528<code>connection.commit()<\/code>\u63d0\u4ea4\u66f4\u6539\u3002\u82e5\u53d1\u751f\u9519\u8bef\uff0c\u53ef\u4ee5\u4f7f\u7528<code>connection.rollback()<\/code>\u6765\u64a4\u9500\u66f4\u6539\u3002\u6b64\u5916\uff0c\u4f7f\u7528\u53c2\u6570\u5316\u67e5\u8be2\u53ef\u4ee5\u907f\u514dSQL\u6ce8\u5165\uff0c\u589e\u5f3a\u5b89\u5168\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u66f4\u65b0\u6587\u4ef6\u6570\u636e\u5e93\u8868\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528SQLAlchemy\u3001\u4f7f\u7528Pandas\u3001\u4f7f\u7528SQLite\u3001\u4f7f\u7528Py [&hellip;]","protected":false},"author":3,"featured_media":1141315,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1141308"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1141308"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1141308\/revisions"}],"predecessor-version":[{"id":1141316,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1141308\/revisions\/1141316"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1141315"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1141308"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1141308"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1141308"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}