mirror of
https://github.com/python/cpython.git
synced 2024-11-24 02:15:30 +08:00
bpo-44106: Purge unused sqlite3 doc includes (GH-26234)
This commit is contained in:
parent
92d1064727
commit
d798acc873
@ -1,17 +0,0 @@
|
||||
import sqlite3
|
||||
|
||||
class CountCursorsConnection(sqlite3.Connection):
|
||||
def __init__(self, *args, **kwargs):
|
||||
sqlite3.Connection.__init__(self, *args, **kwargs)
|
||||
self.numcursors = 0
|
||||
|
||||
def cursor(self, *args, **kwargs):
|
||||
self.numcursors += 1
|
||||
return sqlite3.Connection.cursor(self, *args, **kwargs)
|
||||
|
||||
con = sqlite3.connect(":memory:", factory=CountCursorsConnection)
|
||||
cur1 = con.cursor()
|
||||
cur2 = con.cursor()
|
||||
print(con.numcursors)
|
||||
|
||||
con.close()
|
@ -1,28 +0,0 @@
|
||||
# Not referenced from the documentation, but builds the database file the other
|
||||
# code snippets expect.
|
||||
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
DB_FILE = "mydb"
|
||||
|
||||
if os.path.exists(DB_FILE):
|
||||
os.remove(DB_FILE)
|
||||
|
||||
con = sqlite3.connect(DB_FILE)
|
||||
cur = con.cursor()
|
||||
cur.execute("""
|
||||
create table lang
|
||||
(
|
||||
name varchar(20),
|
||||
first_appeared integer
|
||||
)
|
||||
""")
|
||||
|
||||
cur.execute("insert into lang (name, first_appeared) values ('Forth', 1970)")
|
||||
cur.execute("insert into lang (name, first_appeared) values ('Ada', 1980)")
|
||||
|
||||
con.commit()
|
||||
|
||||
cur.close()
|
||||
con.close()
|
@ -1,19 +0,0 @@
|
||||
import sqlite3
|
||||
|
||||
con = sqlite3.connect("mydb")
|
||||
|
||||
cur = con.cursor()
|
||||
SELECT = "select name, first_appeared from people order by first_appeared, name"
|
||||
|
||||
# 1. Iterate over the rows available from the cursor, unpacking the
|
||||
# resulting sequences to yield their elements (name, first_appeared):
|
||||
cur.execute(SELECT)
|
||||
for name, first_appeared in cur:
|
||||
print(f"The {name} programming language appeared in {first_appeared}.")
|
||||
|
||||
# 2. Equivalently:
|
||||
cur.execute(SELECT)
|
||||
for row in cur:
|
||||
print(f"The {row[0]} programming language appeared in {row[1]}.")
|
||||
|
||||
con.close()
|
@ -1,15 +0,0 @@
|
||||
import sqlite3
|
||||
|
||||
# Create a connection to the database file "mydb":
|
||||
con = sqlite3.connect("mydb")
|
||||
|
||||
# Get a Cursor object that operates in the context of Connection con:
|
||||
cur = con.cursor()
|
||||
|
||||
# Execute the SELECT statement:
|
||||
cur.execute("select * from lang order by first_appeared")
|
||||
|
||||
# Retrieve all rows as a sequence and print that sequence:
|
||||
print(cur.fetchall())
|
||||
|
||||
con.close()
|
@ -1,18 +0,0 @@
|
||||
import sqlite3
|
||||
|
||||
con = sqlite3.connect("mydb")
|
||||
|
||||
cur = con.cursor()
|
||||
|
||||
languages = (
|
||||
("Smalltalk", 1972),
|
||||
("Swift", 2014),
|
||||
)
|
||||
|
||||
for lang in languages:
|
||||
cur.execute("insert into lang (name, first_appeared) values (?, ?)", lang)
|
||||
|
||||
# The changes will not be saved unless the transaction is committed explicitly:
|
||||
con.commit()
|
||||
|
||||
con.close()
|
@ -1,10 +0,0 @@
|
||||
import sqlite3
|
||||
import datetime
|
||||
|
||||
con = sqlite3.connect(":memory:", detect_types=sqlite3.PARSE_COLNAMES)
|
||||
cur = con.cursor()
|
||||
cur.execute('select ? as "x [timestamp]"', (datetime.datetime.now(),))
|
||||
dt = cur.fetchone()[0]
|
||||
print(dt, type(dt))
|
||||
|
||||
con.close()
|
@ -1,6 +0,0 @@
|
||||
import sqlite3
|
||||
|
||||
# The shared cache is only available in SQLite versions 3.3.3 or later
|
||||
# See the SQLite documentation for details.
|
||||
|
||||
sqlite3.enable_shared_cache(True)
|
@ -1,25 +0,0 @@
|
||||
import sqlite3
|
||||
|
||||
FIELD_MAX_WIDTH = 20
|
||||
|
||||
con = sqlite3.connect("mydb")
|
||||
cur = con.cursor()
|
||||
cur.execute("select * from lang order by name, first_appeared")
|
||||
|
||||
# Print a header.
|
||||
for fieldDesc in cur.description:
|
||||
print(fieldDesc[0].ljust(FIELD_MAX_WIDTH), end=' ')
|
||||
print() # Finish the header with a newline.
|
||||
print('-' * 78)
|
||||
|
||||
# For each row, print the value of each field left-justified within
|
||||
# the maximum possible width of that field.
|
||||
fieldIndices = range(len(cur.description))
|
||||
for row in cur:
|
||||
for fieldIndex in fieldIndices:
|
||||
fieldValue = str(row[fieldIndex])
|
||||
print(fieldValue.ljust(FIELD_MAX_WIDTH), end=' ')
|
||||
|
||||
print() # Finish the row with a newline.
|
||||
|
||||
con.close()
|
Loading…
Reference in New Issue
Block a user