Tests sending functions and SQL expressions to the VALUES and SET clauses of INSERT/UPDATE instances, and that column-level defaults get overridden.
(self, connection)
| 1443 | |
| 1444 | @testing.provide_metadata |
| 1445 | def test_update(self, connection): |
| 1446 | """ |
| 1447 | Tests sending functions and SQL expressions to the VALUES and SET |
| 1448 | clauses of INSERT/UPDATE instances, and that column-level defaults |
| 1449 | get overridden. |
| 1450 | """ |
| 1451 | |
| 1452 | meta = self.metadata |
| 1453 | t = Table( |
| 1454 | "t1", |
| 1455 | meta, |
| 1456 | Column( |
| 1457 | "id", |
| 1458 | Integer, |
| 1459 | normalize_sequence(config, Sequence("t1idseq", optional=True)), |
| 1460 | primary_key=True, |
| 1461 | ), |
| 1462 | Column("value", Integer), |
| 1463 | ) |
| 1464 | t2 = Table( |
| 1465 | "t2", |
| 1466 | meta, |
| 1467 | Column( |
| 1468 | "id", |
| 1469 | Integer, |
| 1470 | normalize_sequence(config, Sequence("t2idseq", optional=True)), |
| 1471 | primary_key=True, |
| 1472 | ), |
| 1473 | Column("value", Integer, default=7), |
| 1474 | Column("stuff", String(20), onupdate="thisisstuff"), |
| 1475 | ) |
| 1476 | meta.create_all(connection) |
| 1477 | connection.execute(t.insert().values(value=func.length("one"))) |
| 1478 | eq_(connection.execute(t.select()).first().value, 3) |
| 1479 | connection.execute(t.update().values(value=func.length("asfda"))) |
| 1480 | eq_(connection.execute(t.select()).first().value, 5) |
| 1481 | |
| 1482 | r = connection.execute( |
| 1483 | t.insert().values(value=func.length("sfsaafsda")) |
| 1484 | ) |
| 1485 | id_ = r.inserted_primary_key[0] |
| 1486 | eq_( |
| 1487 | connection.execute(t.select().where(t.c.id == id_)).first().value, |
| 1488 | 9, |
| 1489 | ) |
| 1490 | connection.execute(t.update().values({t.c.value: func.length("asdf")})) |
| 1491 | eq_(connection.execute(t.select()).first().value, 4) |
| 1492 | connection.execute(t2.insert()) |
| 1493 | connection.execute(t2.insert().values(value=func.length("one"))) |
| 1494 | connection.execute( |
| 1495 | t2.insert().values(value=func.length("asfda") + -19), |
| 1496 | dict(stuff="hi"), |
| 1497 | ) |
| 1498 | |
| 1499 | res = sorted(connection.execute(select(t2.c.value, t2.c.stuff))) |
| 1500 | eq_(res, [(-14, "hi"), (3, None), (7, None)]) |
| 1501 | |
| 1502 | connection.execute( |
nothing calls this directly
no test coverage detected