Mercurial > sqlpython
comparison sqlpython/connections.py @ 441:da332a670378
successful connect to mysql testdb
author | catherine@dellzilla |
---|---|
date | Mon, 01 Feb 2010 16:32:13 -0500 |
parents | e1a962dd7139 |
children | 0b71da565ebe |
comparison
equal
deleted
inserted
replaced
440:e1a962dd7139 | 441:da332a670378 |
---|---|
109 setattr(self, param, connectargs.group(param)) | 109 setattr(self, param, connectargs.group(param)) |
110 except IndexError: | 110 except IndexError: |
111 pass | 111 pass |
112 self.set_corrections() | 112 self.set_corrections() |
113 if not self.password: | 113 if not self.password: |
114 self.password = getpass.getpass() | 114 self.password = getpass.getpass() |
115 def parse_connect_uri(self, uri): | 115 def parse_connect_uri(self, uri): |
116 results = self.connection_uri_parser.search(uri) | 116 results = self.connection_uri_parser.search(uri) |
117 if results: | 117 if results: |
118 (self.username, self.password, self.hostname, self.port, self.database | 118 (self.username, self.password, self.hostname, self.port, self.database |
119 ) = gerald.utilities.dburi.Connection().parse_uri(results.group(2)) | 119 ) = gerald.utilities.dburi.Connection().parse_uri(results.group(2)) |
147 rdbms = 'mysql' | 147 rdbms = 'mysql' |
148 default_port = 3306 | 148 default_port = 3306 |
149 def set_defaults(self): | 149 def set_defaults(self): |
150 self.port = self.default_port | 150 self.port = self.default_port |
151 self.hostname = 'localhost' | 151 self.hostname = 'localhost' |
152 self.database = os.getenv('USER') | |
152 def connection(self): | 153 def connection(self): |
153 return MySQLdb.connect(host = self.hostname, user = self.username, | 154 return MySQLdb.connect(host = self.hostname, user = self.username, |
154 passwd = self.password, db = self.database, | 155 passwd = self.password, db = self.database, |
155 port = self.port, sql_mode = 'ANSI') | 156 port = self.port, sql_mode = 'ANSI') |
156 | 157 |
159 default_port = 5432 | 160 default_port = 5432 |
160 def set_defaults(self): | 161 def set_defaults(self): |
161 self.port = os.getenv('PGPORT') or self.default_port | 162 self.port = os.getenv('PGPORT') or self.default_port |
162 self.database = os.getenv('ORACLE_SID') | 163 self.database = os.getenv('ORACLE_SID') |
163 self.hostname = os.getenv('PGHOST') or 'localhost' | 164 self.hostname = os.getenv('PGHOST') or 'localhost' |
165 self.username = os.getenv('USER') | |
164 def connection(self): | 166 def connection(self): |
165 return psycopg2.connect(host = self.hostname, user = self.username, | 167 return psycopg2.connect(host = self.hostname, user = self.username, |
166 password = self.password, database = self.database, | 168 password = self.password, database = self.database, |
167 port = self.port) | 169 port = self.port) |
168 | 170 |