Skip to content

Commit fc41f92

Browse files
authored
BUG: #34211 (#34212)
1 parent f1c03ad commit fc41f92

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

doc/source/whatsnew/v1.1.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,7 @@ I/O
872872
- Bug in :meth:`read_parquet` was raising a ``FileNotFoundError`` when passed an s3 directory path. (:issue:`26388`)
873873
- Bug in :meth:`~DataFrame.to_parquet` was throwing an ``AttributeError`` when writing a partitioned parquet file to s3 (:issue:`27596`)
874874
- Bug in :meth:`~DataFrame.to_excel` could not handle the column name `render` and was raising an ``KeyError`` (:issue:`34331`)
875+
- Bug in :meth:`~SQLDatabase.execute` was raising a ``ProgrammingError`` for some DB-API drivers when the SQL statement contained the `%` character and no parameters were present (:issue:`34211`)
875876

876877
Plotting
877878
^^^^^^^^

pandas/io/sql.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,9 @@ def run_transaction(self):
11621162

11631163
def execute(self, *args, **kwargs):
11641164
"""Simple passthrough to SQLAlchemy connectable"""
1165-
return self.connectable.execute(*args, **kwargs)
1165+
return self.connectable.execution_options(no_parameters=True).execute(
1166+
*args, **kwargs
1167+
)
11661168

11671169
def read_table(
11681170
self,

pandas/tests/io/test_sql.py

+10
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@
194194
"Name"=%(name)s AND "SepalLength"=%(length)s
195195
""",
196196
},
197+
"read_no_parameters_with_percent": {
198+
"sqlite": "SELECT * FROM iris WHERE Name LIKE '%'",
199+
"mysql": "SELECT * FROM iris WHERE `Name` LIKE '%'",
200+
"postgresql": "SELECT * FROM iris WHERE \"Name\" LIKE '%'",
201+
},
197202
"create_view": {
198203
"sqlite": """
199204
CREATE VIEW iris_view AS
@@ -424,6 +429,11 @@ def _read_sql_iris_named_parameter(self):
424429
iris_frame = self.pandasSQL.read_query(query, params=params)
425430
self._check_iris_loaded_frame(iris_frame)
426431

432+
def _read_sql_iris_no_parameter_with_percent(self):
433+
query = SQL_STRINGS["read_no_parameters_with_percent"][self.flavor]
434+
iris_frame = self.pandasSQL.read_query(query, params=None)
435+
self._check_iris_loaded_frame(iris_frame)
436+
427437
def _to_sql(self, method=None):
428438
self.drop_table("test_frame1")
429439

0 commit comments

Comments
 (0)