Package conary :: Package dbstore :: Module base_drv
[hide private]
[frames] | no frames]

Source Code for Module conary.dbstore.base_drv

  1  # 
  2  # Copyright (c) 2005-2008 rPath, Inc. 
  3  # 
  4  # This program is distributed under the terms of the Common Public License, 
  5  # version 1.0. A copy of this license should have been distributed with this 
  6  # source file in a file called LICENSE. If it is not present, the license 
  7  # is always available at http://www.rpath.com/permanent/licenses/CPL-1.0. 
  8  # 
  9  # This program is distributed in the hope that it will be useful, but 
 10  # without any warranty; without even the implied warranty of merchantability 
 11  # or fitness for a particular purpose. See the Common Public License for 
 12  # full details. 
 13  # 
 14   
 15  import sys 
 16  import re 
 17   
 18  import sqlerrors, sqllib 
 19   
 20  # class for encapsulating binary strings for dumb drivers 
21 -class BaseBinary:
22 - def __init__(self, s):
23 assert(isinstance(s, str)) 24 self.s = s
25 - def __str__(self):
26 return self.s
27 - def __repr__(self):
28 return self.s
29 30 # this will be derived by the backend drivers to handle schema creation
31 -class BaseKeywordDict(dict):
32 keys = { 'PRIMARYKEY' : 'INTEGER PRIMARY KEY', 33 'BLOB' : 'BLOB', 34 'MEDIUMBLOB' : 'BLOB', 35 'STRAIGHTJOIN' : '', 36 'TABLEOPTS' : '', 37 'PATHTYPE' : 'STRING', 38 'STRING' : 'STRING', 39 'CREATEVIEW' : 'CREATE VIEW', 40 }
41 - def __init__(self):
42 dict.__init__(self, self.keys)
43
44 - def binaryVal(self, binLen):
45 return "BINARY(%d)" % binLen
46
47 - def __getitem__(self, val):
48 if val.startswith('BINARY'): 49 binLen = val[6:] 50 return self.binaryVal(int(binLen)) 51 52 return dict.__getitem__(self, val)
53 54 # base Cursor class. All backend drivers are expected to provide this 55 # interface
56 -class BaseCursor:
57 binaryClass = BaseBinary
58 - def __init__(self, dbh=None):
59 self.dbh = dbh 60 self._cursor = self._getCursor()
61 62 # map some attributes back to self._cursor
63 - def __getattr__(self, name):
64 if name in set(["description", "lastrowid"]): 65 return getattr(self._cursor, name) 66 raise AttributeError("'%s' attribute is invalid" % (name,))
67
68 - def lastid(self):
69 # wrapper for the lastrowid attribute. 70 if hasattr(self._cursor, "lastrowid"): 71 return self._cursor.lastrowid 72 raise AttributeError("This driver does not know about `lastrowid`")
73 74 # this will need to be provided by each separate driver
75 - def _getCu