Skip to content

Commit

Permalink
Merge ddef74f into 2f1f679
Browse files Browse the repository at this point in the history
  • Loading branch information
Charl1996 committed Jun 14, 2021
2 parents 2f1f679 + ddef74f commit 64fe9f0
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions commcare_export/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ def _get_writer(output_format, output, strict_types):
elif output_format == 'sql':
# Output should be a connection URL
# Writer had bizarre issues so we use a full connection instead of passing in a URL or engine
if output.startswith('mysql'):
charset_split = output.split('charset=')
if len(charset_split) > 1 and charset_split[1] != 'utf8mb4':
raise Exception(f"The charset '{charset_split[1]}' might cause problems with the export. "
f"It is recommended that you use 'utf8mb4' instead.")

return writers.SqlTableWriter(output, strict_types)
else:
raise Exception("Unknown output format: {}".format(output_format))
Expand Down
2 changes: 1 addition & 1 deletion commcare_export/writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ class SqlMixin(object):

def __init__(self, db_url, poolclass=None, engine=None):
self.db_url = db_url
self.collation = 'utf8_bin' if 'mysql' in db_url else None
self.collation = 'utf8mb4_unicode_ci' if 'mysql' in db_url else None
self.engine = engine or sqlalchemy.create_engine(db_url, poolclass=poolclass)

def __enter__(self):
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def tear_down():
'admin_db': 'postgres'
}, marks=pytest.mark.postgres),
pytest.param({
'url': '{}%s?charset=utf8'.format(mysql_base),
'url': '{}%s?charset=utf8mb4'.format(mysql_base),
}, marks=pytest.mark.mysql),
pytest.param({
'url': '{}%s?driver=ODBC+Driver+17+for+SQL+Server'.format(mssql_base),
Expand Down
10 changes: 10 additions & 0 deletions tests/test_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,16 @@ def test_mssql_nvarchar_length_downsize(self, writer):
result = self._get_column_lengths(writer.connection, 'mssql_nvarchar_length_downsize')
assert result['some_data'] == ('some_data', 'nvarchar', -1)

def test_big_lump_of_poo(self, writer):
with writer:
writer.write_table(TableSpec(**{
'name': 'foo_with_emoji',
'headings': ['id', 'fun_to_be_had'],
'rows': [
['A steaming poo', '💩'],
['2020', '😷'],
],
}))

def _get_column_lengths(self, connection, table_name):
return {
Expand Down

0 comments on commit 64fe9f0

Please sign in to comment.