When you use the **params
notation, then params
is always a dictionary.
Calling that function with params=None
means you now have a dictionary with:
>>> def func(**params):
... print params
...
>>> func()
{}
>>> func(params=None)
{'params': None}
>>> func(foo='bar')
{'foo': 'bar'}
The syntax is meant to accept arbitrary keyword parameters, illustrated by the foo
keyword argument above.
Either remove the **
or test for an empty dictionary, and don't set params=None
when calling .execute()
:
def execute(self, statement, **params):
if not params:
self._curs.execute(statement)
else:
self._curs.execute(statement, params)
# ...
and:
rows = sqlcnxn.execute("select * from demographics")
Note that your execute()
function has no return
statement, which means that rows
will be set to None
(the default return value for functions). Add return self
if you meant to return the connection object so that it can be iterated over.