uPyMySQL
uPyMySQL
Currently porting the PyMySQL pure-python implementation mysql client for use with micropython. Its a pretty ugly hack but I'm making progress. Right now though I'm stuck on a portion of code using super. I know from reading through the forums that the micropython implementation of super isn't that robust and was wondering if anyone has any experience with writing work arounds for the use of super and if they have some suggestions. If anyone would like to check out the project you can find it here: https://github.com/dvrhax/uPyMySQL I'm hoping to use this for a data-logger for a couple of projects I'm doing.
Thanks
Thanks
Re: uPyMySQL
So I finally deciphered what the super call was doing and was able to rewrite the classes using traditional inheritance with some duplication of code. My small test case is now working. Hopefully someone will find it useful beside myself. Still some limited functionality especially on the type conversion side as micropython has only limited support for things like datetime.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: uPyMySQL
Are you experiencing actual problems with super()? I had trouble in the past with it occasionally returning `None` but I haven't seen that for some time. You can of course replace it with a specific superclass name:
Code: Select all
class Foo():
def __init__(self):
pass
class Bar(Foo):
def __init__(self):
Foo.__init__(self) # replaces super().__init__()
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: uPyMySQL
I was getting the following error:
For this code snippet:
I ended up rewriting it and just bringing all the code from DictCursorMixin and the code from the _do_get_result method from the cursor class into DictCursor and remove the super call all together. I couldn't call the base class directly because DictCursorMixin is also referenced from another class in the same way, so I had to rewrite that as well.
Code: Select all
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test.py", line 16, in <module>
File "test.py", line 14, in <module>
File "pymysql/cursors.py", line 169, in execute
File "pymysql/cursors.py", line 326, in _query
File "pymysql/cursors.py", line 382, in _do_get_result
AttributeError: 'super' object has no attribute '_do_get_result'
Code: Select all
class DictCursorMixin(object):
# You can override this to use OrderedDict or other dict-like types.
dict_type = dict
def _do_get_result(self):
super(DictCursorMixin, self)._do_get_result()
fields = []
if self.description:
for f in self._result.fields:
name = f.name
if name in fields:
name = f.table_name + '.' + name
fields.append(name)
self._fields = fields
if fields and self._rows:
self._rows = [self._conv_row(r) for r in self._rows]
def _conv_row(self, row):
if row is None:
return None
return self.dict_type(zip(self._fields, row))
class DictCursor(DictCursorMixin, Cursor):
"""A cursor which returns results as a dictionary"""
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: uPyMySQL
OK. I've only used the zero-argument form of super() in MicroPython. Support for multiple inheritance may be incomplete - you might like to search GitHub issues. If you can produce a simple test case where MicroPython differs from CPython you could raise an issue.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: uPyMySQL
Posted it to this issue here: https://github.com/micropython/micropython/issues/3205
The only thing I could find that was close was the issue you had posted back in May of 2016 but I wasn't convinced that it was the same issue. I did supply a test case which exhibits the bug however details beyond that are pretty sparse as I'm not sure I understand the issue real well myself.
Thanks for your help
The only thing I could find that was close was the issue you had posted back in May of 2016 but I wasn't convinced that it was the same issue. I did supply a test case which exhibits the bug however details beyond that are pretty sparse as I'm not sure I understand the issue real well myself.
Thanks for your help
Re: uPyMySQL
I tried your library and I'm getting the following error when I run the demo code:
Using ESP32 running LoBo build. Trying to insert data to MariaDB 10 database running on a local NAS.[Errno 104] ECONNRESET
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "sqltest.py", line 9, in <module>
File "upymysql/__init__.py", line 86, in Connect
File "upymysql/connections.py", line 658, in __init__
File "upymysql/connections.py", line 923, in connect
File "upymysql/connections.py", line 923, in connect
File "upymysql/connections.py", line 875, in connect
File "upymysql/connections.py", line 873, in connect
AttributeError: 'OSError' object has no attribute 'errno'
Re: uPyMySQL
Did you have any luck resolving this? I'm getting back into the codebase as I can't get it to fit onto my Feather Huzzah and I'd like to incorporate whatever fixes you did or work on fixing it myself. Do you have the code that you ran to get the error?
Re: uPyMySQL
I was able to get a simple insert query working, but I shelved the project at that point.
Re: uPyMySQL
I've only recently picked this back up and I'm really only using it for logging functionality so basic inserts myself. I have gone back and shrunk the size considerably and also worked through some more kinks including some with regards to "errno" so If you do pick up the project again make sure to use the updated code.
Good luck
Good luck