mirror of
https://github.com/python/cpython.git
synced 2025-10-05 06:31:48 +00:00
gh-95273: Condense sqlite3 executescript example (GH-95383)
(cherry picked from commit e9c8de669d
)
Co-authored-by: Erlend Egeberg Aasland <erlend.aasland@innova.no>
This commit is contained in:
parent
3e9a496b6b
commit
6eae15abb6
2 changed files with 9 additions and 27 deletions
|
@ -1,25 +0,0 @@
|
||||||
import sqlite3
|
|
||||||
|
|
||||||
con = sqlite3.connect(":memory:")
|
|
||||||
cur = con.cursor()
|
|
||||||
cur.executescript("""
|
|
||||||
create table person(
|
|
||||||
firstname,
|
|
||||||
lastname,
|
|
||||||
age
|
|
||||||
);
|
|
||||||
|
|
||||||
create table book(
|
|
||||||
title,
|
|
||||||
author,
|
|
||||||
published
|
|
||||||
);
|
|
||||||
|
|
||||||
insert into book(title, author, published)
|
|
||||||
values (
|
|
||||||
'Dirk Gently''s Holistic Detective Agency',
|
|
||||||
'Douglas Adams',
|
|
||||||
1987
|
|
||||||
);
|
|
||||||
""")
|
|
||||||
con.close()
|
|
|
@ -997,9 +997,16 @@ Cursor Objects
|
||||||
|
|
||||||
*sql_script* must be a :class:`string <str>`.
|
*sql_script* must be a :class:`string <str>`.
|
||||||
|
|
||||||
Example:
|
Example::
|
||||||
|
|
||||||
.. literalinclude:: ../includes/sqlite3/executescript.py
|
# cur is an sqlite3.Cursor object
|
||||||
|
cur.executescript("""
|
||||||
|
begin;
|
||||||
|
create table person(firstname, lastname, age);
|
||||||
|
create table book(title, author, published);
|
||||||
|
create table publisher(name, address);
|
||||||
|
commit;
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
.. method:: fetchone()
|
.. method:: fetchone()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue