本文整理汇总了Python中sql.Table.update方法的典型用法代码示例。如果您正苦于以下问题:Python Table.update方法的具体用法?Python Table.update怎么用?Python Table.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sql.Table
的用法示例。
在下文中一共展示了Table.update方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_subselect
# 需要导入模块: from sql import Table [as 别名]
# 或者: from sql.Table import update [as 别名]
def test_update_subselect(self):
t1 = Table('t1')
t2 = Table('t2')
query_list = t1.update([t1.c], [t2.select(t2.c, where=t2.i == t1.i)])
query_nolist = t1.update([t1.c], t2.select(t2.c, where=t2.i == t1.i))
for query in [query_list, query_nolist]:
self.assertEqual(str(query),
'UPDATE "t1" SET "c" = ('
'SELECT "b"."c" FROM "t2" AS "b" WHERE ("b"."i" = "t1"."i"))')
self.assertEqual(query.params, ())
示例2: __register__
# 需要导入模块: from sql import Table [as 别名]
# 或者: from sql.Table import update [as 别名]
def __register__(cls, module_name):
cursor = Transaction().cursor
model_data = Table('ir_model_data')
# Migration from 3.0: new tax rates
if module_name == 'account_nl':
for old_id, new_id in (
('tva_vente_19_6', 'tva_vente_taux_normal'),
('tva_vente_7', 'tva_vente_taux_intermediaire'),
('tva_vente_intracommunautaire_19_6',
'tva_vente_intracommunautaire_taux_normal'),
('tva_vente_intracommunautaire_7',
'tva_vente_intracommunautaire_taux_intermediaire'),
('tva_achat_19_6', 'tva_achat_taux_normal'),
('tva_achat_7', 'tva_achat_taux_intermediaire'),
('tva_achat_intracommunautaire_19_6',
'tva_achat_intracommunautaire_taux_normal'),
):
cursor.execute(*model_data.select(model_data.id,
where=(model_data.fs_id == new_id)
& (model_data.module == module_name)))
if cursor.fetchone():
continue
cursor.execute(*model_data.update(
columns=[model_data.fs_id],
values=[new_id],
where=(model_data.fs_id == old_id)
& (model_data.module == module_name)))
super(TaxTemplate, cls).__register__(module_name)
示例3: test_update2
# 需要导入模块: from sql import Table [as 别名]
# 或者: from sql.Table import update [as 别名]
def test_update2(self):
t1 = Table('t1')
t2 = Table('t2')
query = t1.update([t1.c], ['foo'], from_=[t2], where=(t1.c == t2.c))
self.assertEqual(str(query),
'UPDATE "t1" AS "b" SET "c" = %s FROM "t2" AS "a" '
'WHERE ("b"."c" = "a"."c")')
self.assertEqual(query.params, ('foo',))
示例4: __register__
# 需要导入模块: from sql import Table [as 别名]
# 或者: from sql.Table import update [as 别名]
def __register__(cls, module_name):
cursor = Transaction().cursor
model_data = Table('ir_model_data')
# Migration from 1.6: corrected misspelling of ounce (was once)
cursor.execute(*model_data.update(
columns=[model_data.fs_id],
values=['uom_ounce'],
where=(model_data.fs_id == 'uom_once')
& (model_data.module == 'product')))
super(Uom, cls).__register__(module_name)
示例5: __register__
# 需要导入模块: from sql import Table [as 别名]
# 或者: from sql.Table import update [as 别名]
def __register__(cls, module_name):
cursor = Transaction().cursor
model_data = Table('ir_model_data')
model = Table('ir_model')
# Migration from 1.2: packing renamed into shipment
cursor.execute(*model_data.update(
columns=[model_data.fs_id],
values=[Overlay(model_data.fs_id, 'shipment',
Position('packing', model_data.fs_id),
len('packing'))],
where=model_data.fs_id.like('%packing%')
& (model_data.module == module_name)))
cursor.execute(*model.update(
columns=[model.model],
values=[Overlay(model.model, 'shipment',
Position('packing', model.model),
len('packing'))],
where=model.model.like('%packing%')
& (model.module == module_name)))
super(ShipmentInternal, cls).__register__(module_name)
示例6: resets
# 需要导入模块: from sql import Table [as 别名]
# 或者: from sql.Table import update [as 别名]
def resets(cls, dbname):
table = Table('ir_cache')
with Transaction().new_transaction() as transaction,\
transaction.connection.cursor() as cursor,\
cls._resets_lock:
cls._resets.setdefault(dbname, set())
for name in cls._resets[dbname]:
cursor.execute(*table.select(table.name,
where=table.name == name))
if cursor.fetchone():
# It would be better to insert only
cursor.execute(*table.update([table.timestamp],
[CurrentTimestamp()],
where=table.name == name))
else:
cursor.execute(*table.insert(
[table.timestamp, table.name],
[[CurrentTimestamp(), name]]))
cls._resets[dbname].clear()
示例7: rename
# 需要导入模块: from sql import Table [as 别名]
# 或者: from sql.Table import update [as 别名]
def rename(cursor, table_name, old_name, new_name, var_name):
table = Table(table_name)
cursor.execute(
*table.update([getattr(table, var_name)], [new_name], where=(getattr(table, var_name) == old_name))
)