1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
|
import sqlalchemy as sa
from sqlalchemy import BigInteger
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import Sequence
from sqlalchemy import String
from sqlalchemy import testing
from sqlalchemy.dialects import sqlite
from sqlalchemy.schema import CreateSequence
from sqlalchemy.schema import DropSequence
from sqlalchemy.sql import select
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import config
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
from sqlalchemy.testing import is_false
from sqlalchemy.testing import is_true
from sqlalchemy.testing.assertions import expect_deprecated
from sqlalchemy.testing.assertsql import AllOf
from sqlalchemy.testing.assertsql import CompiledSQL
from sqlalchemy.testing.assertsql import EachOf
from sqlalchemy.testing.provision import normalize_sequence
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
class SequenceDDLTest(fixtures.TestBase, testing.AssertsCompiledSQL):
__dialect__ = "default"
__backend__ = True
@testing.combinations(
(Sequence("foo_seq"), ""),
(Sequence("foo_seq", start=5), "START WITH 5"),
(Sequence("foo_seq", increment=2), "INCREMENT BY 2"),
(
Sequence("foo_seq", increment=2, start=5),
"INCREMENT BY 2 START WITH 5",
),
(
Sequence("foo_seq", increment=2, start=0, minvalue=0),
"INCREMENT BY 2 START WITH 0 MINVALUE 0",
),
(
Sequence("foo_seq", increment=2, start=1, maxvalue=5),
"INCREMENT BY 2 START WITH 1 MAXVALUE 5",
),
(
Sequence("foo_seq", increment=2, start=1, nomaxvalue=True),
"INCREMENT BY 2 START WITH 1 NO MAXVALUE",
),
(
Sequence("foo_seq", increment=2, start=0, nominvalue=True),
"INCREMENT BY 2 START WITH 0 NO MINVALUE",
),
(
Sequence("foo_seq", start=1, maxvalue=10, cycle=True),
"START WITH 1 MAXVALUE 10 CYCLE",
),
(
Sequence("foo_seq", cache=1000),
"CACHE 1000",
),
(Sequence("foo_seq", minvalue=42), "MINVALUE 42"),
(Sequence("foo_seq", minvalue=-42), "MINVALUE -42"),
(
Sequence("foo_seq", minvalue=42, increment=2),
"INCREMENT BY 2 MINVALUE 42",
),
(
Sequence("foo_seq", minvalue=-42, increment=2),
"INCREMENT BY 2 MINVALUE -42",
),
(
Sequence("foo_seq", minvalue=42, increment=-2),
"INCREMENT BY -2 MINVALUE 42",
),
(
# remove this when the `order` parameter is removed
# issue #10207 - ensure ORDER does not render
Sequence("foo_seq", order=True),
"",
),
(
Sequence("foo_seq", minvalue=-42, increment=-2),
"INCREMENT BY -2 MINVALUE -42",
),
(Sequence("foo_seq", maxvalue=99), "MAXVALUE 99"),
(Sequence("foo_seq", maxvalue=-99), "MAXVALUE -99"),
(
Sequence("foo_seq", maxvalue=99, increment=2),
"INCREMENT BY 2 MAXVALUE 99",
),
(
Sequence("foo_seq", maxvalue=99, increment=-2),
"INCREMENT BY -2 MAXVALUE 99",
),
(
Sequence("foo_seq", maxvalue=-99, increment=-2),
"INCREMENT BY -2 MAXVALUE -99",
),
(
Sequence("foo_seq", minvalue=42, maxvalue=99),
"MINVALUE 42 MAXVALUE 99",
),
(
Sequence("foo_seq", minvalue=42, maxvalue=99, increment=2),
"INCREMENT BY 2 MINVALUE 42 MAXVALUE 99",
),
(
Sequence("foo_seq", minvalue=-42, maxvalue=-9, increment=2),
"INCREMENT BY 2 MINVALUE -42 MAXVALUE -9",
),
(
Sequence("foo_seq", minvalue=42, maxvalue=99, increment=-2),
"INCREMENT BY -2 MINVALUE 42 MAXVALUE 99",
),
(
Sequence("foo_seq", minvalue=-42, maxvalue=-9, increment=-2),
"INCREMENT BY -2 MINVALUE -42 MAXVALUE -9",
),
)
def test_create_ddl(self, sequence, sql):
before = sequence.start
self.assert_compile(
CreateSequence(sequence),
("CREATE SEQUENCE foo_seq " + sql).strip(),
)
eq_(sequence.start, before)
def test_drop_ddl(self):
self.assert_compile(
CreateSequence(Sequence("foo_seq"), if_not_exists=True),
"CREATE SEQUENCE IF NOT EXISTS foo_seq",
)
self.assert_compile(
DropSequence(Sequence("foo_seq")), "DROP SEQUENCE foo_seq"
)
self.assert_compile(
DropSequence(Sequence("foo_seq"), if_exists=True),
"DROP SEQUENCE IF EXISTS foo_seq",
)
class SequenceExecTest(fixtures.TestBase):
__requires__ = ("sequences",)
__backend__ = True
@classmethod
def setup_test_class(cls):
cls.seq = normalize_sequence(config, Sequence("my_sequence"))
cls.seq.create(testing.db)
@classmethod
def teardown_test_class(cls):
cls.seq.drop(testing.db)
def _assert_seq_result(self, ret):
"""asserts return of next_value is an int"""
assert isinstance(ret, int)
assert ret >= testing.db.dialect.default_sequence_base
def test_execute(self, connection):
s = normalize_sequence(config, Sequence("my_sequence"))
self._assert_seq_result(connection.scalar(s))
def test_execute_deprecated(self, connection):
s = normalize_sequence(config, Sequence("my_sequence", optional=True))
with expect_deprecated(
r"Using the .execute\(\) method to invoke a "
r"DefaultGenerator object is deprecated; please use "
r"the .scalar\(\) method."
):
self._assert_seq_result(connection.execute(s))
def test_scalar_optional(self, connection):
"""test dialect executes a Sequence, returns nextval, whether
or not "optional" is set"""
s = normalize_sequence(config, Sequence("my_sequence", optional=True))
self._assert_seq_result(connection.scalar(s))
def test_execute_next_value(self, connection):
"""test func.next_value().execute()/.scalar() works
with connectionless execution."""
s = normalize_sequence(config, Sequence("my_sequence"))
self._assert_seq_result(connection.scalar(s.next_value()))
def test_execute_optional_next_value(self, connection):
"""test func.next_value().execute()/.scalar() works
with connectionless execution."""
s = normalize_sequence(config, Sequence("my_sequence", optional=True))
self._assert_seq_result(connection.scalar(s.next_value()))
def test_func_embedded_select(self, connection):
"""test can use next_value() in select column expr"""
s = normalize_sequence(config, Sequence("my_sequence"))
self._assert_seq_result(connection.scalar(select(s.next_value())))
@testing.requires.sequences_in_other_clauses
@testing.provide_metadata
def test_func_embedded_whereclause(self, connection):
"""test can use next_value() in whereclause"""
metadata = self.metadata
t1 = Table("t", metadata, Column("x", Integer))
t1.create(testing.db)
connection.execute(t1.insert(), [{"x": 1}, {"x": 300}, {"x": 301}])
s = normalize_sequence(config, Sequence("my_sequence"))
eq_(
list(
connection.execute(t1.select().where(t1.c.x > s.next_value()))
),
[(300,), (301,)],
)
@testing.provide_metadata
def test_func_embedded_valuesbase(self, connection):
"""test can use next_value() in values() of _ValuesBase"""
metadata = self.metadata
t1 = Table(
"t",
metadata,
Column("x", Integer),
)
t1.create(testing.db)
s = normalize_sequence(config, Sequence("my_sequence"))
connection.execute(t1.insert().values(x=s.next_value()))
self._assert_seq_result(connection.scalar(t1.select()))
def test_inserted_pk_no_returning(self, metadata, connection):
"""test inserted_primary_key contains [None] when
pk_col=next_value(), implicit returning is not used."""
# I'm not really sure what this test wants to accomlish.
t1 = Table(
"t",
metadata,
Column("x", Integer, primary_key=True),
implicit_returning=False,
)
s = normalize_sequence(
config, Sequence("my_sequence_here", metadata=metadata)
)
conn = connection
t1.create(conn)
s.create(conn)
r = conn.execute(t1.insert().values(x=s.next_value()))
if testing.requires.emulated_lastrowid_even_with_sequences.enabled:
eq_(r.inserted_primary_key, (1,))
else:
eq_(r.inserted_primary_key, (None,))
@testing.combinations(
("implicit_returning",),
("no_implicit_returning",),
("explicit_returning", testing.requires.insert_returning),
(
"return_defaults_no_implicit_returning",
testing.requires.insert_returning,
),
(
"return_defaults_implicit_returning",
testing.requires.insert_returning,
),
argnames="returning",
)
@testing.requires.multivalues_inserts
def test_seq_multivalues_inline(self, metadata, connection, returning):
_implicit_returning = "no_implicit_returning" not in returning
t1 = Table(
"t",
metadata,
Column(
"x",
Integer,
normalize_sequence(config, Sequence("my_seq")),
primary_key=True,
),
Column("data", String(50)),
implicit_returning=_implicit_returning,
)
metadata.create_all(connection)
conn = connection
stmt = t1.insert().values(
[{"data": "d1"}, {"data": "d2"}, {"data": "d3"}]
)
if returning == "explicit_returning":
stmt = stmt.returning(t1.c.x)
elif "return_defaults" in returning:
stmt = stmt.return_defaults()
r = conn.execute(stmt)
if returning == "explicit_returning":
eq_(r.all(), [(1,), (2,), (3,)])
elif "return_defaults" in returning:
eq_(r.returned_defaults_rows, None)
# TODO: not sure what this is
eq_(r.inserted_primary_key_rows, [(None,)])
eq_(
conn.execute(t1.select().order_by(t1.c.x)).all(),
[(1, "d1"), (2, "d2"), (3, "d3")],
)
@testing.combinations(
("implicit_returning",),
("no_implicit_returning",),
(
"explicit_returning",
testing.requires.insert_returning
+ testing.requires.insert_executemany_returning,
),
(
"return_defaults_no_implicit_returning",
testing.requires.insert_returning
+ testing.requires.insert_executemany_returning,
),
(
"return_defaults_implicit_returning",
testing.requires.insert_returning
+ testing.requires.insert_executemany_returning,
),
argnames="returning",
)
def test_seq_multivalues_executemany(
self, connection, metadata, returning
):
_implicit_returning = "no_implicit_returning" not in returning
t1 = Table(
"t",
metadata,
Column(
"x",
Integer,
normalize_sequence(config, Sequence("my_seq")),
primary_key=True,
),
Column("data", String(50)),
implicit_returning=_implicit_returning,
)
metadata.create_all(connection)
conn = connection
stmt = t1.insert()
if returning == "explicit_returning":
stmt = stmt.returning(t1.c.x)
elif "return_defaults" in returning:
stmt = stmt.return_defaults()
r = conn.execute(
stmt, [{"data": "d1"}, {"data": "d2"}, {"data": "d3"}]
)
if returning == "explicit_returning":
eq_(r.all(), [(1,), (2,), (3,)])
elif "return_defaults" in returning:
if "no_implicit_returning" in returning:
eq_(r.returned_defaults_rows, None)
eq_(r.inserted_primary_key_rows, [(1,), (2,), (3,)])
else:
eq_(r.returned_defaults_rows, [(1,), (2,), (3,)])
eq_(r.inserted_primary_key_rows, [(1,), (2,), (3,)])
eq_(
conn.execute(t1.select().order_by(t1.c.x)).all(),
[(1, "d1"), (2, "d2"), (3, "d3")],
)
@testing.requires.insert_returning
def test_inserted_pk_implicit_returning(self, connection, metadata):
"""test inserted_primary_key contains the result when
pk_col=next_value(), when implicit returning is used."""
s = normalize_sequence(config, Sequence("my_sequence"))
t1 = Table(
"t",
metadata,
Column(
"x",
Integer,
primary_key=True,
),
implicit_returning=True,
)
t1.create(connection)
r = connection.execute(t1.insert().values(x=s.next_value()))
self._assert_seq_result(r.inserted_primary_key[0])
class SequenceTest(fixtures.TestBase, testing.AssertsCompiledSQL):
__requires__ = ("sequences",)
__backend__ = True
@testing.combinations(
(Sequence("foo_seq"),),
(Sequence("foo_seq", start=8),),
(Sequence("foo_seq", increment=5),),
)
def test_start_increment(self, seq):
seq = normalize_sequence(config, seq)
seq.create(testing.db)
try:
with testing.db.connect() as conn:
values = [conn.scalar(seq) for i in range(3)]
start = seq.start or testing.db.dialect.default_sequence_base
inc = seq.increment or 1
eq_(values, list(range(start, start + inc * 3, inc)))
finally:
seq.drop(testing.db)
def _has_sequence(self, connection, name):
return testing.db.dialect.has_sequence(connection, name)
def test_nextval_unsupported(self):
"""test next_value() used on non-sequence platform
raises NotImplementedError."""
s = normalize_sequence(config, Sequence("my_seq"))
d = sqlite.dialect()
assert_raises_message(
NotImplementedError,
"Dialect 'sqlite' does not support sequence increments.",
s.next_value().compile,
dialect=d,
)
def test_checkfirst_sequence(self, connection):
s = normalize_sequence(config, Sequence("my_sequence"))
s.create(connection, checkfirst=False)
assert self._has_sequence(connection, "my_sequence")
s.create(connection, checkfirst=True)
s.drop(connection, checkfirst=False)
assert not self._has_sequence(connection, "my_sequence")
s.drop(connection, checkfirst=True)
def test_checkfirst_metadata(self, connection):
m = MetaData()
Sequence("my_sequence", metadata=m)
m.create_all(connection, checkfirst=False)
assert self._has_sequence(connection, "my_sequence")
m.create_all(connection, checkfirst=True)
m.drop_all(connection, checkfirst=False)
assert not self._has_sequence(connection, "my_sequence")
m.drop_all(connection, checkfirst=True)
def test_checkfirst_table(self, connection):
m = MetaData()
s = normalize_sequence(config, Sequence("my_sequence"))
t = Table("t", m, Column("c", Integer, s, primary_key=True))
t.create(connection, checkfirst=False)
assert self._has_sequence(connection, "my_sequence")
t.create(connection, checkfirst=True)
t.drop(connection, checkfirst=False)
assert not self._has_sequence(connection, "my_sequence")
t.drop(connection, checkfirst=True)
@testing.provide_metadata
def test_table_overrides_metadata_create(self, connection):
metadata = self.metadata
normalize_sequence(config, Sequence("s1", metadata=metadata))
s2 = normalize_sequence(config, Sequence("s2", metadata=metadata))
s3 = normalize_sequence(config, Sequence("s3"))
t = Table("t", metadata, Column("c", Integer, s3, primary_key=True))
assert s3.metadata is metadata
t.create(connection, checkfirst=True)
s3.drop(connection)
# 't' is created, and 's3' won't be
# re-created since it's linked to 't'.
# 's1' and 's2' are, however.
metadata.create_all(connection)
assert self._has_sequence(connection, "s1")
assert self._has_sequence(connection, "s2")
assert not self._has_sequence(connection, "s3")
s2.drop(connection)
assert self._has_sequence(connection, "s1")
assert not self._has_sequence(connection, "s2")
metadata.drop_all(connection)
assert not self._has_sequence(connection, "s1")
assert not self._has_sequence(connection, "s2")
@testing.requires.insert_returning
@testing.requires.supports_sequence_for_autoincrement_column
@testing.provide_metadata
def test_freestanding_sequence_via_autoinc(self, connection):
t = Table(
"some_table",
self.metadata,
Column(
"id",
Integer,
autoincrement=True,
primary_key=True,
default=normalize_sequence(
config, Sequence("my_sequence", metadata=self.metadata)
).next_value(),
),
)
self.metadata.create_all(connection)
result = connection.execute(t.insert())
eq_(result.inserted_primary_key, (1,))
@testing.requires.sequences_as_server_defaults
@testing.provide_metadata
def test_shared_sequence(self, connection):
# test case for #6071
common_seq = normalize_sequence(
config, Sequence("common_sequence", metadata=self.metadata)
)
Table(
"table_1",
self.metadata,
Column(
"id",
Integer,
common_seq,
server_default=common_seq.next_value(),
primary_key=True,
),
)
Table(
"table_2",
self.metadata,
Column(
"id",
Integer,
common_seq,
server_default=common_seq.next_value(),
primary_key=True,
),
)
self.metadata.create_all(connection)
is_true(self._has_sequence(connection, "common_sequence"))
is_true(testing.db.dialect.has_table(connection, "table_1"))
is_true(testing.db.dialect.has_table(connection, "table_2"))
self.metadata.drop_all(connection)
is_false(self._has_sequence(connection, "common_sequence"))
is_false(testing.db.dialect.has_table(connection, "table_1"))
is_false(testing.db.dialect.has_table(connection, "table_2"))
def test_next_value_type(self):
seq = normalize_sequence(
config, Sequence("my_sequence", data_type=BigInteger)
)
assert isinstance(seq.next_value().type, BigInteger)
class TableBoundSequenceTest(fixtures.TablesTest):
__requires__ = ("sequences",)
__backend__ = True
@testing.fixture
def table_fixture(self, metadata, connection, implicit_returning):
def go(implicit_returning):
cartitems = Table(
"cartitems",
metadata,
Column(
"cart_id",
Integer,
normalize_sequence(config, Sequence("cart_id_seq")),
primary_key=True,
autoincrement=False,
),
Column("description", String(40)),
Column("createdate", sa.DateTime()),
implicit_returning=implicit_returning,
)
# a little bit of implicit case sensitive naming test going on here
Manager = Table(
"Manager",
metadata,
Column(
"obj_id",
Integer,
normalize_sequence(config, Sequence("obj_id_seq")),
),
Column("name", String(128)),
Column(
"id",
Integer,
normalize_sequence(
config, Sequence("Manager_id_seq", optional=True)
),
primary_key=True,
),
implicit_returning=implicit_returning,
)
metadata.create_all(connection)
return Manager, cartitems
return go
@testing.combinations(
(True, testing.requires.insert_returning),
(False,),
argnames="implicit_returning",
)
def test_insert_via_seq(
self, table_fixture, connection, implicit_returning
):
Manager, cartitems = table_fixture(implicit_returning)
connection.execute(cartitems.insert(), dict(description="hi"))
connection.execute(cartitems.insert(), dict(description="there"))
r = connection.execute(cartitems.insert(), dict(description="lala"))
expected = 2 + testing.db.dialect.default_sequence_base
eq_(r.inserted_primary_key[0], expected)
eq_(
connection.scalar(
sa.select(cartitems.c.cart_id).where(
cartitems.c.description == "lala"
),
),
expected,
)
@testing.combinations(
(True, testing.requires.insert_returning),
(False,),
argnames="implicit_returning",
)
def test_seq_nonpk(self, connection, table_fixture, implicit_returning):
"""test sequences fire off as defaults on non-pk columns"""
sometable, cartitems = table_fixture(implicit_returning)
conn = connection
result = conn.execute(sometable.insert(), dict(name="somename"))
eq_(result.postfetch_cols(), [sometable.c.obj_id])
result = conn.execute(sometable.insert(), dict(name="someother"))
conn.execute(
sometable.insert(), [{"name": "name3"}, {"name": "name4"}]
)
dsb = testing.db.dialect.default_sequence_base
eq_(
list(conn.execute(sometable.select().order_by(sometable.c.id))),
[
(
dsb,
"somename",
dsb,
),
(
dsb + 1,
"someother",
dsb + 1,
),
(
dsb + 2,
"name3",
dsb + 2,
),
(
dsb + 3,
"name4",
dsb + 3,
),
],
)
class SequenceAsServerDefaultTest(
testing.AssertsExecutionResults, fixtures.TablesTest
):
__requires__ = ("sequences_as_server_defaults",)
__backend__ = True
run_create_tables = "each"
@classmethod
def define_tables(cls, metadata):
m = metadata
s = normalize_sequence(config, Sequence("t_seq", metadata=m))
Table(
"t_seq_test",
m,
Column("id", Integer, s, server_default=s.next_value()),
Column("data", String(50)),
)
s2 = normalize_sequence(config, Sequence("t_seq_2", metadata=m))
Table(
"t_seq_test_2",
m,
Column("id", Integer, server_default=s2.next_value()),
Column("data", String(50)),
)
def test_default_textual_w_default(self, connection):
connection.exec_driver_sql(
"insert into t_seq_test (data) values ('some data')"
)
eq_(
connection.exec_driver_sql("select id from t_seq_test").scalar(), 1
)
def test_default_core_w_default(self, connection):
t_seq_test = self.tables.t_seq_test
connection.execute(t_seq_test.insert().values(data="some data"))
eq_(connection.scalar(select(t_seq_test.c.id)), 1)
def test_default_textual_server_only(self, connection):
connection.exec_driver_sql(
"insert into t_seq_test_2 (data) values ('some data')"
)
eq_(
connection.exec_driver_sql("select id from t_seq_test_2").scalar(),
1,
)
def test_default_core_server_only(self, connection):
t_seq_test = self.tables.t_seq_test_2
connection.execute(t_seq_test.insert().values(data="some data"))
eq_(connection.scalar(select(t_seq_test.c.id)), 1)
def test_drop_ordering(self):
with self.sql_execution_asserter(testing.db) as asserter:
self.tables_test_metadata.drop_all(testing.db, checkfirst=False)
asserter.assert_(
AllOf(
CompiledSQL("DROP TABLE t_seq_test_2", {}),
CompiledSQL("DROP TABLE t_seq_test", {}),
),
AllOf(
# dropped as part of metadata level
CompiledSQL("DROP SEQUENCE t_seq", {}),
CompiledSQL("DROP SEQUENCE t_seq_2", {}),
),
)
def test_drop_ordering_single_table(self):
with self.sql_execution_asserter(testing.db) as asserter:
for table in self.tables_test_metadata.tables.values():
table.drop(testing.db, checkfirst=False)
asserter.assert_(
AllOf(
CompiledSQL("DROP TABLE t_seq_test_2", {}),
EachOf(
CompiledSQL("DROP TABLE t_seq_test", {}),
CompiledSQL("DROP SEQUENCE t_seq", {}),
),
)
)
|