def buildUpdateSQL(self, tableInfo): """(Internal) Build SQL to update a RowObject. Returns: SQL that is used to contruct a rowObject class. """ sql = "UPDATE %s SET" % tableInfo.rowTableName # build update attributes first = 1 for column, type in tableInfo.rowColumns: if getKeyColumn(tableInfo.rowClass, column): continue if not first: sql = sql + ", " sql = sql + " %s = %s" % (column, "%s") first = 0 # build where clause first = 1 sql = sql + " WHERE " for keyColumn, type in tableInfo.rowKeyColumns: if not first: sql = sql + " AND " sql = sql + " %s = %s " % (keyColumn, "%s") first = 0 return sql
def __setattr__(self, name, value): """Special setattr to prevent changing of key values. """ # build where clause if getKeyColumn(self.__class__, name): raise DBError("cannot assign value <%s> to key column attribute <%s> of RowObject class" % (value, name)) if name in self.rowColumns: if value != self.__dict__.get(name, None) and not self.dirty: self.setDirty(1) self.__dict__[name] = value
def updateRowSQL(self, rowObject): """Build SQL to update the contents of rowObject. """ args = [] tableInfo = self.schema[rowObject.rowTableName] for column, type in tableInfo.rowColumns: if not getKeyColumn(rowObject.__class__, column): args.append(self.quote_value(rowObject.findAttribute(column), type)) for keyColumn, type in tableInfo.rowKeyColumns: args.append(self.quote_value(rowObject.findAttribute(keyColumn), type)) return self.getTableInfo(rowObject).updateSQL % tuple(args)
def __setattr__(self, name, value): """Special setattr to prevent changing of key values. """ # build where clause if getKeyColumn(self.__class__, name): raise DBError( "cannot assign value <%s> to key column attribute <%s> of RowObject class" % (value, name)) if name in self.rowColumns: if value != self.__dict__.get(name, None) and not self.dirty: self.setDirty(1) self.__dict__[name] = value
def updateRowSQL(self, rowObject): """build SQL to update my current state. """ args = [] tableInfo = self.schema[rowObject.rowTableName] # build update attributes for column, type in tableInfo.rowColumns: if not getKeyColumn(rowObject.__class__, column): args.append(self.quote_value(rowObject.findAttribute(column), type)) # build where clause for keyColumn, type in tableInfo.rowKeyColumns: args.append(self.quote_value(rowObject.findAttribute(keyColumn), type)) return self.getTableInfo(rowObject).updateSQL % tuple(args)
def updateRowSQL(self, rowObject): """Build SQL to update the contents of rowObject. """ args = [] tableInfo = self.schema[rowObject.rowTableName] # build update attributes for column, type in tableInfo.rowColumns: if not getKeyColumn(rowObject.__class__, column): args.append( self.quote_value(rowObject.findAttribute(column), type)) # build where clause for keyColumn, type in tableInfo.rowKeyColumns: args.append( self.quote_value(rowObject.findAttribute(keyColumn), type)) return self.getTableInfo(rowObject).updateSQL % tuple(args)
def createDefaultAttributes(self): """Populate instance with default attributes. This is used when creating a new instance NOT from the database. """ for attr in self.rowColumns: if getKeyColumn(self.__class__, attr): continue for column, ctype, typeid in self.dbColumns: if column.lower(column) == attr.lower(): q = dbTypeMap.get(ctype, None) if q == NOQUOTE: setattr(self, attr, 0) else: setattr(self, attr, "")
def randomizeRow(row, nulls_ok=True, trailing_spaces_ok=True): values = {} for name, type in row.rowColumns: if util.getKeyColumn(row, name): values[name] = getattr(row, name) continue elif nulls_ok and random.randint(0, 9) == 0: value = None # null elif type == "int": value = random.randint(-10000, 10000) else: if random.randint(0, 9) == 0: value = "" else: value = "".join(map(lambda i: chr(random.randrange(32, 127)), xrange(random.randint(1, 64)))) if not trailing_spaces_ok: value = value.rstrip() setattr(row, name, value) values[name] = value return values
def randomizeRow(row, nulls_ok=True, trailing_spaces_ok=True): values = {} for name, type in row.rowColumns: if util.getKeyColumn(row, name): values[name] = getattr(row, name) continue elif nulls_ok and random.randint(0, 9) == 0: value = None # null elif type == 'int': value = random.randint(-10000, 10000) else: if random.randint(0, 9) == 0: value = '' else: value = ''.join(map(lambda i:chr(random.randrange(32,127)), xrange(random.randint(1, 64)))) if not trailing_spaces_ok: value = value.rstrip() setattr(row, name, value) values[name] = value return values