|
186 | 186 | "mysql": "SELECT * FROM iris WHERE `Name` LIKE '%'",
|
187 | 187 | "postgresql": "SELECT * FROM iris WHERE \"Name\" LIKE '%'",
|
188 | 188 | },
|
189 |
| - "create_view": { |
190 |
| - "sqlite": """ |
191 |
| - CREATE VIEW iris_view AS |
192 |
| - SELECT * FROM iris |
193 |
| - """ |
194 |
| - }, |
195 | 189 | }
|
196 | 190 |
|
197 | 191 |
|
@@ -256,6 +250,23 @@ def create_and_load_iris(conn, iris_file: Path, dialect: str):
|
256 | 250 | conn.execute(stmt)
|
257 | 251 |
|
258 | 252 |
|
| 253 | +def create_and_load_iris_view(conn): |
| 254 | + stmt = "CREATE VIEW iris_view AS SELECT * FROM iris" |
| 255 | + if isinstance(conn, sqlite3.Connection): |
| 256 | + cur = conn.cursor() |
| 257 | + cur.execute(stmt) |
| 258 | + else: |
| 259 | + from sqlalchemy import text |
| 260 | + from sqlalchemy.engine import Engine |
| 261 | + |
| 262 | + stmt = text(stmt) |
| 263 | + if isinstance(conn, Engine): |
| 264 | + with conn.connect() as conn: |
| 265 | + conn.execute(stmt) |
| 266 | + else: |
| 267 | + conn.execute(stmt) |
| 268 | + |
| 269 | + |
259 | 270 | @pytest.fixture
|
260 | 271 | def iris_path(datapath):
|
261 | 272 | iris_path = datapath("io", "data", "csv", "iris.csv")
|
@@ -391,10 +402,6 @@ def load_iris_data(self, iris_path):
|
391 | 402 | else:
|
392 | 403 | create_and_load_iris(self.conn, iris_path, self.flavor)
|
393 | 404 |
|
394 |
| - def _load_iris_view(self): |
395 |
| - self.drop_table("iris_view") |
396 |
| - self._get_exec().execute(SQL_STRINGS["create_view"][self.flavor]) |
397 |
| - |
398 | 405 | def _check_iris_loaded_frame(self, iris_frame):
|
399 | 406 | pytype = iris_frame.dtypes[0].type
|
400 | 407 | row = iris_frame.iloc[0]
|
@@ -697,7 +704,7 @@ def setup_method(self, load_iris_data):
|
697 | 704 | self.load_test_data_and_sql()
|
698 | 705 |
|
699 | 706 | def load_test_data_and_sql(self):
|
700 |
| - self._load_iris_view() |
| 707 | + create_and_load_iris_view(self.conn) |
701 | 708 | self._load_raw_sql()
|
702 | 709 |
|
703 | 710 | def test_read_sql_iris(self):
|
|
0 commit comments