MCPcopy Index your code
hub / github.com/sqlalchemy/sqlalchemy / test_from_sql_default

Method test_from_sql_default

test/sql/test_insert.py:1243–1290  ·  view source on GitHub ↗

test combinations with a column that has a SQL default

(self)

Source from the content-addressed store, hash-verified

1241 stmt.compile()
1242
1243 def test_from_sql_default(self):
1244 """test combinations with a column that has a SQL default"""
1245
1246 mytable = self.tables.mytable_w_sql_default
1247 stmt = mytable.insert().values(
1248 description=from_dml_column(mytable.c.created_at)
1249 )
1250
1251 self.assert_compile(
1252 stmt,
1253 "INSERT INTO mytable_w_sql_default (description, created_at) "
1254 "VALUES (now(), now())",
1255 )
1256
1257 stmt = mytable.insert().values(
1258 description=cast(from_dml_column(mytable.c.created_at), String)
1259 + " o clock"
1260 )
1261
1262 self.assert_compile(
1263 stmt,
1264 "INSERT INTO mytable_w_sql_default (description, created_at) "
1265 "VALUES ((CAST(now() AS VARCHAR) || :param_1), now())",
1266 )
1267
1268 stmt = mytable.insert().values(
1269 name="some name",
1270 description=cast(from_dml_column(mytable.c.created_at), String)
1271 + " "
1272 + from_dml_column(mytable.c.name),
1273 )
1274
1275 self.assert_compile(
1276 stmt,
1277 "INSERT INTO mytable_w_sql_default "
1278 "(name, description, created_at) VALUES "
1279 "(:name, (CAST(now() AS VARCHAR) || :param_1 || :name), now())",
1280 checkparams={"name": "some name", "param_1": " "},
1281 )
1282 self.assert_compile(
1283 stmt,
1284 "INSERT INTO mytable_w_sql_default "
1285 "(name, description, created_at) VALUES "
1286 "(?, (CAST(CURRENT_TIMESTAMP AS VARCHAR) || ? || ?), "
1287 "CURRENT_TIMESTAMP)",
1288 checkpositional=("some name", " ", "some name"),
1289 dialect="sqlite",
1290 )
1291
1292 def test_from_sql_expr(self):
1293 mytable = self.tables.mytable

Callers

nothing calls this directly

Calls 5

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

Tested by

no test coverage detected