CARVIEW |
Select Language
HTTP/2 302
server: nginx
date: Fri, 18 Jul 2025 04:57:42 GMT
content-type: text/plain; charset=utf-8
content-length: 0
x-archive-redirect-reason: found capture at 20071029191659
location: https://web.archive.org/web/20071029191659/https://wiki.python.org/moin/DbApiCheatSheet
server-timing: captures_list;dur=0.585111, exclusion.robots;dur=0.019461, exclusion.robots.policy;dur=0.008324, esindex;dur=0.011327, cdx.remote;dur=23.245033, LoadShardBlock;dur=216.785593, PetaboxLoader3.datanode;dur=77.326896, PetaboxLoader3.resolve;dur=112.746513
x-app-server: wwwb-app219
x-ts: 302
x-tr: 268
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
set-cookie: SERVER=wwwb-app219; path=/
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
HTTP/2 200
server: nginx
date: Fri, 18 Jul 2025 04:57:43 GMT
content-type: text/html;charset=utf-8
x-archive-orig-date: Mon, 29 Oct 2007 19:16:59 GMT
x-archive-orig-server: Apache/2.0.54 (Debian GNU/Linux) mod_fastcgi/2.4.2
x-archive-orig-connection: close
x-archive-guessed-content-type: text/html
x-archive-guessed-charset: utf-8
memento-datetime: Mon, 29 Oct 2007 19:16:59 GMT
link: ; rel="original", ; rel="timemap"; type="application/link-format", ; rel="timegate", ; rel="first memento"; datetime="Mon, 29 Oct 2007 19:16:59 GMT", ; rel="memento"; datetime="Mon, 29 Oct 2007 19:16:59 GMT", ; rel="next memento"; datetime="Sat, 13 Sep 2008 01:16:49 GMT", ; rel="last memento"; datetime="Fri, 12 Jul 2024 22:41:38 GMT"
content-security-policy: default-src 'self' 'unsafe-eval' 'unsafe-inline' data: blob: archive.org web.archive.org web-static.archive.org wayback-api.archive.org athena.archive.org analytics.archive.org pragma.archivelab.org wwwb-events.archive.org
x-archive-src: 52_0_20071029175225_crawl105-c/52_0_20071029191516_crawl107.arc.gz
server-timing: captures_list;dur=0.679186, exclusion.robots;dur=0.024622, exclusion.robots.policy;dur=0.010625, esindex;dur=0.014504, cdx.remote;dur=11.172337, LoadShardBlock;dur=117.217369, PetaboxLoader3.datanode;dur=195.283305, load_resource;dur=168.739315, PetaboxLoader3.resolve;dur=42.322220
x-app-server: wwwb-app219
x-ts: 200
x-tr: 352
server-timing: TR;dur=0,Tw;dur=0,Tc;dur=0
x-location: All
x-rl: 0
x-na: 0
x-page-cache: MISS
server-timing: MISS
x-nid: DigitalOcean
referrer-policy: no-referrer-when-downgrade
permissions-policy: interest-cohort=()
content-encoding: gzip
DbApiCheatSheet - PythonInfo Wiki
DbApiCheatSheet
Some quick syntax reminders for common tasks using DB-API2 modules.
task | postgresql | sqlite | MySQL | Oracle | ODBC |
---|---|---|---|---|---|
create database | createdb mydb | created automatically when opened with sqlite3 | created with Oracle XE install | ||
command-line tool | psql -d mydb | sqlite3 mydb.sqlite | sqlplus scott/tiger | ||
GUI tool | pgadmin3 | mysql-admin | sqldeveloper | ||
install module | easy_install psycopg2 | included in Python 2.5 standard library | easy_install mysql-python or apt-get install python-mysqldb | easy_install cx_oracle (but see note) | |
import | from psycopg2 import * | from sqlite3 import * | from MySQLdb import * | from cx_Oracle import * | |
connect | conn = connect("dbname='testdb' user='me' host='localhost' password='mypassword'”) | conn = connect('mydb.sqlite') or conn=connect(':memory:') | conn=connect('scott/tiger@xe') | conn = odbc.odbc('DBALIAS') or odbc.odbc('DBALIAS/USERNAME/PASSWORD') | |
get cursor | curs = conn.cursor() | curs = conn.cursor() | curs = conn.cursor() | ||
execute SELECT | curs.execute('SELECT * FROM tbl') | curs.execute('SELECT * FROM tbl') | curs.execute('SELECT * FROM tbl') | ||
fetch | curs.fetchone(); curs.fetchall(); curs.fetchmany() | curs.fetchone(); curs.fetchall(); curs.fetchmany() | curs.fetchone(); curs.fetchall(); curs.fetchmany(); for r in curs | ||
use bind variables | curs.execute('SELECT * FROM tbl WHERE col = %(varnm)s', {'varnm':22}) | curs.execute('SELECT * FROM tbl WHERE col = ?', [22]) | curs.execute('SELECT * FROM tbl WHERE col = %s', [22]) | curs.execute('SELECT * FROM tbl WHERE col = :varnm', {'varnm':22}) | |
commit | conn.commit() (required) | conn.commit() (required) | conn.commit() (required) |
See also DbApiModuleComparison, DatabaseProgramming
EditText (last edited 2007-10-09 16:53:29 by CatherineDevlin)
DeleteCache (cached 2007-10-09 16:53:29)- Login
- Navigation
- Actions
- Your recent pages