MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / test_from_sql_onupdate

Method test_from_sql_onupdate

test/sql/test_update.py:1075–1137  ·  view source on GitHub ↗

test combinations with a column that has a SQL onupdate

(self)

Source from the content-addressed store, hash-verified

1073 )
1074
1075 def test_from_sql_onupdate(self):
1076 """test combinations with a column that has a SQL onupdate"""
1077
1078 mytable = self.tables.mytable_with_onupdate
1079 stmt = mytable.update().values(
1080 description=from_dml_column(mytable.c.updated_at)
1081 )
1082
1083 self.assert_compile(
1084 stmt,
1085 "UPDATE mytable_with_onupdate SET description=now(), "
1086 "updated_at=now()",
1087 )
1088
1089 stmt = mytable.update().values(
1090 description=cast(from_dml_column(mytable.c.updated_at), String)
1091 + " o clock"
1092 )
1093
1094 self.assert_compile(
1095 stmt,
1096 "UPDATE mytable_with_onupdate SET "
1097 "description=(CAST(now() AS VARCHAR) || :param_1), "
1098 "updated_at=now()",
1099 )
1100
1101 stmt = mytable.update().values(
1102 description=cast(from_dml_column(mytable.c.updated_at), String)
1103 + " "
1104 + from_dml_column(mytable.c.name)
1105 )
1106
1107 self.assert_compile(
1108 stmt,
1109 "UPDATE mytable_with_onupdate SET "
1110 "description=(CAST(now() AS VARCHAR) || :param_1 || "
1111 "mytable_with_onupdate.name), updated_at=now()",
1112 )
1113
1114 stmt = mytable.update().values(
1115 name="some name",
1116 description=cast(from_dml_column(mytable.c.updated_at), String)
1117 + " "
1118 + from_dml_column(mytable.c.name),
1119 )
1120
1121 self.assert_compile(
1122 stmt,
1123 "UPDATE mytable_with_onupdate SET "
1124 "name=:name, "
1125 "description=(CAST(now() AS VARCHAR) || :param_1 || "
1126 ":name), updated_at=now()",
1127 checkparams={"name": "some name", "param_1": " "},
1128 )
1129 self.assert_compile(
1130 stmt,
1131 "UPDATE mytable_with_onupdate SET "
1132 "name=?, "

Callers

nothing calls this directly

Calls 5

from_dml_columnFunction · 0.90
castFunction · 0.90
assert_compileMethod · 0.80
valuesMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected