5 # Requires: Python 3.2, psycopg2 |
5 # Requires: Python 3.2, psycopg2 |
6 # |
6 # |
7 # Part of pgtoolkit |
7 # Part of pgtoolkit |
8 # http://hg.devl.cz/pgtoolkit |
8 # http://hg.devl.cz/pgtoolkit |
9 # |
9 # |
10 # Copyright (c) 2010, 2011, 2012 Radek Brich <radek.brich@devl.cz> |
10 # Copyright (c) 2010, 2011, 2012, 2013 Radek Brich <radek.brich@devl.cz> |
11 # |
11 # |
12 # Permission is hereby granted, free of charge, to any person obtaining a copy |
12 # Permission is hereby granted, free of charge, to any person obtaining a copy |
13 # of this software and associated documentation files (the "Software"), to deal |
13 # of this software and associated documentation files (the "Software"), to deal |
14 # in the Software without restriction, including without limitation the rights |
14 # in the Software without restriction, including without limitation the rights |
15 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
15 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
27 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
27 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
28 # THE SOFTWARE. |
28 # THE SOFTWARE. |
29 |
29 |
30 """Postgres database connection manager |
30 """Postgres database connection manager |
31 |
31 |
32 PgManager wraps psycopg2 connect function, adding following features: |
32 PgManager wraps psycopg2, adding following features: |
33 |
33 |
34 * Save and reuse database connection parameters |
34 * Save and reuse database connection parameters |
35 |
35 |
36 * Connection pooling |
36 * Connection pooling |
37 |
37 |
472 if not ci.isolation_level is None: |
472 if not ci.isolation_level is None: |
473 conn.set_isolation_level(ci.isolation_level) |
473 conn.set_isolation_level(ci.isolation_level) |
474 if ci.init_statement: |
474 if ci.init_statement: |
475 curs = conn.cursor() |
475 curs = conn.cursor() |
476 curs.execute(ci.init_statement) |
476 curs.execute(ci.init_statement) |
|
477 curs.connection.commit() |
477 curs.close() |
478 curs.close() |
478 return conn |
479 return conn |
479 |
480 |
480 def _normalize_isolation_level(self, level): |
481 def _normalize_isolation_level(self, level): |
481 if type(level) == str: |
482 if type(level) == str: |