def sqlObjRef(self): """Return the 64-bit integer value that refers to self in a SQL database. This only makes sense if the UseBigIntObjRefColumns setting is True. """ return objRefJoin(self.klass().id(), self.serialNum())
def readStoreDataRow(self, obj, row, i): # this does *not* get called under the old approach of single obj ref columns. see MiddleObject.readStoreData classId, objId = row[i], row[i+1] if objId is None: value = None else: value = objRefJoin(classId, objId) # @@ 2004-20-02 ce ^ that's wasteful to join them just so they can be split later, but it works well with the legacy code obj.setValueForAttr(self, value) return i + 2
def stringToValue(self, string): parts = string.split('.', 2) if len(parts) == 2: className, objSerialNum = parts else: className = self.targetClassName() objSerialNum = string klass = self.klass().klasses()._model.klass(className) klassId = klass.id() objRef = objRefJoin(klassId, int(objSerialNum)) return objRef
def sqlForNonNoneSampleInput(self, input): """Get SQL for non-None sample input. Obj ref sample data format is "Class.serialNum", such as "Thing.3". If the Class and period are missing, then the obj ref's type is assumed. Also, a comment can follow the value after a space: "User.3 Joe Schmoe" or "User.3 - Joe Schmoe" This is useful so that you can look at the sample later and know what the obj ref value is referring to without having to look it up. MiddleKit only looks at the first part ("User.3"). """ if self.refByAttr: # the column was spec'ed as "foo by bar". # so match by "bar" value, not serial number. # refByAttr holds the "bar" attr targetKlass = self.targetKlass() refByAttr = self.refByAttr assert targetKlass is refByAttr.klass() sql = '(select %s from %s where %s=%s)' % ( targetKlass.sqlSerialColumnName(), targetKlass.sqlTableName(), refByAttr.sqlColumnName(), refByAttr.sqlForSampleInput(input)) sql = str(targetKlass.id()) + ',' + sql # print '>> sql =', sql return sql # caveat: this only works if the object is found directly in the # target class. i.e., inheritance is not supported # caveat: this does not work if the UseBigIntObjRefColumns setting # is true (by default it is false) # caveat: MS SQL Server supports subselects but complains # "Subqueries are not allowed in this context. Only scalar expressions are allowed." # so more work is needed in its SQL generator else: # the de facto technique of <serialnum> or <class name>.<serial num> input = input.split() # this gets rid of the sample value comment described above if input: input = input[0] else: input = '' parts = input.split('.') if len(parts) == 2: className = parts[0] objSerialNum = parts[1] else: className = self.targetClassName() objSerialNum = input or 'null' klass = self.klass().klasses()._model.klass(className) klassId = klass.id() if self.setting('UseBigIntObjRefColumns', False): objRef = objRefJoin(klassId, objSerialNum) return str(objRef) else: return '%s,%s' % (klassId, objSerialNum)
def readStoreDataRow(self, obj, row, i): # This does *not* get called under the old approach of single obj ref columns. # See MiddleObject.readStoreData. classId, objId = row[i], row[i + 1] if objId is None: value = None else: value = objRefJoin(classId, objId) # @@ 2004-20-02 ce ^ that's wasteful to join them just so they can be split later, # but it works well with the legacy code obj.setValueForAttr(self, value) return i + 2
def sqlForNonNoneSampleInput(self, input): """Get SQL for non-None sample input. Obj ref sample data format is "Class.serialNum", such as "Thing.3". If the Class and period are missing, then the obj ref's type is assumed. Also, a comment can follow the value after a space: "User.3 Joe Schmoe" or "User.3 - Joe Schmoe" This is useful so that you can look at the sample later and know what the obj ref value is referring to without having to look it up. MiddleKit only looks at the first part ("User.3"). """ if self.refByAttr: # the column was spec'ed as "foo by bar". # so match by "bar" value, not serial number. # refByAttr holds the "bar" attr targetKlass = self.targetKlass() refByAttr = self.refByAttr assert targetKlass is refByAttr.klass() sql = '(select %s from %s where %s=%s)' % ( targetKlass.sqlSerialColumnName(), targetKlass.sqlTableName(), refByAttr.sqlColumnName(), refByAttr.sqlForSampleInput(input)) sql = str(targetKlass.id()) + ',' + sql # print '>> sql =', sql return sql # caveat: this only works if the object is found directly in the # target class. i.e., inheritance is not supported # caveat: this does not work if the UseBigIntObjRefColumns setting # is true (by default it is false) # caveat: MS SQL Server supports subselects but complains # "Subqueries are not allowed in this context. Only scalar expressions are allowed." # so more work is needed in its SQL generator else: # the de facto technique of <serialnum> or <class name>.<serial num> input = input.split(None, 1) # this gets rid of the sample value comment described above if input: input = input[0] else: input = '' parts = input.split('.', 2) if len(parts) == 2: className, objSerialNum = parts else: className = self.targetClassName() objSerialNum = input or 'null' klass = self.klass().klasses()._model.klass(className) klassId = klass.id() if self.setting('UseBigIntObjRefColumns', False): objRef = objRefJoin(klassId, objSerialNum) return str(objRef) else: return '%s,%s' % (klassId, objSerialNum)
def sampleValue(self, value): """ Obj ref sample data format is "Class.serialNum", such as "Thing.3". If the Class and period are missing, then the obj ref's type is assumed. """ parts = value.split('.') if len(parts) == 2: className = parts[0] objSerialNum = parts[1] else: className = self.className() objSerialNum = value # @@ 2000-11-24 ce: check that we're pointing to a legal class klass = self.klass().klasses()._model.klass(className) klassId = klass.id() objRef = objRefJoin(klassId, objSerialNum) return str(objRef)
def sqlObjRef(self): return objRefJoin(self.klass().id(), self.serialNum())