diff options
| author | Federico Di Gregorio <fog@initd.org> | 2007-01-16 13:45:41 +0000 |
|---|---|---|
| committer | Federico Di Gregorio <fog@initd.org> | 2007-01-16 13:45:41 +0000 |
| commit | f43a52f781cd34dd6e41ce04d4798550f81127d5 (patch) | |
| tree | a2f2a49782f1d366a298b4938e950bbb8d17e320 /examples/dict.py | |
| parent | 5c425f5294c4ddda49143f4a519b999717396303 (diff) | |
| download | psycopg2-f43a52f781cd34dd6e41ce04d4798550f81127d5.tar.gz | |
Added RealDictCursor from #143.
Diffstat (limited to 'examples/dict.py')
| -rw-r--r-- | examples/dict.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/examples/dict.py b/examples/dict.py index 37dc74a..9ee28a7 100644 --- a/examples/dict.py +++ b/examples/dict.py @@ -32,14 +32,34 @@ print "Encoding for this connection is", conn.encoding curs = conn.cursor(cursor_factory=psycopg2.extras.DictCursor) curs.execute("SELECT 1 AS foo, 'cip' AS bar, date(now()) as zot") +print "Cursor's row factory is", curs.row_factory data = curs.fetchone() +print "The type of the data row is", type(data) print "Some data accessed both as tuple and dict:" print " ", data['foo'], data['bar'], data['zot'] print " ", data[0], data[1], data[2] # execute another query and demostrate we can still access the row curs.execute("SELECT 2 AS foo") +print "The type of the data row is", type(data) print "Some more data accessed both as tuple and dict:" print " ", data['foo'], data['bar'], data['zot'] print " ", data[0], data[1], data[2] + +curs = conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) +curs.execute("SELECT 1 AS foo, 'cip' AS bar, date(now()) as zot") +print "Cursor's row factory is", curs.row_factory + +data = curs.fetchone() +print "The type of the data row is", type(data) +print "Some data accessed both as tuple and dict:" +print " ", data['foo'], data['bar'], data['zot'] +print " ", "No access using indices: this is a specialized cursor." + +# execute another query and demostrate we can still access the row +curs.execute("SELECT 2 AS foo") +print "The type of the data row is", type(data) +print "Some more data accessed both as tuple and dict:" +print " ", data['foo'], data['bar'], data['zot'] +print " ", "No access using indices: this is a specialized cursor." |
