コード例 #1
0
ファイル: sqlreflector.py プロジェクト: samis/blockBox
	def buildUpdateSQL(self, tableInfo):
		"""(Internal) Build SQL template 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
コード例 #2
0
ファイル: row.py プロジェクト: TheArchives/blockBox
	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
コード例 #3
0
ファイル: row.py プロジェクト: samis/blockBox
    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
コード例 #4
0
ファイル: row.py プロジェクト: samis/blockBox
    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, "")
コード例 #5
0
ファイル: row.py プロジェクト: TheArchives/blockBox
	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, "")
コード例 #6
0
ファイル: sqlreflector.py プロジェクト: samis/blockBox
	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)