Mercurial > p > roundup > code
comparison roundup/backends/back_postgresql.py @ 3100:406862712b7d maint-0.8
merge from HEAD
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 13 Jan 2005 05:05:12 +0000 |
| parents | d6b848497747 |
| children | e1da7b5b04ab |
comparison
equal
deleted
inserted
replaced
| 3098:5b0f7f1cc3cb | 3100:406862712b7d |
|---|---|
| 12 import psycopg | 12 import psycopg |
| 13 | 13 |
| 14 from roundup import hyperdb, date | 14 from roundup import hyperdb, date |
| 15 from roundup.backends import rdbms_common | 15 from roundup.backends import rdbms_common |
| 16 | 16 |
| 17 def connection_dict(config, dbnamestr=None): | |
| 18 ''' read_default_group is MySQL-specific, ignore it ''' | |
| 19 d = rdbms_common.connection_dict(config, dbnamestr) | |
| 20 if d.has_key('read_default_group'): | |
| 21 del d['read_default_group'] | |
| 22 if d.has_key('read_default_file'): | |
| 23 del d['read_default_file'] | |
| 24 return d | |
| 25 | |
| 17 def db_create(config): | 26 def db_create(config): |
| 18 """Clear all database contents and drop database itself""" | 27 """Clear all database contents and drop database itself""" |
| 19 command = 'CREATE DATABASE %s'%config.RDBMS_NAME | 28 command = 'CREATE DATABASE %s'%config.RDBMS_NAME |
| 20 config.logging.getLogger('hyperdb').info(command) | 29 config.logging.getLogger('hyperdb').info(command) |
| 21 db_command(config, command) | 30 db_command(config, command) |
| 31 | 40 |
| 32 def db_command(config, command): | 41 def db_command(config, command): |
| 33 '''Perform some sort of database-level command. Retry 10 times if we | 42 '''Perform some sort of database-level command. Retry 10 times if we |
| 34 fail by conflicting with another user. | 43 fail by conflicting with another user. |
| 35 ''' | 44 ''' |
| 36 template1 = rdbms_common.connection_dict(config) | 45 template1 = connection_dict(config) |
| 37 template1['database'] = 'template1' | 46 template1['database'] = 'template1' |
| 38 | 47 |
| 39 try: | 48 try: |
| 40 conn = psycopg.connect(**template1) | 49 conn = psycopg.connect(**template1) |
| 41 except psycopg.OperationalError, message: | 50 except psycopg.OperationalError, message: |
| 68 return 0 | 77 return 0 |
| 69 return 1 | 78 return 1 |
| 70 | 79 |
| 71 def db_exists(config): | 80 def db_exists(config): |
| 72 """Check if database already exists""" | 81 """Check if database already exists""" |
| 73 db = rdbms_common.connection_dict(config, 'database') | 82 db = connection_dict(config, 'database') |
| 74 try: | 83 try: |
| 75 conn = psycopg.connect(**db) | 84 conn = psycopg.connect(**db) |
| 76 conn.close() | 85 conn.close() |
| 77 return 1 | 86 return 1 |
| 78 except: | 87 except: |
| 83 | 92 |
| 84 # used by some code to switch styles of query | 93 # used by some code to switch styles of query |
| 85 implements_intersect = 1 | 94 implements_intersect = 1 |
| 86 | 95 |
| 87 def sql_open_connection(self): | 96 def sql_open_connection(self): |
| 88 db = rdbms_common.connection_dict(self.config, 'database') | 97 db = connection_dict(self.config, 'database') |
| 89 self.config.logging.getLogger('hyperdb').info('open database %r'%( | 98 self.config.logging.getLogger('hyperdb').info('open database %r'%( |
| 90 db['database'],)) | 99 db['database'],)) |
| 91 try: | 100 try: |
| 92 conn = psycopg.connect(**db) | 101 conn = psycopg.connect(**db) |
| 93 except psycopg.OperationalError, message: | 102 except psycopg.OperationalError, message: |
