Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError when insert unicode #2

Closed
void285 opened this issue May 16, 2019 · 0 comments
Closed

UnicodeEncodeError when insert unicode #2

void285 opened this issue May 16, 2019 · 0 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@void285
Copy link
Collaborator

void285 commented May 16, 2019

When do insert action, if I use unicode in data field, It raise the UnicodeEncodeError, if I use str, all is well.

# python2.7
db = Medoo(dbtype="sqlite", database="test.db")
name = "foobar"
data = u"测试中文数据"
db.insert('items', {'name': name, 'data': data, 'ctime': int(time.time())})
Traceback (most recent call last):
  File "test.py", line 24, in <module>
    db.insert('items', {'name': name, 'data': data, 'ctime': int(time.time())})
  File "C:\Python27\lib\site-packages\medoo\base.py", line 70, in insert
    sql = self.builder.insert(table, fields, *values)
  File "C:\Python27\lib\site-packages\medoo\builder.py", line 658, in insert
    self._insert(table, values2, fields)
  File "C:\Python27\lib\site-packages\medoo\builder.py", line 560, in _insert
    valterms.append('({})'.format(','.join([Builder.DIALECT.value(iv) for iv in inval])))
  File "C:\Python27\lib\site-packages\medoo\dialect.py", line 39, in value
    return "'{}'".format(str(item).replace("'", "''"))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)
@pwwang pwwang added bug Something isn't working good first issue Good for newcomers labels May 16, 2019
@pwwang pwwang closed this as completed in e6a9e81 May 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants