Chào mừng bạn đến blog Kế Toán.VN Trang Chủ

Table of Content

Trình trợ giúp Python SQL ✅ Chi Tiết

Mẹo Hướng dẫn Trình trợ giúp Python SQL Mới Nhất

Lê Mạnh Hùng đang tìm kiếm từ khóa Trình trợ giúp Python SQL được Cập Nhật vào lúc : 2022-12-25 10:35:11 . Với phương châm chia sẻ Thủ Thuật về trong nội dung bài viết một cách Chi Tiết 2022. Nếu sau khi tham khảo nội dung bài viết vẫn ko hiểu thì hoàn toàn có thể lại Comments ở cuối bài để Mình lý giải và hướng dẫn lại nha.

Trong nội dung bài viết này, tất cả chúng ta đã thấy rằng tất cả chúng ta hoàn toàn có thể sử dụng những truy vấn SQL để thao tác trên DataFrames thuận tiện và đơn giản ra làm sao. Điều này cho tất cả chúng ta thuở nào cơ duy nhất. Vũ khí này hoàn toàn có thể là một vũ khí mạnh trong kho vũ khí của bất kỳ Nhà khoa học tài liệu nào, người biết SQL và Python, cả hai

Nội dung chính Show
    Hướng dẫn¶Thẩm quyền xử lý và xử lý¶Chức năng mô-đun¶Hằng số mô-đun¶Đối tượng link¶Đối tượng con trỏ¶Đối tượng hàng¶Đối tượng đốm màu¶Chuẩn bị đối tượngProtocol¶Ngoại lệ¶SQLite and Python types¶Bộ điều hợp và bộ quy đổi mặc định¶Làm thế nào để hướng dẫn¶Cách sử dụng trình giữ chỗ để link những giá trị trong truy vấn SQL¶Cách điều chỉnh nhiều chủng loại Python tùy chỉnh thành những giá trị SQLite¶How to convert SQLite values to custom Python types¶Adapter and converter recipes¶How to use connection shortcut methods¶How to use the connection context manager¶How to work with SQLite URIs¶How to create and use row factories¶Explanation¶Transaction control¶Can I run SQL query in Python?How to build SQL query in Python?Làm cách nào để sử dụng trình giữ chỗ trong truy vấn SQL bằng Python?Làm cách nào để lấy tài liệu từ cơ sở tài liệu bằng Python?

Cả hai đều là ngôn từ mạnh mẽ và tự tin và có điểm mạnh và điểm yếu tương ứng. Sử dụng phương pháp được hiển thị trong nội dung bài viết này, hay nói cách khác, sử dụng thư viện

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 74 và hàm cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 75, tất cả chúng ta hoàn toàn có thể sử dụng phương pháp tốt nhất và hiệu suất cao nhất để thao tác tài liệu, ngay trong môi trường tự nhiên thiên nhiên python và thậm chí cả Jupyter Notebook. This is music to my ears. I hope you enjoyed the cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 76 too 🤓

In this article, you saw how to use SQL queries inside python. But if you want to connect the two most powerful workhorses of the Data Science world, SQL and Python. This is not the end, but only the first step towards getting the “Best of Both Worlds”

End Notes

Now you can start using Python to work upon your data which rests in SQL Databases. In able to connect to your SQL databases, go thru my article How to Access & Use SQL Database with pyodbc in Python. Once you brought it as DataFrame, then all the operations are usual Pandas operations or SQL queries being operated on Pandas DataFrame as you saw in this article

Apart from the function of SQL shown in this article, many other popular SQL functions are easily implementable in Python. Read 15 Pandas functions to replicate basic SQL Queries in Python for learning how to do that

The implied learning in this article was, that you can use Python to do things that you thought were only possible using SQL. There may or may not be straight forward solution to things, but if you are inclined to find it, there are enough resources your disposal to find a way out. You can look the mix and match the learning from my book, PYTHON MADE EASY – Step by Step Guide to Programming and Data Analysis using Python for Beginners and Intermediate Level

About the Author. I am Nilabh Nishchhal. I like making seemingly difficult topics easy and write about them. Check out more https. //www. authornilabh. com/. My attempt to make Python easy and Accessible to all is Python Made Easy

Cover Photo Credit.  Photo by Norbert Hentges on Unsplash

The truyền thông shown in this article are not owned by Analytics Vidhya and are used the Author’s discretion

SQLite is a C library that provides a lightweight disk-based database that doesn’t require a separate server process and allows accessing the database using a nonstandard variant of the SQL query language. Some applications can use SQLite for internal data storage. It’s also possible to prototype an application using SQLite and then port the code to a larger database such as PostgreSQL or Oracle

The

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 module was written by Gerhard Häring. It provides an SQL interface compliant with the DB-API 2. 0 specification described by PEP 249, and requires SQLite 3. 7. 15 or newer

This document includes four main sections

    Tutorial teaches how to use the

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 module.

    Reference describes the classes and functions this module defines.

    How-to guides details how to handle specific tasks.

    Explanation provides in-depth background on transaction control.

See also

https. //www. sqlite. org

The SQLite web page; the documentation describes the syntax and the available data types for the supported SQL dialect

https. //www. w3schools. com/sql/

Tutorial, reference and examples for learning SQL syntax

PEP 249 - Database API Specification 2. 0

PEP written by Marc-André Lemburg

Hướng dẫn¶

Trong hướng dẫn này, bạn sẽ tạo cơ sở tài liệu phim Monty Python bằng phương pháp sử dụng hiệu suất cao

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 cơ bản. Nó giả định một sự hiểu biết cơ bản về những khái niệm cơ sở tài liệu, gồm có con trỏ và thanh toán giao dịch thanh toán

Đầu tiên, tất cả chúng ta cần tạo một cơ sở tài liệu mới và mở một link cơ sở tài liệu để được cho phép

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 thao tác với nó. Gọi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 5 để tạo link đến cơ sở tài liệu cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 6 trong thư mục thao tác hiện tại, tạo ngầm nếu chưa tồn tại

import sqlite3 con = sqlite3.connect("tutorial.db")

Đối tượng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7 được trả về cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 8 đại diện cho link với cơ sở tài liệu trên đĩa

Để thực thi những câu lệnh SQL và tìm nạp kết quả từ những truy vấn SQL, tất cả chúng ta sẽ cần sử dụng một con trỏ cơ sở tài liệu. Gọi

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 9 để tạo cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 1

Bây giờ tất cả chúng ta đã có link cơ sở tài liệu và con trỏ, tất cả chúng ta hoàn toàn có thể tạo bảng cơ sở tài liệu

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 01 với những cột cho tiêu đề, năm phát hành và điểm đánh giá. Để đơn giản, tất cả chúng ta chỉ việc sử dụng tên cột trong khai báo bảng – nhờ tính năng gõ linh hoạt của SQLite, việc chỉ định kiểu tài liệu là tùy chọn. Thực hiện câu lệnh cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 02 bằng phương pháp gọi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 03

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 5

Chúng tôi hoàn toàn có thể xác minh rằng bảng mới đã được tạo bằng phương pháp truy vấn bảng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 04 được tích hợp sẵn trong SQLite, hiện sẽ chứa một mục nhập cho định nghĩa bảng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 01 (xem Bảng lược đồ để biết rõ ràng). Thực hiện truy vấn đó bằng phương pháp gọi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 03, gán kết quả cho cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 07 và gọi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 08 để lấy hàng kết quả

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 1

Chúng ta hoàn toàn có thể thấy rằng bảng đã được tạo, khi truy vấn trả về một

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09 chứa tên của bảng. Nếu chúng tôi truy vấn cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 04 cho một bảng không tồn tại cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 41, thì cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 08 sẽ trả về cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7

