$99 GRAYBYTE WORDPRESS FILE MANAGER $13

SERVER : vnpttt-amd7f72-h1.vietnix.vn #1 SMP Fri May 24 12:42:50 UTC 2024
SERVER IP : 103.200.23.149 | ADMIN IP 216.73.216.22
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/lib64/python2.7/site-packages/sqlalchemy/testing/suite/

HOME
Current File : /lib64/python2.7/site-packages/sqlalchemy/testing/suite//test_rowcount.py
# testing/suite/test_rowcount.py
# Copyright (C) 2005-2024 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: https://www.opensource.org/licenses/mit-license.php
from sqlalchemy import bindparam
from sqlalchemy import Column
from sqlalchemy import Integer
from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy import Table
from sqlalchemy import testing
from sqlalchemy import text
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures


class RowCountTest(fixtures.TablesTest):
    """test rowcount functionality"""

    __requires__ = ("sane_rowcount",)
    __backend__ = True

    @classmethod
    def define_tables(cls, metadata):
        Table(
            "employees",
            metadata,
            Column(
                "employee_id",
                Integer,
                autoincrement=False,
                primary_key=True,
            ),
            Column("name", String(50)),
            Column("department", String(1)),
        )

    @classmethod
    def insert_data(cls, connection):
        cls.data = data = [
            ("Angela", "A"),
            ("Andrew", "A"),
            ("Anand", "A"),
            ("Bob", "B"),
            ("Bobette", "B"),
            ("Buffy", "B"),
            ("Charlie", "C"),
            ("Cynthia", "C"),
            ("Chris", "C"),
        ]

        employees_table = cls.tables.employees
        connection.execute(
            employees_table.insert(),
            [
                {"employee_id": i, "name": n, "department": d}
                for i, (n, d) in enumerate(data)
            ],
        )

    def test_basic(self, connection):
        employees_table = self.tables.employees
        s = select(
            employees_table.c.name, employees_table.c.department
        ).order_by(employees_table.c.employee_id)
        rows = connection.execute(s).fetchall()

        eq_(rows, self.data)

    def test_update_rowcount1(self, connection):
        employees_table = self.tables.employees

        # WHERE matches 3, 3 rows changed
        department = employees_table.c.department
        r = connection.execute(
            employees_table.update().where(department == "C"),
            {"department": "Z"},
        )
        assert r.rowcount == 3

    def test_update_rowcount2(self, connection):
        employees_table = self.tables.employees

        # WHERE matches 3, 0 rows changed
        department = employees_table.c.department

        r = connection.execute(
            employees_table.update().where(department == "C"),
            {"department": "C"},
        )
        eq_(r.rowcount, 3)

    @testing.requires.sane_rowcount_w_returning
    def test_update_rowcount_return_defaults(self, connection):
        employees_table = self.tables.employees

        department = employees_table.c.department
        stmt = (
            employees_table.update()
            .where(department == "C")
            .values(name=employees_table.c.department + "Z")
            .return_defaults()
        )

        r = connection.execute(stmt)
        eq_(r.rowcount, 3)

    def test_raw_sql_rowcount(self, connection):
        # test issue #3622, make sure eager rowcount is called for text
        result = connection.exec_driver_sql(
            "update employees set department='Z' where department='C'"
        )
        eq_(result.rowcount, 3)

    def test_text_rowcount(self, connection):
        # test issue #3622, make sure eager rowcount is called for text
        result = connection.execute(
            text("update employees set department='Z' " "where department='C'")
        )
        eq_(result.rowcount, 3)

    def test_delete_rowcount(self, connection):
        employees_table = self.tables.employees

        # WHERE matches 3, 3 rows deleted
        department = employees_table.c.department
        r = connection.execute(
            employees_table.delete().where(department == "C")
        )
        eq_(r.rowcount, 3)

    @testing.requires.sane_multi_rowcount
    def test_multi_update_rowcount(self, connection):
        employees_table = self.tables.employees
        stmt = (
            employees_table.update()
            .where(employees_table.c.name == bindparam("emp_name"))
            .values(department="C")
        )

        r = connection.execute(
            stmt,
            [
                {"emp_name": "Bob"},
                {"emp_name": "Cynthia"},
                {"emp_name": "nonexistent"},
            ],
        )

        eq_(r.rowcount, 2)

    @testing.requires.sane_multi_rowcount
    def test_multi_delete_rowcount(self, connection):
        employees_table = self.tables.employees

        stmt = employees_table.delete().where(
            employees_table.c.name == bindparam("emp_name")
        )

        r = connection.execute(
            stmt,
            [
                {"emp_name": "Bob"},
                {"emp_name": "Cynthia"},
                {"emp_name": "nonexistent"},
            ],
        )

        eq_(r.rowcount, 2)

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
23 Sep 2024 10.41 AM
root / root
0755
__init__.py
0.705 KB
5 Sep 2024 10.50 PM
root / root
0644
__init__.pyc
0.544 KB
23 Sep 2024 10.41 AM
root / root
0644
test_cte.py
6.278 KB
5 Sep 2024 10.50 PM
root / root
0644
test_cte.pyc
5.922 KB
23 Sep 2024 10.41 AM
root / root
0644
test_ddl.py
11.727 KB
5 Sep 2024 10.50 PM
root / root
0644
test_ddl.pyc
13.649 KB
23 Sep 2024 10.41 AM
root / root
0644
test_deprecations.py
5.189 KB
5 Sep 2024 10.50 PM
root / root
0644
test_deprecations.pyc
5.749 KB
23 Sep 2024 10.41 AM
root / root
0644
test_dialect.py
12.845 KB
5 Sep 2024 10.50 PM
root / root
0644
test_dialect.pyc
14.484 KB
23 Sep 2024 10.41 AM
root / root
0644
test_insert.py
11.116 KB
5 Sep 2024 10.50 PM
root / root
0644
test_insert.pyc
11.29 KB
23 Sep 2024 10.41 AM
root / root
0644
test_reflection.py
60.271 KB
5 Sep 2024 10.50 PM
root / root
0644
test_reflection.pyc
53.012 KB
23 Sep 2024 10.41 AM
root / root
0644
test_results.py
13.899 KB
5 Sep 2024 10.50 PM
root / root
0644
test_results.pyc
13.577 KB
23 Sep 2024 10.41 AM
root / root
0644
test_rowcount.py
5.008 KB
5 Sep 2024 10.50 PM
root / root
0644
test_rowcount.pyc
5.65 KB
23 Sep 2024 10.41 AM
root / root
0644
test_select.py
55.827 KB
5 Sep 2024 10.50 PM
root / root
0644
test_select.pyc
73.698 KB
23 Sep 2024 10.41 AM
root / root
0644
test_sequence.py
8.479 KB
5 Sep 2024 10.50 PM
root / root
0644
test_sequence.pyc
10.213 KB
23 Sep 2024 10.41 AM
root / root
0644
test_types.py
47.198 KB
5 Sep 2024 10.50 PM
root / root
0644
test_types.pyc
53.136 KB
23 Sep 2024 10.41 AM
root / root
0644
test_unicode_ddl.py
6.827 KB
5 Sep 2024 10.50 PM
root / root
0644
test_unicode_ddl.pyc
5.743 KB
23 Sep 2024 10.41 AM
root / root
0644
test_update_delete.py
1.837 KB
5 Sep 2024 10.50 PM
root / root
0644
test_update_delete.pyc
2.679 KB
23 Sep 2024 10.41 AM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF