Mercurial > p > roundup > code
comparison roundup/backends/back_postgresql.py @ 3099:519b92df37dc
handle ~/.my.cnf files for MySQL defaults [SF#1096031]
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 13 Jan 2005 05:02:19 +0000 |
| parents | 6da931530497 |
| children | 57b60bda9473 |
comparison
equal
deleted
inserted
replaced
| 3097:7b3f1a610d9c | 3099:519b92df37dc |
|---|---|
| 1 #$Id: back_postgresql.py,v 1.27 2005-01-08 11:25:23 jlgijsbers Exp $ | 1 #$Id: back_postgresql.py,v 1.28 2005-01-13 05:02:18 richard Exp $ |
| 2 # | 2 # |
| 3 # Copyright (c) 2003 Martynas Sklyzmantas, Andrey Lebedev <andrey@micro.lt> | 3 # Copyright (c) 2003 Martynas Sklyzmantas, Andrey Lebedev <andrey@micro.lt> |
| 4 # | 4 # |
| 5 # This module is free software, and you may redistribute it and/or modify | 5 # This module is free software, and you may redistribute it and/or modify |
| 6 # under the same terms as Python, so long as this copyright message and | 6 # under the same terms as Python, so long as this copyright message and |
| 13 import psycopg | 13 import psycopg |
| 14 | 14 |
| 15 from roundup import hyperdb, date | 15 from roundup import hyperdb, date |
| 16 from roundup.backends import rdbms_common | 16 from roundup.backends import rdbms_common |
| 17 | 17 |
| 18 def connection_dict(config, dbnamestr=None): | |
| 19 ''' read_default_group is MySQL-specific, ignore it ''' | |
| 20 d = rdbms_common.connection_dict(config, dbnamestr) | |
| 21 if d.has_key('read_default_group'): | |
| 22 del d['read_default_group'] | |
| 23 if d.has_key('read_default_file'): | |
| 24 del d['read_default_file'] | |
| 25 return d | |
| 26 | |
| 18 def db_create(config): | 27 def db_create(config): |
| 19 """Clear all database contents and drop database itself""" | 28 """Clear all database contents and drop database itself""" |
| 20 command = 'CREATE DATABASE %s'%config.RDBMS_NAME | 29 command = 'CREATE DATABASE %s'%config.RDBMS_NAME |
| 21 config.logging.getLogger('hyperdb').info(command) | 30 config.logging.getLogger('hyperdb').info(command) |
| 22 db_command(config, command) | 31 db_command(config, command) |
| 32 | 41 |
| 33 def db_command(config, command): | 42 def db_command(config, command): |
| 34 '''Perform some sort of database-level command. Retry 10 times if we | 43 '''Perform some sort of database-level command. Retry 10 times if we |
| 35 fail by conflicting with another user. | 44 fail by conflicting with another user. |
| 36 ''' | 45 ''' |
| 37 template1 = rdbms_common.connection_dict(config) | 46 template1 = connection_dict(config) |
| 38 template1['database'] = 'template1' | 47 template1['database'] = 'template1' |
| 39 | 48 |
| 40 try: | 49 try: |
| 41 conn = psycopg.connect(**template1) | 50 conn = psycopg.connect(**template1) |
| 42 except psycopg.OperationalError, message: | 51 except psycopg.OperationalError, message: |
| 69 return 0 | 78 return 0 |
| 70 return 1 | 79 return 1 |
| 71 | 80 |
| 72 def db_exists(config): | 81 def db_exists(config): |
| 73 """Check if database already exists""" | 82 """Check if database already exists""" |
| 74 db = rdbms_common.connection_dict(config, 'database') | 83 db = connection_dict(config, 'database') |
| 75 try: | 84 try: |
| 76 conn = psycopg.connect(**db) | 85 conn = psycopg.connect(**db) |
| 77 conn.close() | 86 conn.close() |
| 78 return 1 | 87 return 1 |
| 79 except: | 88 except: |
| 84 | 93 |
| 85 # used by some code to switch styles of query | 94 # used by some code to switch styles of query |
| 86 implements_intersect = 1 | 95 implements_intersect = 1 |
| 87 | 96 |
| 88 def sql_open_connection(self): | 97 def sql_open_connection(self): |
| 89 db = rdbms_common.connection_dict(self.config, 'database') | 98 db = connection_dict(self.config, 'database') |
| 90 self.config.logging.getLogger('hyperdb').info('open database %r'%( | 99 self.config.logging.getLogger('hyperdb').info('open database %r'%( |
| 91 db['database'],)) | 100 db['database'],)) |
| 92 try: | 101 try: |
| 93 conn = psycopg.connect(**db) | 102 conn = psycopg.connect(**db) |
| 94 except psycopg.OperationalError, message: | 103 except psycopg.OperationalError, message: |
