Skip to content

Commit b27a2bc

Browse files
authored
{rdbms-connect} Add support to read UTF-8 files with and without BOM (#5162)
1 parent b3d10f6 commit b27a2bc

File tree

6 files changed

+522
-319
lines changed

6 files changed

+522
-319
lines changed

src/rdbms-connect/HISTORY.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
Release History
44
===============
55

6+
1.0.3
7+
++++++
8+
+ Add support to read UTF-8 files with and without BOM
9+
610
1.0.2
711
++++++
812
+ Use compatible release for `setproctitle` to support Python 3.10

src/rdbms-connect/azext_rdbms_connect/custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ def _connect_execute_file(server_type, host, server_name, database_name, login_u
251251
logger.warning("Running sql file '%s'...", file_path)
252252
cursor = connection.cursor()
253253

254-
with open(file_path, "r", encoding="utf-8") as sql_file:
254+
with open(file_path, "r", encoding="utf-8-sig") as sql_file:
255255
cursor.execute(sql_file.read())
256256

257257
if server_type == 'postgres':

src/rdbms-connect/azext_rdbms_connect/tests/latest/recordings/test_mysql_flexible_server_connect.yaml

Lines changed: 258 additions & 162 deletions
Large diffs are not rendered by default.

src/rdbms-connect/azext_rdbms_connect/tests/latest/recordings/test_postgres_flexible_server_connect.yaml

Lines changed: 250 additions & 154 deletions
Large diffs are not rendered by default.

src/rdbms-connect/azext_rdbms_connect/tests/latest/test_rdbms-connect_scenario.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
class RdbmsConnectMgmtScenarioTest(ScenarioTest):
2525

2626
postgres_location = 'eastus'
27-
mysql_location = 'westus2'
27+
mysql_location = 'westus'
2828

2929
@AllowLargeResponse()
3030
@ResourceGroupPreparer(location=postgres_location)
@@ -107,6 +107,13 @@ def _test_successful_connect(self, database_engine, resource_group):
107107
self.cmd('{} flexible-server execute -n {} -u {} -p {} -d {} -f {}'
108108
.format(database_engine, server_name, username, generated_password, default_database, file_path))
109109

110+
# test file execution encoded with BOM
111+
with open(file_path, "wb") as sql_file:
112+
sql_file.write(b"\xef\xbb\xbfCREATE DATABASE sampledb2;")
113+
114+
self.cmd('{} flexible-server execute -n {} -u {} -p {} -d {} -f {}'
115+
.format(database_engine, server_name, username, generated_password, default_database, file_path))
116+
110117
os.remove(file_path)
111118

112119
def _test_vnet_connect(self, database_engine, resource_group):

src/rdbms-connect/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
# TODO: Confirm this is the right version number you want and it matches your
1818
# HISTORY.rst entry.
19-
VERSION = '1.0.2'
19+
VERSION = '1.0.3'
2020

2121
# The full list of classifiers is available at
2222
# https://pypi.python.org/pypi?%3Aaction=list_classifiers

0 commit comments

Comments
 (0)