@@ -0,0 +1,2056 @@
+#!/usr/bin/env python%0A# -*- coding: utf8 -*-%0A%0A%22%22%22%0A%0ASLEM Mydb Class%0A%0A%22%22%22%0A__author__ = %22Arnis Civciss (arnis.civciss@gmail.com)%22%0A__version__ = %22$Revision: 0.1 $%22%0A__date__ = %22$Date: 2012/08/09 $%22%0A__copyright__ = %22Copyright (c) 2012 Arnis Civciss%22%0A__license__ = %22%22%0A%0Aimport sys%0Aimport MySQLdb as mdb%0A%0Aclass Mydb:%0A  %22%22%22Class Db implemets methods to access SLEM Mysql data base.%22%22%22%0A  def __init__(self, **kwargs):%0A    %22%22%22Init - host, user, passwd, dbname - params.%22%22%22%0A    self.host = kwargs%5B'host'%5D%0A    self.user = kwargs%5B'user'%5D%0A    self.passwd = kwargs%5B'passwd'%5D%0A    self.dbname = kwargs%5B'dbname'%5D%0A    %0A  def connect(self):%0A    %22%22%22Connects and creates cursor and db handler.%22%22%22%0A    self.dbh = mdb.connect(self.host,self.user,self.passwd,self.dbname)%0A    self.cursor = self.dbh.cursor(mdb.cursors.DictCursor)%0A     %0A  def do_sql(self, sql, sql_data=None, get='get'):%0A    '''Executes sql statement %0A        if get=='get' selects and returns rows and rowcount.%0A        if get=='set' does executemany. sql_data is a tuple of parameters.%0A        e.g. %0A        sql = %22%22%22INSERT IGNORE INTO dslamz_dslamtype (type) VALUES (%25s)%22%22%22%0A        sql_data = %5B(%22ETH%22),(%22ATM%22)%5D%0A        try:%0A          la = mango.do_sql(sql, sql_data, 'set')%0A        except mango.Error(), e:%0A            print %22Db Error %25d: %25s%22 %25 (e.args%5B0%5D, e.args%5B1%5D)%0A    '''%0A    if get == 'get':%0A      self.cursor.execute(sql)%0A      rows = self.cursor.fetchall()%0A      rowcount = self.cursor.rowcount%0A      return rows, rowcount%0A    elif get == 'set': %0A      self.cursor.executemany(sql, sql_data)%0A      self.dbh.commit ()%0A      return 1%0A    else: pass%0A%0A  def Error(self):%0A    %22%22%22Error handling%22%22%22%0A    return mdb.Error%0A%0A  def close(self):%0A    %22%22%22Close connection.%22%22%22%0A    self.dbh.close()%0A    %0A  def get_host(self):%0A    %22%22%22returns host attribute%22%22%22%0A    return self.host%0A%0A  def get_user(self):%0A    %22%22%22returns user attribute%22%22%22%0A    return self.user%0A%0A  def get_dbname(self):%0A    %22%22%22returns dbname attribute%22%22%22%0A    return self.dbname%0A%0A  def get_passwd(self):%0A    %22%22%22returns passwd attribute%22%22%22%0A    return self.passwd%0A%0A

Create db.py