Ticket #366: axiom-unique-attribute.patch
| File axiom-unique-attribute.patch, 3.0 kB (added by ironfroggy, 3 years ago) |
|---|
-
axiom/store.py
old new 872 872 sqlarg.append("\n%s %s" % 873 873 (atr.columnName, atr.sqltype)) 874 874 if atr.indexed: 875 indexes.append( nam)875 indexes.append((nam, atr)) 876 876 if len(sqlarg) == 0: 877 877 # XXX should be raised way earlier, in the class definition or something 878 878 raise NoEmptyItems("%r did not define any attributes" % (tableClass,)) … … 884 884 self.connection.rollback() 885 885 886 886 self.createSQL(''.join(sqlstr)) 887 for index in indexes: 888 self.createSQL('CREATE INDEX axiomidx_%s_%s ON %s([%s])' 889 % (tableName, index, 887 for index, index_atr in indexes: 888 if index_atr.unique: 889 unique = "UNIQUE" 890 else: 891 unique = "" 892 self.createSQL('CREATE %s INDEX axiomidx_%s_%s ON %s([%s])' 893 % (unique, 894 tableName, index, 890 895 tableName, index)) 891 896 892 897 if not self.autocommit: -
axiom/errors.py
old new 36 36 Found 2 or more of an item which is supposed to be unique. 37 37 """ 38 38 39 class DuplicateUniqueAttribute(KeyError): 40 """ 41 Found 2 or more of an attribute which is supposed to be unique. 42 """ 43 39 44 class ItemNotFound(KeyError): 40 45 """ 41 46 Did not find even 1 of an item which was supposed to exist. -
axiom/attributes.py
old new 14 14 15 15 from axiom.slotmachine import Attribute as inmemory 16 16 17 from axiom.errors import NoCrossStoreReferences 17 from axiom.errors import NoCrossStoreReferences, DuplicateUniqueAttribute 18 18 19 19 from axiom.iaxiom import IComparison, IOrdering 20 20 … … 282 282 """ 283 283 sqltype = None 284 284 285 def __init__(self, doc='', indexed=False, default=None, allowNone=True ):285 def __init__(self, doc='', indexed=False, default=None, allowNone=True, unique=False): 286 286 inmemory.__init__(self, doc) 287 if unique: 288 indexed = True 287 289 self.indexed = indexed 290 self.unique = unique 288 291 self.default = default 289 292 self.allowNone = allowNone 290 293 … … 692 695 return Time.fromPOSIXTimestamp(dbval / MICRO) 693 696 694 697 class reference(integer): 695 def __init__(self, doc='', indexed=True, allowNone=True, reftype=None ):696 integer.__init__(self, doc, indexed, None, allowNone )698 def __init__(self, doc='', indexed=True, allowNone=True, reftype=None, unique=False): 699 integer.__init__(self, doc, indexed, None, allowNone, unique=unique) 697 700 self.reftype = reftype 698 701 699 702
