username = getpass.getpass('username: ')
if password == None:
password = getpass.getpass('password: ')
+ self.logger.info('logging in to %s:%s as %s'
+ % (host, database, username))
self.db = MySQLdb.connect(host=host, user=username,
passwd=password, db=database)
del(username)
self.cursor = self.db.cursor()
def disconnect(self):
+ self.logger.info('disconnecting')
self.cursor = None
self.db.close()
+ def execute(self, command):
+ self.logger.info(command)
+ self.cursor.execute(command)
+
def set_default_table(self, table):
self.table = table
dict = self._clean_dict(dict)
keys = dict.keys()
values = ["'%s'" % dict[key] for key in keys]
- self.cursor.execute("INSERT INTO %s (%s) VALUES (%s)"
- % (table, ', '.join(keys), ', '.join(values)))
+ self.execute("INSERT INTO %s (%s) VALUES (%s)"
+ % (table, ', '.join(keys), ', '.join(values)))
# error checking
def list_entries(self, dict=None, table=None):
if table == None:
table = self.table
where = self._where_string(dict)
- self.cursor.execute('SELECT * FROM %s%s' % (table, where))
+ self.execute('SELECT * FROM %s%s' % (table, where))
numrows = int(self.cursor.rowcount)
print '\t'.join([dtuple[0] for dtuple in self.cursor.description])
for x in range(0,numrows):
if table == None:
table = self.table
where = self._where_string(dict)
- self.cursor.execute('DELETE FROM %s%s' % (table, where))
+ self.execute('DELETE FROM %s%s' % (table, where))
def _clean_dict(self, dict=None):
if dict == None: