G
Gert Cuykens
import MySQLdb
class Db:
_db=-1
_cursor=-1
@classmethod
def __init__(self,server,user,password,database):
self._db=MySQLdb.connect(server , user , password , database)
self._cursor=self._db.cursor()
@classmethod
def excecute(self,cmd):
self._cursor.execute(cmd)
self._db.commit()
@classmethod
def rowcount(self):
return int(self._cursor.rowcount)
@classmethod
def fetchone(self):
return self._cursor.fetchone()
@classmethod
def close(self):
self._cursor.close()
self._db.close()
if __name__ == '__main__':
gert=Db('localhost','root','******','gert')
gert.excecute('select * from person')
for x in range(0,gert.rowcount):
print gert.fetchone()
gert.close()
gert@gert:~$ python ./Desktop/svn/db/Py/db.py
Traceback (most recent call last):
File "./Desktop/svn/db/Py/db.py", line 35, in <module>
for x in range(0,gert.rowcount):
TypeError: range() integer end argument expected, got instancemethod.
gert@gert:~$
Can anybody explain what i must do in order to get integer instead of
a instance ?
class Db:
_db=-1
_cursor=-1
@classmethod
def __init__(self,server,user,password,database):
self._db=MySQLdb.connect(server , user , password , database)
self._cursor=self._db.cursor()
@classmethod
def excecute(self,cmd):
self._cursor.execute(cmd)
self._db.commit()
@classmethod
def rowcount(self):
return int(self._cursor.rowcount)
@classmethod
def fetchone(self):
return self._cursor.fetchone()
@classmethod
def close(self):
self._cursor.close()
self._db.close()
if __name__ == '__main__':
gert=Db('localhost','root','******','gert')
gert.excecute('select * from person')
for x in range(0,gert.rowcount):
print gert.fetchone()
gert.close()
gert@gert:~$ python ./Desktop/svn/db/Py/db.py
Traceback (most recent call last):
File "./Desktop/svn/db/Py/db.py", line 35, in <module>
for x in range(0,gert.rowcount):
TypeError: range() integer end argument expected, got instancemethod.
gert@gert:~$
Can anybody explain what i must do in order to get integer instead of
a instance ?