(self)
| 113 | cursor.close() |
| 114 | |
| 115 | def test_execution_time_limit(self): |
| 116 | # this method is similarly implemented in test_cursor |
| 117 | |
| 118 | conn = self.connect() |
| 119 | |
| 120 | # table creation and filling is SSCursor only as it's not provided by self.setUp() |
| 121 | self.safe_create_table( |
| 122 | conn, |
| 123 | "test", |
| 124 | "create table test (data varchar(10))", |
| 125 | ) |
| 126 | with conn.cursor() as cur: |
| 127 | cur.execute( |
| 128 | "insert into test (data) values " |
| 129 | "('row1'), ('row2'), ('row3'), ('row4'), ('row5')" |
| 130 | ) |
| 131 | conn.commit() |
| 132 | |
| 133 | db_type = self.get_mysql_vendor(conn) |
| 134 | |
| 135 | with conn.cursor(pymysql.cursors.SSCursor) as cur: |
| 136 | # MySQL MAX_EXECUTION_TIME takes ms |
| 137 | # MariaDB max_statement_time takes seconds as int/float, introduced in 10.1 |
| 138 | |
| 139 | # this will sleep 0.01 seconds per row |
| 140 | if db_type == "mysql": |
| 141 | sql = ( |
| 142 | "SELECT /*+ MAX_EXECUTION_TIME(2000) */ data, sleep(0.01) FROM test" |
| 143 | ) |
| 144 | else: |
| 145 | sql = "SET STATEMENT max_statement_time=2 FOR SELECT data, sleep(0.01) FROM test" |
| 146 | |
| 147 | cur.execute(sql) |
| 148 | # unlike Cursor, SSCursor returns a list of tuples here |
| 149 | self.assertEqual( |
| 150 | cur.fetchall(), |
| 151 | [ |
| 152 | ("row1", 0), |
| 153 | ("row2", 0), |
| 154 | ("row3", 0), |
| 155 | ("row4", 0), |
| 156 | ("row5", 0), |
| 157 | ], |
| 158 | ) |
| 159 | |
| 160 | if db_type == "mysql": |
| 161 | sql = ( |
| 162 | "SELECT /*+ MAX_EXECUTION_TIME(2000) */ data, sleep(0.01) FROM test" |
| 163 | ) |
| 164 | else: |
| 165 | sql = "SET STATEMENT max_statement_time=2 FOR SELECT data, sleep(0.01) FROM test" |
| 166 | cur.execute(sql) |
| 167 | self.assertEqual(cur.fetchone(), ("row1", 0)) |
| 168 | |
| 169 | # this discards the previous unfinished query and raises an |
| 170 | # incomplete unbuffered query warning |
| 171 | with pytest.warns(UserWarning): |
| 172 | cur.execute("SELECT 1") |
nothing calls this directly
no test coverage detected