summaryrefslogtreecommitdiffstats
path: root/Doc/lib/sqlite3/row_factory.py
diff options
context:
space:
mode:
Diffstat (limited to 'Doc/lib/sqlite3/row_factory.py')
-rw-r--r--Doc/lib/sqlite3/row_factory.py13
1 files changed, 13 insertions, 0 deletions
diff --git a/Doc/lib/sqlite3/row_factory.py b/Doc/lib/sqlite3/row_factory.py
new file mode 100644
index 0000000..64676c8
--- /dev/null
+++ b/Doc/lib/sqlite3/row_factory.py
@@ -0,0 +1,13 @@
+import sqlite3
+
+def dict_factory(cursor, row):
+ d = {}
+ for idx, col in enumerate(cursor.description):
+ d[col[0]] = row[idx]
+ return d
+
+con = sqlite3.connect(":memory:")
+con.row_factory = dict_factory
+cur = con.cursor()
+cur.execute("select 1 as a")
+print cur.fetchone()["a"]