Changeset 391 for python/trunk/Doc/includes/sqlite3
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 1 deleted
- 9 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Doc/includes/sqlite3/complete_statement.py
r2 r391 24 24 if buffer.lstrip().upper().startswith("SELECT"): 25 25 print cur.fetchall() 26 except sqlite3.Error ,e:26 except sqlite3.Error as e: 27 27 print "An error occurred:", e.args[0] 28 28 buffer = "" -
python/trunk/Doc/includes/sqlite3/ctx_manager.py
r2 r391 9 9 10 10 # con.rollback() is called after the with block finishes with an exception, the 11 # exception is still raised and must be ca tched11 # exception is still raised and must be caught 12 12 try: 13 13 with con: -
python/trunk/Doc/includes/sqlite3/execute_1.py
r2 r391 1 1 import sqlite3 2 2 3 con = sqlite3.connect("mydb") 4 3 con = sqlite3.connect(":memory:") 5 4 cur = con.cursor() 5 cur.execute("create table people (name_last, age)") 6 6 7 7 who = "Yeltsin" 8 8 age = 72 9 9 10 cur.execute("select name_last, age from people where name_last=? and age=?", (who, age)) 10 # This is the qmark style: 11 cur.execute("insert into people values (?, ?)", (who, age)) 12 13 # And this is the named style: 14 cur.execute("select * from people where name_last=:who and age=:age", {"who": who, "age": age}) 15 11 16 print cur.fetchone() -
python/trunk/Doc/includes/sqlite3/executemany_2.py
r2 r391 1 1 import sqlite3 2 import string 2 3 3 4 def char_generator(): 4 import string 5 for c in string.letters[:26]: 5 for c in string.lowercase: 6 6 yield (c,) 7 7 -
python/trunk/Doc/includes/sqlite3/rowclass.py
r2 r391 1 1 import sqlite3 2 2 3 con = sqlite3.connect(" mydb")3 con = sqlite3.connect(":memory:") 4 4 con.row_factory = sqlite3.Row 5 5 6 6 cur = con.cursor() 7 cur.execute("select name_last, age from people")7 cur.execute("select 'John' as name, 42 as age") 8 8 for row in cur: 9 assert row[0] == row["name _last"]10 assert row["name _last"] == row["nAmE_lAsT"]9 assert row[0] == row["name"] 10 assert row["name"] == row["nAmE"] 11 11 assert row[1] == row["age"] 12 12 assert row[1] == row["AgE"] -
python/trunk/Doc/includes/sqlite3/shared_cache.py
r2 r391 2 2 3 3 # The shared cache is only available in SQLite versions 3.3.3 or later 4 # See the SQLite documentat on for details.4 # See the SQLite documentation for details. 5 5 6 6 sqlite3.enable_shared_cache(True) -
python/trunk/Doc/includes/sqlite3/shortcut_methods.py
r2 r391 18 18 print row 19 19 20 # Using a dummy WHERE clause to not let SQLite take the shortcut table deletes. 21 print "I just deleted", con.execute("delete from person where 1=1").rowcount, "rows" 20 print "I just deleted", con.execute("delete from person").rowcount, "rows" -
python/trunk/Doc/includes/sqlite3/text_factory.py
r2 r391 3 3 con = sqlite3.connect(":memory:") 4 4 cur = con.cursor() 5 6 # Create the table7 con.execute("create table person(lastname, firstname)")8 5 9 6 AUSTRIA = u"\xd6sterreich" … … 18 15 cur.execute("select ?", (AUSTRIA,)) 19 16 row = cur.fetchone() 20 assert type(row[0]) ==str17 assert type(row[0]) is str 21 18 # the bytestrings will be encoded in UTF-8, unless you stored garbage in the 22 19 # database ... … … 30 27 u"\xe4\xf6\xfc".encode("latin1"),)) 31 28 row = cur.fetchone() 32 assert type(row[0]) ==unicode29 assert type(row[0]) is unicode 33 30 34 31 # sqlite3 offers a built-in optimized text_factory that will return bytestring … … 37 34 cur.execute("select ?", (AUSTRIA,)) 38 35 row = cur.fetchone() 39 assert type(row[0]) ==unicode36 assert type(row[0]) is unicode 40 37 41 38 cur.execute("select ?", ("Germany",)) 42 39 row = cur.fetchone() 43 assert type(row[0]) ==str40 assert type(row[0]) is str
Note:
See TracChangeset
for help on using the changeset viewer.