summaryrefslogtreecommitdiff
path: root/examples/dict.py
diff options
context:
space:
mode:
Diffstat (limited to 'examples/dict.py')
-rw-r--r--examples/dict.py20
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."