Bây giờ, hãy thêm hai hàng tài liệu được đáp ứng dưới dạng ký tự SQL bằng phương pháp thực hiện câu lệnh

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 44, một lần nữa bằng phương pháp gọi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 03

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """)

Câu lệnh

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 44 ngầm mở một thanh toán giao dịch thanh toán, thanh toán giao dịch thanh toán này phải cam kết trước khi những thay đổi được lưu vào cơ sở tài liệu (xem Kiểm soát thanh toán giao dịch thanh toán để biết rõ ràng). Gọi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 47 trên đối tượng link để thực hiện thanh toán giao dịch thanh toán.

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0

Chúng tôi hoàn toàn có thể xác minh rằng tài liệu đã được chèn đúng chuẩn bằng phương pháp thực hiện truy vấn

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 48. Sử dụng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 03 hiện đã quen thuộc để gán kết quả cho cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 07 và gọi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 71 để trả về tất cả những hàng kết quả

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 4

Kết quả là một

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 72 trong số hai cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09, mỗi cái một hàng, mỗi cái chứa giá trị cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 74 của hàng đó

Bây giờ, chèn thêm ba hàng bằng phương pháp gọi

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 75

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7

Lưu ý rằng trình giữ chỗ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 76 được sử dụng để link cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 77 với truy vấn. Luôn sử dụng trình giữ chỗ thay vì định dạng chuỗi để link những giá trị Python với câu lệnh SQL, nhằm mục đích tránh những cuộc tấn công SQL injection (xem Cách thức . for more details).

Chúng tôi hoàn toàn có thể xác minh rằng những hàng mới đã được chèn bằng phương pháp thực hiện truy vấn

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 48, lần này lặp lại kết quả của truy vấn

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7

Mỗi hàng là một

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09 hai mục của cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 70, khớp với những cột được chọn trong truy vấn

Cuối cùng, xác minh rằng cơ sở tài liệu đã được ghi vào đĩa bằng phương pháp gọi

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 71 để đóng link hiện có, mở một link mới, tạo con trỏ mới, sau đó truy vấn cơ sở tài liệu

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 10

Bây giờ bạn đã tạo cơ sở tài liệu SQLite bằng mô-đun

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0, đã chèn tài liệu và truy xuất giá trị từ cơ sở tài liệu đó theo nhiều cách thức

See also

    Hướng dẫn cách thực hiện để đọc thêm.

      Cách sử dụng trình giữ chỗ để link những giá trị trong truy vấn SQL

      Cách điều chỉnh nhiều chủng loại Python tùy chỉnh thành những giá trị SQLite

      Cách quy đổi những giá trị SQLite thành nhiều chủng loại Python tùy chỉnh

      Cách sử dụng trình quản lý toàn cảnh link

      Cách tạo và sử dụng row factory

    Giải thích để biết thông tin cơ bản nâng cao về trấn áp thanh toán giao dịch thanh toán.

Thẩm quyền xử lý và xử lý¶

Chức năng mô-đun¶

sqlite3. link(cơ sở tài liệu , thời gian chờ . 0=5.0 , detect_types=0 . Kết nối isolation_level='DEFERRED', check_same_thread=True, factory=sqlite3.Connection , cached_statements=128, uri=False)¶

Mở link tới cơ sở tài liệu SQLite

Thông số

    cơ sở tài liệu ( đối tượng dạng đường dẫn ) – Đường dẫn đến tệp cơ sở tài liệu sẽ được mở. Vượt qua

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 73 để mở link tới cơ sở tài liệu trong RAM thay vì trên đĩa.

    thời gian chờ (float) – Kết nối sẽ đợi bao nhiêu giây trước khi đưa ra một ngoại lệ, nếu cơ sở tài liệu bị khóa bởi một link khác. Nếu một link khác mở một thanh toán giao dịch thanh toán để sửa đổi cơ sở tài liệu, nó sẽ bị khóa cho tới lúc thanh toán giao dịch thanh toán đó được thực hiện. Mặc định năm giây

    detect_types (int) – Kiểm soát xem và bằng phương pháp nào nhiều chủng loại tài liệu không được SQLite tương hỗ được tra cứu để quy đổi thành nhiều chủng loại Python, bằng phương pháp sử dụng . Đặt nó thành bất kỳ phối hợp nào (sử dụng

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 75, bitwise hoặc) của cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 76 và cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 77 để kích hoạt tính năng này. Tên cột được ưu tiên hơn nhiều chủng loại đã khai báo nếu cả hai cờ được đặt. Không thể phát hiện nhiều chủng loại cho những trường đã tạo (ví dụ: cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 78), trong cả những lúc tham số detect_types được đặt; . Theo mặc định (cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 100), tính năng phát hiện loại bị tắt.

    isolation_level (str. Không có) –

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 101 của link, trấn áp liệu những thanh toán giao dịch thanh toán đã có được mở hoàn toàn hay là không và bằng phương pháp nào. Có thể là cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 102 (mặc định), cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 103 hoặc cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 104; . Xem Kiểm soát thanh toán giao dịch thanh toán để biết thêm.

    check_same_thread (bool) – Nếu

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 106 (mặc định), chỉ thread tạo mới hoàn toàn có thể sử dụng link. Nếu cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 107, link hoàn toàn có thể được chia sẻ trên nhiều luồng;

    nhà máy sản xuất (Kết nối) – Một lớp con tùy chỉnh của

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7 để tạo link với, nếu không phải là lớp cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7 mặc định

    cached_statements (int) – Số câu lệnh mà

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 sẽ lưu vào bộ nhớ đệm nội bộ cho link này, để tránh phân tích cú pháp ngân sách. Theo mặc định, 128 câu lệnh

    uri (bool) – Nếu được đặt thành

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 106, cơ sở tài liệu được hiểu là URI với đường dẫn tệp và chuỗi truy vấn tùy chọn. Phần lược đồ phải là cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 112 và đường dẫn hoàn toàn có thể là tương đối hoặc tuyệt đối. Chuỗi truy vấn được cho phép chuyển tham số sang SQLite, được cho phép Cách thao tác với URI SQLite rất khác nhau.
loại trả lại

Sự liên quan

Tăng sự kiện kiểm tra

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 113 với đối số cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 114.

Tăng sự kiện kiểm tra

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 115 với đối số cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 116.

Mới trong phiên bản 3. 4. Tham số uri.

Đã thay đổi trong phiên bản 3. 7. cơ sở tài liệu giờ đây cũng hoàn toàn có thể là một đối tượng dạng đường dẫn , không riêng gì có là một chuỗi.

Mới trong phiên bản 3. 10. Sự kiện truy thuế kiểm toán

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 115. sqlite3. complete_statement(câu lệnh) ¶

Trả lại

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 106 nếu câu lệnh chuỗi dường như chứa một hoặc nhiều câu lệnh SQL hoàn hảo nhất. Không có xác minh cú pháp hoặc phân tích cú pháp dưới bất kỳ hình thức nào được thực hiện, ngoài việc kiểm tra để đảm nói rằng không còn chuỗi ký tự không được đóng dấu và câu lệnh được kết thúc bằng dấu chấm phẩy

Ví dụ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 11

Chức năng này hoàn toàn có thể hữu ích trong quá trình nhập dòng lệnh để xác định xem văn bản đã nhập liệu có phải là một câu lệnh SQL hoàn hảo nhất hay là không hoặc nếu cần nhập thêm trước khi gọi

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 119sqlite3. enable_callback_tracebacks(flag , /)¶

Bật hoặc tắt theo dõi cuộc gọi lại. Theo mặc định, bạn sẽ không sở hữu và nhận được bất kỳ dấu vết nào trong những hiệu suất cao do người tiêu dùng xác định, tổng hợp, trình quy đổi, lệnh gọi lại của người ủy quyền, v.v. Nếu bạn muốn gỡ lỗi chúng, bạn hoàn toàn có thể gọi hiệu suất cao này với cờ được đặt thành

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 106. Sau đó, bạn sẽ nhận được dấu vết từ những cuộc gọi lại trên cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 121. Sử dụng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 107 để tắt lại tính năng này

Đăng ký một

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 123 để có trải nghiệm gỡ lỗi được cải tổ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 12sqlite3. register_adapter(loại , bộ quy đổi, /)¶

Đăng ký bộ điều hợp hoàn toàn có thể gọi được để điều chỉnh loại Python thành loại SQLite. Bộ điều hợp được gọi với một đối tượng Python thuộc loại làm đối số duy nhất của nó và phải trả về giá trị của loại mà SQLite vốn hiểu .

sqlite3. register_converter(typename , converter, /)¶

Đăng ký trình quy đổi hoàn toàn có thể gọi được để quy đổi những đối tượng SQLite thuộc loại tên thành một đối tượng Python thuộc một loại rõ ràng. Trình quy đổi được gọi cho tất cả những giá trị SQLite của kiểu tên; . Tham khảo tham số detect_types của

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 125 để biết thông tin về cách hoạt động và sinh hoạt giải trí của tính năng phát hiện loại

Ghi chú. tên loại và tên của loại trong truy vấn của bạn được đối sánh không phân biệt chữ hoa chữ thường

Hằng số mô-đun¶

sqlite3. PARSE_COLNAMES ¶

Chuyển giá trị cờ này cho tham số detect_types của

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 125 để tra cứu hàm quy đổi bằng phương pháp sử dụng tên loại, được phân tích cú pháp từ tên cột truy vấn, làm khóa từ điển quy đổi. Tên loại phải được đặt trong dấu ngoặc vuông (______1127)

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 13

Cờ này hoàn toàn có thể được kết phù phù hợp với

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 76 bằng phương pháp sử dụng toán tử cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 75 (theo bit hoặc)sqlite3. PARSE_DECLTYPES ¶

Chuyển giá trị cờ này cho tham số detect_types của

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 125 để tra cứu hàm quy đổi bằng phương pháp sử dụng nhiều chủng loại đã khai báo cho từng cột. Các loại được khai báo khi bảng cơ sở tài liệu được tạo. cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 sẽ tra cứu hàm quy đổi bằng phương pháp sử dụng từ đầu tiên của loại được khai báo làm khóa từ điển quy đổi. Ví dụ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 14

Cờ này hoàn toàn có thể được kết phù phù hợp với

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 77 bằng phương pháp sử dụng toán tử cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 75 (theo bit hoặc)sqlite3. SQLITE_OK ¶ sqlite3. SQLITE_DENY ¶ sqlite3. SQLITE_IGNORE ¶

Các cờ sẽ được trả về bởi kĩ năng gọi lại ủy quyền_callback được chuyển đến

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 134, để cho biết thêm thêm liệu

    Truy cập được được cho phép (

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 135),

    Câu lệnh SQL sẽ bị hủy bỏ khi có lỗi (

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 136)

    Cột phải được xem là giá trị

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 137 (cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 138)
sqlite3. apilevel ¶

Hằng số chuỗi cho biết thêm thêm mức DB-API được tương hỗ. Yêu cầu bởi DB-API. Mã hóa cứng thành

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 139sqlite3. paramstyle ¶

Hằng số chuỗi cho biết thêm thêm loại định dạng đánh dấu tham số mà mô-đun

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 mong đợi. Yêu cầu bởi DB-API. Mã hóa cứng thành cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 141

Ghi chú

Mô-đun

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 tương hỗ những kiểu tham số DB-API cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 143, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 144 và cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 145, chính bới đó là những gì mà thư viện SQLite phía dưới tương hỗ. Tuy nhiên, DB-API không được cho phép nhiều giá trị cho thuộc tính cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 146sqlite3. sqlite_version ¶

Số phiên bản của thư viện SQLite thời gian chạy dưới dạng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 147sqlite3. sqlite_version_info ¶

Số phiên bản của thư viện SQLite thời gian chạy là

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09 của cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 149sqlite3. bảo vệ an toàn và đáng tin cậy luồng ¶

Hằng số nguyên theo yêu cầu của DB-API 2. 0, cho biết thêm thêm mức độ bảo vệ an toàn và đáng tin cậy của luồng mà mô-đun

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 tương hỗ. Thuộc tính này được đặt nhờ vào chính sách phân luồng mặc định mà thư viện SQLite phía dưới được biên dịch với. Các chính sách luồng SQLite là

đơn luồng. Trong chính sách này, tất cả những mutex đều bị vô hiệu hóa và SQLite không bảo vệ an toàn và đáng tin cậy khi sử dụng trong nhiều luồng đơn lẻ cùng một lúc

đa luồng. Trong chính sách này, SQLite hoàn toàn có thể được sử dụng bảo vệ an toàn và đáng tin cậy bởi nhiều luồng với điều kiện là không còn link cơ sở tài liệu đơn lẻ nào được sử dụng đồng thời trong hai hoặc nhiều luồng

nối tiếp. Ở chính sách tuần tự hóa, SQLite hoàn toàn có thể được nhiều luồng sử dụng một cách bảo vệ an toàn và đáng tin cậy mà không biến thành hạn chế

Ánh xạ từ những chính sách luồng SQLite sang DB-API 2. 0 mức độ bảo vệ an toàn và đáng tin cậy luồng như sau

Chế độ luồng SQLite

chủ đề bảo vệ an toàn và đáng tin cậy

SQLITE_THREADSAFE

DB-API 2. 0 ý nghĩa

đơn luồng

0

0

Chủ đề hoàn toàn có thể không chia sẻ mô-đun

đa luồng

1

2

Chủ đề hoàn toàn có thể chia sẻ mô-đun, nhưng không link

nối tiếp

3

1

Chủ đề hoàn toàn có thể chia sẻ mô-đun, link và con trỏ

Đã thay đổi trong phiên bản 3. 11. Đặt động luồng bảo vệ an toàn và đáng tin cậy thay vì mã hóa cứng thành

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 151. sqlite3. phiên bản ¶

Số phiên bản của mô-đun này là

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 147. Đây không phải là phiên bản của thư viện SQLitesqlite3. version_info ¶

Số phiên bản của mô-đun này là

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09 của cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 149. Đây không phải là phiên bản của thư viện SQLite

Đối tượng link¶

lớp sqlite3. Kết nối ¶

Mỗi cơ sở tài liệu SQLite mở được đại diện bởi một đối tượng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7, đối tượng này được tạo bằng phương pháp sử dụng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 5. Mục đích chính của chúng là tạo ra những đối tượng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 và Kiểm soát thanh toán giao dịch thanh toán .

See also

    Cách sử dụng những phương pháp phím tắt link

    Cách sử dụng trình quản lý toàn cảnh link

Kết nối cơ sở tài liệu SQLite có những thuộc tính và phương thức sau

con trỏ(nhà máy sản xuất=Con trỏ)¶

Tạo và trả về một đối tượng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00. Phương thức con trỏ đồng ý một nhà máy sản xuất tham số tùy chọn duy nhất. Nếu được đáp ứng, đây phải là một phiên bản hoàn toàn có thể gọi được trả về một phiên bản của cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 hoặc những lớp con của nóblobopen(bảng , cột, row, /, *, readonly=False, name='main')¶

Mở tay cầm

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 160 cho BLOB hiện cóThông số

    table (str) – Tên của bảng chứa blob

    cột (str) – Tên của cột chứa đốm màu

    row (str) – Tên của hàng chứa đốm màu

    chỉ đọc (bool) – Đặt thành

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 106 nếu blob được mở mà không còn quyền ghi. Mặc định là cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 107

    name (str) – Tên của cơ sở tài liệu chứa blob. Mặc định là

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 163
tăng

OperationalError - Khi nỗ lực mở một đốm màu trong bảng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 164loại trả lại

Bãi

Ghi chú

Không thể thay đổi kích thước đốm màu bằng lớp

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 160. Sử dụng hàm SQL cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 166 để tạo đốm màu có kích thước cố định và thắt chặt

Mới trong phiên bản 3. 11

cam kết() ¶

Cam kết mọi thanh toán giao dịch thanh toán đang chờ xử lý vào cơ sở tài liệu. Nếu không còn thanh toán giao dịch thanh toán mở, phương pháp này là không hoạt động và sinh hoạt giải trí

rollback() ¶

Quay lại điểm khởi đầu của bất kỳ thanh toán giao dịch thanh toán đang chờ xử lý nào. Nếu không còn thanh toán giao dịch thanh toán mở, phương pháp này là không hoạt động và sinh hoạt giải trí

đóng() ¶

Đóng link cơ sở tài liệu. Bất kỳ thanh toán giao dịch thanh toán đang chờ xử lý nào đều không được cam kết ngầm;

thực thi(sql , tham số=(), /)¶

Tạo một đối tượng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 mới và gọi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 119 trên đó với sql và tham số đã cho. Trả về đối tượng con trỏ mớiexecutemany(sql , tham số, /)¶

Tạo một đối tượng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 mới và gọi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 171 trên đó với sql và tham số đã cho. Trả về đối tượng con trỏ mớiexecutescript(sql_script , /)¶

Tạo một đối tượng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 mới và gọi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 173 trên đó với sql_script đã cho. Trả về đối tượng con trỏ mớicreate_function(tên , narg, func, *, deterministic=False)¶

Tạo hoặc xóa hàm SQL do người tiêu dùng định nghĩa

Thông số

    name (str) – Tên của hàm SQL

    narg (int) – Số lượng đối số mà hàm SQL hoàn toàn có thể đồng ý. Nếu

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 174, nó hoàn toàn có thể nhận bất kỳ số đối số nào

    func ( gọi lại . Không có) – Có thể gọi được gọi khi hàm SQL được gọi. Có thể gọi được phải trả về một loại vốn được tương hỗ bởi SQLite . Đặt thành

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43 để xóa hàm SQL hiện có.

    tất định (bool) – Nếu

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 106, hàm SQL đã tạo được đánh dấu là tất định, được cho phép SQLite thực hiện những tối ưu hóa tương hỗ update
tăng

NotSupportedError - Nếu xác định được sử dụng với những phiên bản SQLite cũ hơn 3. 8. 3

Mới trong phiên bản 3. 8. Tham số xác định.

Ví dụ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 15create_aggregate(tên , /, n_arg, aggregate_class)¶

Tạo hoặc xóa hàm tổng hợp SQL do người tiêu dùng xác định

Thông số

    name (str) – Tên của hàm tổng hợp SQL

    n_arg (int) – Số lượng đối số mà hàm tổng hợp SQL hoàn toàn có thể đồng ý. Nếu

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 174, nó hoàn toàn có thể nhận bất kỳ số đối số nào

    lớp_tổng hợp ( lớp . Không có) –

    Một lớp phải thực hiện những phương pháp sau

      cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 178. Thêm một hàng vào tổng hợp

      ____1179. Trả về kết quả ở đầu cuối của tổng hợp dưới dạng một loại vốn được SQLite tương hỗ .

    Số lượng đối số mà phương thức

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 178 phải hoàn toàn có thể đồng ý được trấn áp bởi n_arg

    Đặt thành

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43 để xóa hàm tổng hợp SQL hiện có

Ví dụ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 16create_window_function(tên , num_params, aggregate_class, /)¶

Tạo hoặc xóa hiệu suất cao hiên chạy cửa số tổng hợp do người tiêu dùng xác định

Thông số

    name (str) – Tên của hàm hiên chạy cửa số tổng hợp SQL để tạo hoặc xóa

    num_params (int) – Số lượng đối số mà hàm hiên chạy cửa số tổng hợp SQL hoàn toàn có thể đồng ý. Nếu

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 174, nó hoàn toàn có thể nhận bất kỳ số đối số nào

    lớp_tổng hợp ( lớp . Không có) –

    Một lớp phải thực hiện những phương thức sau

      cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 178. Thêm một hàng vào hiên chạy cửa số hiện tại

      cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 184. Trả về giá trị hiện tại của tổng hợp

      cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 185. Xóa một hàng khỏi hiên chạy cửa số hiện tại

      ____1179. Trả về kết quả ở đầu cuối của tổng hợp dưới dạng một loại vốn được SQLite tương hỗ .

    Số lượng đối số mà những phương thức

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 178 và cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 184 phải hoàn toàn có thể đồng ý được trấn áp bởi num_params

    Đặt thành

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43 để xóa hiệu suất cao hiên chạy cửa số tổng hợp SQL hiện có
tăng

NotSupportedError – Nếu được sử dụng với phiên bản SQLite cũ hơn 3. 25. 0, không tương hỗ những hiệu suất cao hiên chạy cửa số tổng hợp

Mới trong phiên bản 3. 11

Ví dụ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 17create_collation(tên , hoàn toàn có thể gọi)¶

Tạo một đối chiếu mang tên name bằng hiệu suất cao đối chiếu hoàn toàn có thể gọi được. hoàn toàn có thể gọi được thông qua hai đối số

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 147 và nó sẽ trả về một cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 191

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 151 nếu cái đầu tiên được đặt cao hơn cái thứ hai

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 174 nếu cái đầu tiên được đặt thấp hơn cái thứ hai

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 100 nếu chúng được sắp xếp bằng nhau

Ví dụ sau đây đã cho tất cả chúng ta biết một đối chiếu sắp xếp ngược lại

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 18

Xóa hiệu suất cao đối chiếu bằng phương pháp đặt hoàn toàn có thể gọi thành

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43

Đã thay đổi trong phiên bản 3. 11. Tên đối chiếu hoàn toàn có thể chứa bất kỳ ký tự Unicode nào. Trước đó, chỉ những ký tự ASCII được phép.

gián đoạn() ¶

Gọi phương thức này từ một luồng khác để hủy bỏ mọi truy vấn hoàn toàn có thể đang thực thi trên link. Các truy vấn bị hủy bỏ sẽ đưa ra một ngoại lệ

set_authorizer(authorizer_callback) ¶

Đăng ký ủy quyền hoàn toàn có thể gọi được để được gọi cho từng lần nỗ lực truy cập một cột của bảng trong cơ sở tài liệu. Cuộc gọi lại phải trả về một trong số

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 135, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 136 hoặc cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 138 để báo hiệu cách thư viện SQLite phía dưới xử lý quyền truy cập vào cột

Đối số đầu tiên cho cuộc gọi lại biểu thị loại hoạt động và sinh hoạt giải trí nào sẽ được ủy quyền. Đối số thứ hai và thứ ba sẽ là đối số hoặc

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43 tùy thuộc vào đối số thứ nhất. Đối số thứ 4 là tên gọi của cơ sở tài liệu (“main”, “temp”, v.v. ) nếu có. Đối số thứ 5 là tên gọi của trình kích hoạt hoặc chính sách xem trong cùng phụ trách cho nỗ lực truy cập hoặc cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43 nếu nỗ lực truy cập này trực tiếp từ mã SQL đầu vào

Vui lòng tham khảo tài liệu SQLite về những giá trị hoàn toàn có thể có cho đối số thứ nhất và ý nghĩa của đối số thứ hai và thứ ba tùy thuộc vào đối số thứ nhất. Tất cả những hằng số thiết yếu đều có sẵn trong mô-đun

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0

Chuyển

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43 dưới dạng ủy quyền_callback sẽ vô hiệu hóa trình ủy quyền

Đã thay đổi trong phiên bản 3. 11. Đã thêm tương hỗ để tắt trình ủy quyền bằng phương pháp sử dụng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43. set_progress_handler(progress_handler , n)¶

Đăng ký process_handler hoàn toàn có thể gọi để được gọi cho từng n hướng dẫn của máy ảo SQLite. Điều này hữu ích nếu bạn muốn được gọi từ SQLite trong những hoạt động và sinh hoạt giải trí sinh hoạt chạy dài, ví dụ như để update GUI

Nếu bạn muốn xóa bất kỳ trình xử lý tiến trình nào đã setup trước đó, hãy gọi phương thức bằng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43 cho process_handler

Trả về một giá trị khác 0 từ hàm xử lý sẽ chấm hết truy vấn hiện giờ đang thực hiện và khiến truy vấn tăng ngoại lệ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 505set_trace_callback(trace_callback) ¶

Đăng ký dấu vết gọi lại hoàn toàn có thể gọi được để được gọi cho từng câu lệnh SQL thực sự được thực thi bởi phần phụ trợ SQLite

Đối số duy nhất được truyền cho lệnh gọi lại là câu lệnh (dưới dạng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 79) đang được thực thi. Giá trị trả về của cuộc gọi lại bị bỏ qua. Lưu ý rằng chương trình phụ trợ không riêng gì có chạy những câu lệnh được truyền cho những phương thức cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 507. Các nguồn khác gồm có quản lý thanh toán giao dịch thanh toán của mô-đun cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 và việc thực thi những trình kích hoạt được xác định trong cơ sở tài liệu hiện tại.

Vượt qua

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43 dưới dạng trace_callback sẽ vô hiệu hóa lệnh gọi lại theo dõi

Ghi chú

Các ngoại lệ được đưa ra trong cuộc gọi lại theo dõi không được phổ biến. Là một công cụ tương hỗ phát triển và gỡ lỗi, hãy sử dụng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 510 để được cho phép in truy nguyên từ những ngoại lệ được đưa ra trong lệnh gọi lại theo dõi

Mới trong phiên bản 3. 3

enable_load_extension(đã bật , /)¶

Cho phép công cụ SQLite tải những tiện ích mở rộng SQLite từ thư viện dùng chung nếu được bật là

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 106; . Các tiện ích mở rộng SQLite hoàn toàn có thể xác định những hiệu suất cao mới, tổng hợp hoặc triển khai bảng ảo hoàn toàn mới. Một phần mở rộng nổi tiếng là phần mở rộng tìm kiếm toàn văn được phân phối với SQLite

Ghi chú

Mô-đun

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 không được xây dựng với tương hỗ tiện ích mở rộng hoàn toàn có thể tải theo mặc định, vì một số trong những nền tảng (đặc biệt là macOS) có những thư viện SQLite được biên dịch mà không còn tính năng này. Để nhận tương hỗ tiện ích mở rộng hoàn toàn có thể tải, bạn phải vượt qua tùy chọn cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 513 để định thông số kỹ thuật

Tăng sự kiện kiểm tra

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 514 với những đối số cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 515, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 516.

Mới trong phiên bản 3. 2

Đã thay đổi trong phiên bản 3. 10. Đã thêm sự kiện kiểm tra

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 514.

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 19load_extension(đường dẫn , /)¶

Tải tiện ích mở rộng SQLite từ thư viện dùng chung có tại đường dẫn. Cho phép tải tiện ích mở rộng bằng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 518 trước khi gọi phương thức này

Tăng sự kiện kiểm tra

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 519 với những đối số cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 515, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 521.

Mới trong phiên bản 3. 2

Đã thay đổi trong phiên bản 3. 10. Đã thêm sự kiện truy thuế kiểm toán

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 519. iterdump() ¶

Trả về một trình lặp để kết xuất cơ sở tài liệu dưới dạng mã nguồn SQL. Hữu ích khi lưu cơ sở tài liệu trong bộ nhớ để phục hồi sau này. Tương tự như lệnh

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 523 trong shell sqlite3.

Ví dụ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 50 dự trữ(tiềm năng , *, pages=- 1, progress=None, name='main', sleep=0.250) ¶

Tạo bản sao lưu của cơ sở tài liệu SQLite

Hoạt động trong cả những lúc cơ sở tài liệu đang được truy cập bởi những máy khách khác hoặc đồng thời bởi cùng một link

Thông số

    đích (Kết nối) – Kết nối cơ sở tài liệu để lưu bản sao lưu vào

    pages (int) – Số trang cần sao chép cùng một lúc. Nếu bằng hoặc nhỏ hơn

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 100, toàn bộ cơ sở tài liệu sẽ được sao chép trong một bước. Mặc định là cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 174

    tiến trình ( gọi lại . Không có) – Nếu được đặt thành hoàn toàn có thể gọi được, thì nó được gọi với ba đối số nguyên cho từng lần lặp sao lưu. trạng thái của lần lặp ở đầu cuối, số trang còn sót lại vẫn được sao chép và tổng số trang. Mặc định là

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43.

    name (str) – Tên của cơ sở tài liệu để sao lưu.

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 163 (mặc định) cho cơ sở tài liệu chính, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 528 cho cơ sở tài liệu tạm thời hoặc tên của cơ sở tài liệu tùy chỉnh như được đính kèm bằng phương pháp sử dụng câu lệnh SQL cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 529

    ngủ (float) – Số giây để ngủ giữa mỗi lần thử liên tục để sao lưu những trang còn sót lại

Ví dụ 1, sao chép một cơ sở tài liệu hiện có sang một cơ sở tài liệu khác

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 51

Ví dụ 2, sao chép cơ sở tài liệu hiện có vào một bản sao tạm thời

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 52

Mới trong phiên bản 3. 7

getlimit(khuôn khổ , /)¶

Nhận số lượng giới hạn thời gian chạy link

Thông số

khuôn khổ (int) – Danh mục số lượng giới hạn SQLite được truy vấn

loại trả lại

int

tăng

Lỗi lập trình - Nếu khuôn khổ không được thư viện SQLite phía dưới nhận dạng

Ví dụ, truy vấn độ dài tối đa của câu lệnh SQL cho

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7 cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 8 (mặc định là 1000000000)

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 53

Mới trong phiên bản 3. 11

setlimit(khuôn khổ , số lượng giới hạn, /)¶

Đặt số lượng giới hạn thời gian chạy link. Nỗ lực tăng số lượng giới hạn trên số lượng giới hạn trên cứng của nó bị cắt ngắn một cách lặng lẽ đến số lượng giới hạn trên cứng. Bất kể số lượng giới hạn có bị thay đổi hay là không, giá trị trước đó của số lượng giới hạn được trả về

Thông số

    khuôn khổ (int) – Danh mục số lượng giới hạn SQLite sẽ được đặt

    số lượng giới hạn (int) – Giá trị của số lượng giới hạn mới. Nếu âm, số lượng giới hạn hiện tại không thay đổi

loại trả lại

int

tăng

Lỗi lập trình - Nếu khuôn khổ không được thư viện SQLite phía dưới nhận dạng

Ví dụ, số lượng giới hạn số lượng cơ sở tài liệu đính kèm là một trong cho

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7 cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 8 (số lượng giới hạn mặc định là 10)

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 54

Mới trong phiên bản 3. 11

xếp thứ tự(* , tên='main')¶

Tuần tự hóa cơ sở tài liệu thành một đối tượng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 124. Đối với một tệp cơ sở tài liệu trên đĩa thông thường, việc tuần tự hóa chỉ là một bản sao của tệp đĩa. Đối với cơ sở tài liệu trong bộ nhớ hoặc cơ sở tài liệu “tạm thời”, tuần tự hóa là cùng một chuỗi byte sẽ được ghi vào đĩa nếu cơ sở tài liệu đó được sao lưu vào đĩaThông số

name (str) – Tên cơ sở tài liệu sẽ được sắp xếp theo thứ tự. Mặc định là

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 163loại trả lại

byte

Ghi chú

Phương pháp này chỉ khả dụng nếu thư viện SQLite cơ bản có API tuần tự hóa

Mới trong phiên bản 3. 11

giải tuần tự hóa(tài liệu , /, *, name='main')¶

Giải tuần tự hóa cơ sở tài liệu

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 536 thành một cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7. Phương pháp này khiến link cơ sở tài liệu bị ngắt link khỏi tên cơ sở tài liệu và mở lại tên dưới dạng cơ sở tài liệu trong bộ nhớ nhờ vào tuần tự hóa có trong dữ liệuThông số

    tài liệu (byte) – Cơ sở tài liệu tuần tự hóa

    name (str) – Tên cơ sở tài liệu để giải tuần tự hóa thành. Mặc định là

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 163
tăng

    OperationalError – Nếu link cơ sở tài liệu hiện giờ đang tham gia vào một thanh toán giao dịch thanh toán đọc hoặc một hoạt động và sinh hoạt giải trí sao lưu

    DatabaseError – Nếu tài liệu không chứa cơ sở tài liệu SQLite hợp lệ

    OverflowError - Nếu

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 539 to hơn cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 540

Ghi chú

Phương pháp này chỉ khả dụng nếu thư viện SQLite phía dưới có API deserialize

Mới trong phiên bản 3. 11

in_transaction ¶

Thuộc tính chỉ đọc này tương ứng với chính sách tự động ký SQLite thấp cấp

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 106 nếu một thanh toán giao dịch thanh toán đang hoạt động và sinh hoạt giải trí (có những thay đổi không được cam kết), cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 107 nếu không

Mới trong phiên bản 3. 2

cấp_độ cô lập ¶

Thuộc tính này trấn áp xử lý thanh toán giao dịch thanh toán do

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 thực hiện. Nếu được đặt thành cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43, những thanh toán giao dịch thanh toán sẽ không bao giờ được mở hoàn toàn. Nếu được đặt thành một trong số cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 102, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 104 hoặc cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 103, tương ứng với hành vi thanh toán giao dịch thanh toán SQLite cơ bản, thì quản lý thanh toán giao dịch thanh toán ngầm được thực hiện.

Nếu không biến thành ghi đè bởi tham số Isolation_level của

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 125, giá trị mặc định là cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 549, là bí danh của cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 102row_factory ¶

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 551 ban đầu cho những đối tượng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 được tạo từ link này. Việc gán cho thuộc tính này sẽ không ảnh hưởng đến cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 551 con trỏ hiện có thuộc link này, chỉ những con trỏ mới. Là cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43 theo mặc định, nghĩa là mỗi hàng được trả về dưới dạng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09

Xem Cách tạo và sử dụng những xưởng tạo hàng để biết thêm rõ ràng.

text_factory ¶

Một kĩ năng gọi được đồng ý một tham số

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 124 và trả về một đại diện văn bản của nó. Có thể gọi được gọi cho những giá trị SQLite với kiểu tài liệu cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 557. Theo mặc định, thuộc tính này được đặt thành cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 79. Thay vào đó, nếu bạn muốn trả lại cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 124, hãy đặt text_factory thành cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 124

Ví dụ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 55total_changes ¶

Trả về tổng số hàng cơ sở tài liệu đã được sửa đổi, chèn hoặc xóa Tính từ lúc lúc link cơ sở tài liệu được mở

Đối tượng con trỏ¶

Một đối tượng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 đại diện cho một con trỏ cơ sở tài liệu được sử dụng để thực thi những câu lệnh SQL và quản lý ngữ cảnh của thao tác tìm nạp. Con trỏ được tạo bằng phương pháp sử dụng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 562 hoặc bằng phương pháp sử dụng bất kỳ phương thức phím tắt link nào .

Đối tượng con trỏ là trình lặp , nghĩa là nếu bạn

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 119 một truy vấn cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 48, bạn hoàn toàn có thể chỉ việc lặp lại con trỏ để tìm nạp những hàng kết quả.

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 56lớp sqlite3. Con trỏ ¶

Một phiên bản

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 có những thuộc tính và phương thức sauthực thi(sql , tham số=(), /)¶

Thực thi câu lệnh SQL sql. Liên kết những giá trị với câu lệnh bằng phương pháp sử dụng phần giữ chỗ ánh xạ tới trình tự hoặc

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 566 .

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 119 sẽ chỉ thực thi một câu lệnh SQL duy nhất. Nếu bạn nỗ lực thực hiện nhiều hơn nữa một câu lệnh với nó, thì nó sẽ tăng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 568. Sử dụng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 173 nếu bạn muốn thực thi nhiều câu lệnh SQL với một lệnh gọi

Nếu

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 101 không phải là cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43, thì sql là một câu lệnh cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 44, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 573, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 574 hoặc cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 575 và không còn thanh toán giao dịch thanh toán mở, một thanh toán giao dịch thanh toán được mở hoàn toàn trước khi thực hiện sqlexecutemany(sql , tham số, /)¶

Thực thi được tham số hóa Câu lệnh SQL sql đối với tất cả những trình tự tham số hoặc ánh xạ được tìm thấy trong những tham số trình tự. Cũng hoàn toàn có thể sử dụng một iterator đáp ứng những tham số thay vì một chuỗi. Sử dụng xử lý thanh toán giao dịch thanh toán ngầm in như

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 119.

Ví dụ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 57executescript(sql_script , /)¶

Thực thi những câu lệnh SQL trong sql_script. Nếu có một thanh toán giao dịch thanh toán đang chờ xử lý, một câu lệnh ngầm

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 577 sẽ được thực hiện trước. Không có trấn áp thanh toán giao dịch thanh toán ngầm nào khác được thực hiện;

sql_script phải là một

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 147

Ví dụ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 58tìm nạp() ¶

Nếu

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 551 là cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43, hãy trả về kết quả truy vấn hàng tiếp theo được đặt là cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09. Khác, chuyển nó đến nhà máy sản xuất sản xuất hàng và trả về kết quả của nó. Trả lại cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43 nếu không còn thêm dữ liệufetchmany(size=con trỏ. kích thước mảng) ¶

Trả về nhóm hàng tiếp theo của kết quả truy vấn dưới dạng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 72. Trả về list trống nếu không hề hàng nào nữa

Số lượng hàng cần tìm nạp cho từng cuộc gọi được chỉ định bởi tham số kích thước. Nếu kích thước không được đáp ứng,

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 584 sẽ xác định số lượng hàng sẽ được tìm nạp. Nếu có ít hàng hơn kích thước, số hàng có sẵn sẽ được trả về

Lưu ý rằng có những xem xét về hiệu suất liên quan đến tham số kích thước. Để có hiệu suất tối ưu, tốt nhất nên sử dụng thuộc tính arraysize. Nếu tham số kích thước được sử dụng, thì tốt nhất là không thay đổi giá trị từ cuộc gọi

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 585 này sang cuộc gọi tiếp theotìm nạp() ¶

Trả về tất cả những hàng (còn sót lại) của kết quả truy vấn dưới dạng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 72. Trả về list trống nếu không còn hàng nào. Lưu ý rằng thuộc tính cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 584 hoàn toàn có thể ảnh hưởng đến hiệu suất của thao tác nàyđóng() ¶

Đóng con trỏ ngay giờ đây (chứ không phải bất kể lúc nào

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 588 được gọi)

Con trỏ sẽ không sử dụng được từ thời điểm này trở đi;

setinputsizes(kích thước , /)¶

Yêu cầu bởi DB-API. Không làm gì trong

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0setoutputsize(kích thước , cột=None, /)¶

Yêu cầu bởi DB-API. Không làm gì trong

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0kích thước mảng ¶

Thuộc tính đọc/ghi trấn áp số hàng được trả về bởi

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 585. Giá trị mặc định là một trong nghĩa là một hàng sẽ được tìm nạp cho từng cuộc gọikết nối ¶

Thuộc tính chỉ đọc đáp ứng cơ sở tài liệu SQLite

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7 thuộc về con trỏ. Đối tượng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 được tạo bằng phương pháp gọi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 9 sẽ có thuộc tính cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 515 đề cập đến con

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 59mô tả ¶

Thuộc tính chỉ đọc đáp ứng tên cột của truy vấn ở đầu cuối. Để duy trì kĩ năng tương thích với API Python DB, nó trả về 7-bộ cho từng cột trong đó sáu mục ở đầu cuối của mỗi bộ là

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43

Nó cũng khá được đặt cho những câu lệnh

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 48 mà không còn bất kỳ hàng nào phù hợplastrowid ¶

Thuộc tính chỉ đọc đáp ứng id hàng của hàng được chèn ở đầu cuối. Nó chỉ được update sau khi câu lệnh

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 44 hoặc cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 575 thành công sử dụng phương pháp cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 119. Đối với những câu lệnh khác, sau cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 171 hoặc cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 173 hoặc nếu chèn không thành công, giá trị của cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 104 sẽ không thay đổi. Giá trị ban đầu của cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 104 là cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43

Ghi chú

Chèn vào bảng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 164 không được ghi lại

Đã thay đổi trong phiên bản 3. 6. Đã thêm tương hỗ cho câu lệnh

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 575. số hàng ¶

Thuộc tính chỉ đọc đáp ứng số lượng hàng đã sửa đổi cho những câu lệnh

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 44, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 573, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 574 và cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 575; . Nó chỉ được update bằng những phương pháp cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 119 và cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 171row_factory ¶

Kiểm soát cách trình bày một hàng được tìm nạp từ cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 này. Nếu cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43, một hàng được màn biểu diễn dưới dạng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09. Có thể được đặt thành cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 119 đi kèm; . callable that accepts two arguments, a

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 object and the cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09 of row values, and returns a custom object representing an SQLite row.

Mặc định là những gì

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 122 đã được đặt khi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 được tạo. Việc gán cho thuộc tính này sẽ không ảnh hưởng đến cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 122 của link chính

Xem Cách tạo và sử dụng những xưởng tạo hàng để biết thêm rõ ràng.

Đối tượng hàng¶

lớp sqlite3. Hàng ¶

Một phiên bản

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 125 đóng vai trò là một cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 551 được tối ưu hóa cao cho những đối tượng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7. Nó tương hỗ phép lặp, kiểm tra đẳng thức, truy cập cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 128 và ánh xạ theo tên cột và chỉ mục.

Hai đối tượng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 125 so sánh bằng nhau nếu chúng mang tên và giá trị cột giống hệt nhau

Xem Cách tạo và sử dụng những xưởng tạo hàng để biết thêm rõ ràng.

phím() ¶

Trả lại một

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 72 tên cột là cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 131. Ngay sau một truy vấn, nó là phần tử đầu tiên của mỗi bộ trong cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 132

Đã thay đổi trong phiên bản 3. 5. Đã thêm tương hỗ cắt lát.

Đối tượng đốm màu¶

Mới trong phiên bản 3. 11

lớp sqlite3. Blob ¶

Phiên bản

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 160 là một đối tượng dạng tệp hoàn toàn có thể đọc và ghi tài liệu trong SQLite BLOB. Gọi cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 134 để lấy kích thước (số byte) của đốm màu. Sử dụng những chỉ số và lát để truy cập trực tiếp vào tài liệu blob.

Sử dụng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 160 làm trình quản lý ngữ cảnh để đảm nói rằng tay cầm blob được đóng lại sau khi sử dụng.

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 10đóng() ¶

Đóng đốm màu

Blob sẽ không sử dụng được từ thời điểm này trở đi. Một ngoại lệ

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 136 (hoặc phân lớp) sẽ được đưa ra nếu có bất kỳ thao tác nào tiếp theo được thực hiện với blobđọc(độ dài=- 1, /)¶

Đọc những byte tài liệu có độ dài từ đốm màu ở vị trí bù hiện tại. Nếu đạt đến cuối đốm màu, tài liệu lên tới EOF sẽ được trả về. Khi độ dài không được chỉ định hoặc là số âm,

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 137 sẽ đọc cho tới hết đốm màughi(tài liệu , /)¶

Ghi tài liệu vào đốm màu ở phần bù hiện tại. Chức năng này sẽ không thể thay đổi độ dài blob. Viết vượt quá phần cuối của đốm màu sẽ tăng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 138kể() ¶

Trả về vị trí truy cập hiện tại của blob

tìm kiếm(bù , gốc=os.SEEK_SET , /) ¶

Đặt vị trí truy cập hiện tại của blob thành offset. Đối số gốc mặc định là

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 139 (định vị đốm màu tuyệt đối). Các giá trị khác cho nguồn gốc là cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 140 (tìm kiếm liên quan đến vị trí hiện tại) và cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 141 (tìm kiếm liên quan đến phần cuối của blob)

Chuẩn bị đối tượngProtocol¶

lớp sqlite3. Chuẩn bị giao thức ¶

Mục đích duy nhất của loại PrepareProtocol là hoạt động và sinh hoạt giải trí như một giao thức thích ứng kiểu PEP 246 cho những đối tượng hoàn toàn có thể tự thích ứng để native SQLite types.

Ngoại lệ¶

Hệ thống phân cấp ngoại lệ được xác định bởi DB-API 2. 0 (PEP 249)

ngoại lệ sqlite3. Cảnh báo ¶

Ngoại lệ này hiện không được mô-đun

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 đưa ra, nhưng hoàn toàn có thể được đưa ra bởi những ứng dụng sử dụng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0, ví dụ: nếu hàm do người tiêu dùng xác định cắt bớt tài liệu trong khi chèn. cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 144 là một lớp con của cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 145 ngoại lệ sqlite3. Lỗi ¶

Lớp cơ sở của những ngoại lệ khác trong mô-đun này. Sử dụng điều này để bắt tất cả những lỗi với một câu lệnh

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 146 duy nhất. cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 136 is a subclass of cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 145

If the exception originated from within the SQLite library, the following two attributes are added to the exception

sqlite_errorcode ¶

The numeric error code from the SQLite API

Mới trong phiên bản 3. 11

sqlite_errorname ¶

Tên tượng trưng của mã lỗi số từ API SQLite

Mới trong phiên bản 3. 11

exception sqlite3. InterfaceError ¶

Ngoại lệ được đưa ra do lạm dụng API SQLite C thấp cấp. In other words, if this exception is raised, it probably indicates a bug in the

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 module. cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 150 là một lớp con của cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 136ngoại lệ sqlite3. DatabaseError ¶

Exception raised for errors that are related to the database. This serves as the base exception for several types of database errors. It is only raised implicitly through the specialised subclasses.

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 152 is a subclass of cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 136exception sqlite3. Lỗi tài liệu ¶

Exception raised for errors caused by problems with the processed data, like numeric values out of range, and strings which are too long.

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 154 là một lớp con của cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 152exception sqlite3. OperationalError ¶

Exception raised for errors that are related to the database’s operation, and not necessarily under the control of the programmer. For example, the database path is not found, or a transaction could not be processed.

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 505 is a subclass of cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 152exception sqlite3. IntegrityError ¶

Exception raised when the relational integrity of the database is affected, e. g. a foreign key check fails. It is a subclass of

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 152exception sqlite3. InternalError ¶

Exception raised when SQLite encounters an internal error. If this is raised, it may indicate that there is a problem with the runtime SQLite library.

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 159 is a subclass of cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 152ngoại lệ sqlite3. ProgrammingError ¶

Exception raised for

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 API programming errors, for example supplying the wrong number of bindings to a query, or trying to operate on a closed cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7. cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 568 is a subclass of cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 152exception sqlite3. NotSupportedError ¶

Exception raised in case a method or database API is not supported by the underlying SQLite library. For example, setting deterministic to

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 106 in cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 166, if the underlying SQLite library does not support deterministic functions. cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 167 is a subclass of cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 152

SQLite and Python types¶

SQLite natively supports the following types.

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 137, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 170, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 171, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 557, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 173

The following Python types can thus be sent to SQLite without any problem

Python type

SQLite type

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 137

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 176

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 170

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 178

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 171

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 79

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 557

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 124

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 173

Đây là cách nhiều chủng loại SQLite được quy đổi thành nhiều chủng loại Python theo mặc định

SQLite type

Python type

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 137

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 170

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 176

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 171

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 178

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 557

phụ thuộc vào

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 191, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 79 theo mặc định

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 173

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 124

Hệ thống loại của mô-đun

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 hoàn toàn có thể mở rộng theo hai cách. bạn hoàn toàn có thể tàng trữ nhiều chủng loại Python tương hỗ update trong cơ sở tài liệu SQLite qua bộ điều hợp đối tượng và bạn hoàn toàn có thể để mô-đun cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 quy đổi nhiều chủng loại SQLite thành nhiều chủng loại Python qua converters.

Bộ điều hợp và bộ quy đổi mặc định¶

Có những bộ điều hợp mặc định cho những loại ngày và giờ trong mô-đun ngày giờ. Chúng sẽ được gửi dưới dạng ngày ISO/dấu thời gian ISO tới SQLite

Bộ quy đổi mặc định được đăng ký dưới tên “ngày” cho

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 197 và dưới tên “dấu thời gian” cho cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 198

Bằng cách này, bạn hoàn toàn có thể sử dụng ngày/dấu thời gian từ Python mà không cần thêm bất kỳ thao tác nào trong hầu hết những trường hợp. Định dạng của cục điều hợp cũng tương thích với những hàm ngày/giờ SQLite thử nghiệm

Ví dụ sau minh họa điều này

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 11

Nếu dấu thời gian được tàng trữ trong SQLite có phần phân số dài hơn thế nữa 6 số, thì giá trị của dấu thời gian đó sẽ bị bộ quy đổi dấu thời gian cắt ngắn thành độ đúng chuẩn micro giây

Ghi chú

Trình quy đổi “dấu thời gian” mặc định bỏ qua những giá trị bù UTC trong cơ sở tài liệu và luôn trả về một đối tượng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 198 ngây thơ. Để duy trì độ lệch UTC trong dấu thời gian, hãy tắt bộ quy đổi hoặc đăng ký bộ quy đổi nhận ra độ lệch với cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 74

Làm thế nào để hướng dẫn¶

Cách sử dụng trình giữ chỗ để link những giá trị trong truy vấn SQL¶

Các hoạt động và sinh hoạt giải trí SQL thường cần sử dụng những giá trị từ những biến Python. Tuy nhiên, hãy thận trọng khi sử dụng những thao tác chuỗi của Python để lắp ráp những truy vấn, vì chúng dễ bị tấn công SQL injection. Ví dụ: kẻ tấn công hoàn toàn có thể chỉ việc đóng một trích dẫn và đưa vào

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 701 để chọn tất cả những hàng

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 12

Thay vào đó, hãy sử dụng thay thế tham số của DB-API. Để chèn một biến vào một chuỗi truy vấn, hãy sử dụng một trình giữ chỗ trong chuỗi và thay thế những giá trị thực tế vào truy vấn bằng phương pháp đáp ứng chúng dưới dạng một

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09 giá trị cho đối số thứ hai của phương thức cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 119 của con trỏ. Một câu lệnh SQL hoàn toàn có thể sử dụng một trong hai loại trình giữ chỗ. dấu chấm hỏi (kiểu qmark) hoặc trình giữ chỗ được đặt tên (kiểu được đặt tên). Đối với kiểu qmark, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 704 phải là một trình tự . Đối với kiểu được đặt tên, nó hoàn toàn có thể là một trình tự hoặc phiên bản cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 566. Độ dài của chuỗi phải phù phù phù hợp với số lượng phần giữ chỗ, nếu không một số trong những cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 568 sẽ tăng lên. Nếu một cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 566 được đáp ứng, nó phải chứa những khóa cho tất cả những tham số được đặt tên. Bất kỳ mục tương hỗ update được bỏ qua. Đây là một ví dụ về cả hai phong cách.

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 13

Cách điều chỉnh nhiều chủng loại Python tùy chỉnh thành những giá trị SQLite¶

SQLite chỉ tương hỗ một số trong những loại tài liệu hạn chế. Để tàng trữ nhiều chủng loại Python tùy chỉnh trong cơ sở tài liệu SQLite, hãy điều chỉnh chúng theo một trong Các loại Python mà SQLite hiểu được .

Có hai phương pháp để điều chỉnh những đối tượng Python thành những kiểu SQLite. để đối tượng của bạn tự điều chỉnh hoặc sử dụng bộ điều hợp hoàn toàn có thể gọi được. Cái sau sẽ được ưu tiên hơn cái trước. Đối với một thư viện xuất một loại tùy chỉnh, hoàn toàn có thể hợp lý khi được cho phép loại đó tự điều chỉnh. Với tư cách là nhà phát triển ứng dụng, việc trấn áp trực tiếp bằng phương pháp đăng ký những hiệu suất cao của cục điều hợp tùy chỉnh hoàn toàn có thể hợp lý hơn

Cách viết những đối tượng hoàn toàn có thể thích ứng¶

Suppose we have a

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 708 class that represents a pair of coordinates, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 709 and cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 710, in a Cartesian coordinate system. Cặp tọa độ sẽ được tàng trữ dưới dạng chuỗi văn bản trong cơ sở tài liệu, sử dụng dấu chấm phẩy để phân tách tọa độ. Điều này hoàn toàn có thể được thực hiện bằng phương pháp thêm phương thức cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 711 trả về giá trị đã điều chỉnh. The object passed to protocol will be of type cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 712

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 14How to register adapter callables¶

Khả năng khác là tạo một hàm quy đổi đối tượng Python thành loại tương thích với SQLite. This function can then be registered using

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 713

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 15

How to convert SQLite values to custom Python types¶

Writing an adapter lets you convert from custom Python types to SQLite values. To be able to convert from SQLite values to custom Python types, we use converters

Let’s go back to the

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 708 class. We stored the x and y coordinates separated via semicolons as strings in SQLite

First, we’ll define a converter function that accepts the string as a parameter and constructs a

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 708 object from it

Ghi chú

Converter functions are always passed a

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 124 object, no matter the underlying SQLite data type

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 16

We now need to tell

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 when it should convert a given SQLite value. This is done when connecting to a database, using the detect_types parameter of cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 125. There are three options

    Implicit. set detect_types to

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 76

    Explicit. set detect_types to

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 77

    Both. set detect_types to

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 721. Tên cột được ưu tiên hơn nhiều chủng loại đã khai báo

The following example illustrates the implicit and explicit approaches

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 17

Adapter and converter recipes¶

This section shows recipes for common adapters and converters

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 18

How to use connection shortcut methods¶

Using the

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 119, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 171, and cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 173 methods of the cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7 class, your code can be written more concisely because you don’t have to create the (often superfluous) cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 objects explicitly. Instead, the cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 objects are created implicitly and these shortcut methods return the cursor objects. This way, you can execute a cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 48 statement and iterate over it directly using only a single call on the cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7 object

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 19

How to use the connection context manager¶

A

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7 object can be used as a context manager that automatically commits or rolls back open transactions when leaving the body toàn thân of the context manager. If the body toàn thân of the cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 731 statement finishes without exceptions, the transaction is committed. If this commit fails, or if the body toàn thân of the cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 731 statement raises an uncaught exception, the transaction is rolled back

If there is no open transaction upon leaving the body toàn thân of the

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 731 statement, the context manager is a no-op

Ghi chú

The context manager neither implicitly opens a new transaction nor closes the connection

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 70

How to work with SQLite URIs¶

Some useful URI tricks include

    Open a database in read-only mode

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 71

    Do not implicitly create a new database file if it does not already exist; will raise

    cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 505 if unable to create a new file

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 72

    Create a shared named in-memory database

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 73

More information about this feature, including a list of parameters, can be found in the SQLite URI documentation

How to create and use row factories¶

By default,

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 represents each row as a cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09. If a cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09 does not suit your needs, you can use the cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 119 class or a custom cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 551

Mặc dù

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 551 tồn tại như một thuộc tính trên cả cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 00 và cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 7, nhưng bạn nên đặt cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 122, vì vậy tất cả những con trỏ được tạo từ link sẽ sử dụng cùng một hàng.

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 125 provides indexed and case-insensitive named access to columns, with minimal memory overhead and performance impact over a cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09. Để sử dụng cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 125 làm nhà sản xuất hàng, hãy gán nó cho thuộc tính cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 551

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 74

Queries now return

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 125 objects

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 75

You can create a custom

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 551 that returns each row as a cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 566, with column names mapped to values

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 76

Using it, queries now return a

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 566 instead of a cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 09

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 77

The following row factory returns a named tuple .

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 78

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 753 can be used as follows

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 79

With some adjustments, the above recipe can be adapted to use a

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 754, or any other custom class, instead of a cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 755

Explanation¶

Transaction control¶

The

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 module does not adhere to the transaction handling recommended by PEP 249

If the connection attribute

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 101 is not cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43, new transactions are implicitly opened before cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 119 and cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 171 executes cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 44, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 573, cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 574, or cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 575 statements; for other statements, no implicit transaction handling is performed. Use the cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 167 and cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 766 methods to respectively commit and roll back pending transactions. Bạn hoàn toàn có thể chọn hành vi thanh toán giao dịch thanh toán SQLite cơ bản — nghĩa là, liệu và loại câu lệnh cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 767 mà cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 0 có thực thi ngầm hay là không — thông qua thuộc tính cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 101

If

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 101 is set to cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 43, no transactions are implicitly opened all. This leaves the underlying SQLite library in autocommit mode, but also allows the user to perform their own transaction handling using explicit SQL statements. The underlying SQLite library autocommit mode can be queried using the cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 772 attribute

The

cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 173 method implicitly commits any pending transaction before execution of the given SQL script, regardless of the value of cur.execute(""" INSERT INTO movie VALUES ('Monty Python and the Holy Grail', 1975, 8.2), ('And Now for Something Completely Different', 1971, 7.5) """) 101

Can I run SQL query in Python?

Một cách nhanh gọn và thuận tiện và đơn giản để hoàn toàn có thể chạy những truy vấn SQL bằng Python là sử dụng SQLite . SQLite is a library that utilizes an SQL database engine. It performs relatively fast and has been proven to be highly reliable. SQLite is the most commonly used database engine in the test environment.

How to build SQL query in Python?

Truy vấn SQL trong Python . Bước 1. Nhập SQLAlchemy và Pandas. Hãy khởi đầu với việc nhập thư viện sqlalchemy. . Bước 2. Tạo một công cụ SQL. Chúng tôi tạo một công cụ SQL bằng phương pháp sử dụng lệnh tạo một lớp mới '. . Bước 3 — Chạy truy vấn bằng câu lệnh SQL. . Bước 4 — Viết thư cho DB. . Bước 5— Tạo bảng trong DB

Làm cách nào để sử dụng trình giữ chỗ trong truy vấn SQL bằng Python?

Chúng ta cần đáp ứng những giá trị trong trình giữ chỗ ( %s ) trước khi thực hiện truy vấn . Truyền những biến Python ở vị trí của trình giữ chỗ khi chúng tôi thực hiện truy vấn. Chúng ta cần truyền hai đối số sau cho một con trỏ. hàm exec() để chạy truy vấn được tham số hóa.

Làm cách nào để lấy tài liệu từ cơ sở tài liệu bằng Python?

Các bước tìm nạp hàng từ bảng cơ sở tài liệu MySQL . Kết nối với MySQL từ Python. . Xác định truy vấn CHỌN SQL. . Nhận đối tượng con trỏ từ link. . Thực thi truy vấn SELECT sử dụng phương thức exec(). . Trích xuất tất cả những hàng từ một kết quả. . Lặp lại từng hàng. . Đóng đối tượng con trỏ và đối tượng link cơ sở tài liệu Tải thêm tài liệu liên quan đến nội dung bài viết Trình trợ giúp Python SQL programming python

Review Trình trợ giúp Python SQL ?

Bạn vừa tham khảo tài liệu Với Một số hướng dẫn một cách rõ ràng hơn về Video Trình trợ giúp Python SQL tiên tiến nhất

Chia Sẻ Link Cập nhật Trình trợ giúp Python SQL miễn phí

Hero đang tìm một số trong những Chia Sẻ Link Cập nhật Trình trợ giúp Python SQL Free.

Thảo Luận thắc mắc về Trình trợ giúp Python SQL

Nếu sau khi đọc nội dung bài viết Trình trợ giúp Python SQL vẫn chưa hiểu thì hoàn toàn có thể lại phản hồi ở cuối bài để Ad lý giải và hướng dẫn lại nha #Trình #trợ #giúp #Python #SQL - 2022-12-25 10:35:11

Post a Comment