pwwang / pymedoo

A lightweight database framework for python
MIT License
15 stars 4 forks source link

get method error with none recordsets #5

Closed void285 closed 5 years ago

void285 commented 5 years ago

If no recordset returned from select method, get method encountered with the following error, maybe it's better to return None.

  File "C:\Develop\Python27\lib\site-packages\medoo\base.py", line 95, in get
    return rs.first()[0]
TypeError: 'NoneType' object has no attribute '__getitem__'

src:

    def get(self, table, columns = '*', where = None, join = None):
        rs = self.select(table, columns, where, join)
        return rs.first()[0]
pwwang commented 5 years ago

You may use try except to capture the exception, or I am considering raising a new exception (say NoRecordSetException) based upon the TypeError.

Return None might be misleading since we can't tell if the value in the database is really None (NULL) or it's just because of no recordsets returned.

pwwang commented 5 years ago

Try to get from an empty record will now raise GetFromEmptyRecordError. 1c34788ebf32912955ae47958fc8c9fabc99aee6