本文整理汇总了Python中query.Query.format_type方法的典型用法代码示例。如果您正苦于以下问题:Python Query.format_type方法的具体用法?Python Query.format_type怎么用?Python Query.format_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类query.Query
的用法示例。
在下文中一共展示了Query.format_type方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from query import Query [as 别名]
# 或者: from query.Query import format_type [as 别名]
def save(self):
# If it doesn't have an ID (Either nonexistant or not set), then call the
# create() method to do an INSERT instead of an UPDATE.
try:
if not self.id: self.create()
except AttributeError: self.create()
base = 'UPDATE %s SET ' % self.Table
diff = self.diff()
fields = ''
if not diff: return None
# Build field and value list if there is a difference
for key in diff:
field = self._get_field_by_name(key)
value = field.query(diff[key])
fields += ', ' + field.name + ' = ' + Query.format_type(value)
base += fields[2:] + ' WHERE id = ' + str(self.id)
Query.query(base)
# Right now, just spit back the instance of self
return self
示例2: create
# 需要导入模块: from query import Query [as 别名]
# 或者: from query.Query import format_type [as 别名]
def create(self):
base = 'INSERT INTO %s ' % self.Table
names = []
values = []
for f in self.Structure:
try:
# Try to get the attribute, else raise an exception if it can't be null.
name = f.name
value = Query.format_type(f.query(self.__getattribute__(name)))
names.append(name);values.append(value)
except AttributeError:
primary = self.get_primary()
if not f.null and f.name != primary.name:
raise Exception, 'Field "%s" cannot be null' % f.name
# Build the set of fields and VALUES.
base += '(%s) ' % (', '.join(names))
base += 'VALUES (%s)' % (', '.join(values))
# Execute and dump the current instance's attribs into the _original.
self.Query.query(base)
self._original = self._build_original()
# Spit yourself back!
return self