Changeset 151
- Timestamp:
- 02/01/06 00:11:58
- Files:
-
- trunk/storage/db.py (modified) (3 diffs)
- trunk/storage/storeado.py (modified) (1 diff)
- trunk/storage/storemysql.py (modified) (1 diff)
- trunk/storage/storepypgsql.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/storage/db.py
r150 r151 781 781 if adapter: self.fromAdapter = adapter 782 782 783 self.CreateIfMissing = bool(allOptions.get(u'Create If Missing', 'True'))784 783 self.pool_size = int(allOptions.get(u'Pool Size', '10')) 785 784 … … 847 846 def _get_conn(self): 848 847 # Override this with the connection call for your DB. Example: 849 # try: 850 # conn = libpq.PQconnectdb(self.connstring) 851 # except Exception, x: 852 # if self.CreateIfMissing: 853 # self.create_database() 854 # conn = libpq.PQconnectdb(self.connstring) 855 # else: 856 # raise 857 # return conn 848 # return libpq.PQconnectdb(self.connstring) 858 849 raise NotImplementedError 859 850 860 851 def connection(self): 861 852 if not self.threaded: 853 # Place a single 'conn' entry in self.refs. 862 854 try: 863 855 return self.refs['conn'] … … 898 890 899 891 def release(self, ref): 900 conn = self.refs[ref]901 del self.refs[ref]892 # This method should only be called if self.threaded is True 893 conn = self.refs.pop(ref) 902 894 903 895 if self.pool is not None: trunk/storage/storeado.py
r150 r151 332 332 def _get_conn(self): 333 333 conn = win32com.client.Dispatch(r'ADODB.Connection') 334 try: 335 conn.Open(self.connstring) 336 return conn 337 except pywintypes.com_error, x: 338 if x.args[2][5] == -2147467259: 339 msg = x.args[2][2] 340 if ( 341 # SQL Server: "Cannot open database requested in login 342 # 'dejavu_test'. Login fails." 343 msg.startswith("Cannot open database") or 344 # MSAccess: "Could not find file 345 # 'C:\Python23\Lib\site-packages\dejavu\storage\zoo.mdb'." 346 msg.startswith("Could not find file")): 347 if self.CreateIfMissing: 348 self.create_database() 349 conn.Open(self.connstring) 350 return conn 351 raise 334 conn.Open(self.connstring) 335 return conn 352 336 353 337 def execute(self, query, conn=None): trunk/storage/storemysql.py
r150 r151 161 161 if x.args[0] == 1040: # Too many connections 162 162 raise db.OutOfConnectionsError 163 elif x.args[0] == 1049 and self.CreateIfMissing: 164 self.create_database() 165 conn = _mysql.connect(**self.connargs) 166 else: 167 raise 163 raise 168 164 return conn 169 165 trunk/storage/storepypgsql.py
r150 r151 66 66 return libpq.PQconnectdb(self.connstring) 67 67 except libpq.DatabaseError, x: 68 msg = x.args[0] 69 if msg.endswith('does not exist\n'): 70 if self.CreateIfMissing: 71 self.create_database() 72 return libpq.PQconnectdb(self.connstring) 73 elif msg.startswith('could not connect'): 68 if x.args[0].startswith('could not connect'): 74 69 raise db.OutOfConnectionsError 75 raise x70 raise 76 71 77 72 def _template_conn(self):
