Exemple #1
0
def openmysqlconn():
    dboperater =None
    try:
        dboperater = DBOperater()
        dboperater.createconnection(host=sadb.host,user=sadb.dbuser,passwd=sadb.dbpwd,dbname=sadb.dbname)
    except MySQLdb.Error,e:
        PLOG.debug("Mysql Error %d: %s" %(e.args[0], e.args[1]))   
Exemple #2
0
def executeproc(procsqlname,dboperater=None,args=None):
    resultls = []
    try:
        if dboperater == None:
            dboperater = DBOperater()
        if dboperater.conn == None:
            dboperater.createconnection(host=sadb.host,user=sadb.dbuser,passwd=sadb.dbpwd,dbname=sadb.dbname) #数据库连接
        cur = dboperater.conn.cursor()
        cur.callproc(procsqlname,args)
        dboperater.conn.commit() #提交SQL语句
        cur.close()
    except MySQLdb.Error,e:
        PLOG.debug("Mysql Error %d: %s,sql=%s" %(e.args[0], e.args[1],procsqlname)) 
Exemple #3
0
def querysql(sqltext,dboperater=None,how = 0):
    resultls = []
    try:
        if dboperater == None:
            dboperater = DBOperater()
        if dboperater.conn == None:
            dboperater.createconnection(host=sadb.host,user=sadb.dbuser,passwd=sadb.dbpwd,dbname=sadb.dbname) #数据库连接
        rowNum, result = dboperater.query(sqltext)
        PLOG.trace("%s query finish"%(sqltext))
        resultls = dboperater.fetch_queryresult(result,rowNum, how = how) 
    except MySQLdb.Error,e:
        PLOG.debug("Mysql Error %d: %s,sql=%s" %(e.args[0], e.args[1],sqltext)) 
        return None
Exemple #4
0
def executearrsql(sqltext,dboperater=None,arrsql=None,sqlnum=100,mode = DBHelper.CURSOR_MODE):
    try:
        if dboperater == None:
            dboperater = DBOperater()
        if dboperater.conn == None:
            dboperater.createconnection(host=sadb.host,user=sadb.dbuser,passwd=sadb.dbpwd,dbname=sadb.dbname) #数据库连接
        if arrsql!=None and len(arrsql)>0:
            totalnum = len(arrsql)
            if totalnum%sqlnum == 0:
                foocount = totalnum/sqlnum
            else:
                foocount = totalnum/sqlnum+1
            i = 0
            while i<foocount:
                arr = arrsql[i*sqlnum:(i+1)*sqlnum]
                dboperater.execute(sqltext,args=arr,mode=mode,many=True)#执行SQL语句
                dboperater.conn.commit() #提交SQL语句
                i+=1  
        else:
            # 执行单条sql语句
            dboperater.execute(sqltext,mode=mode)
            dboperater.conn.commit()
    except MySQLdb.Error,e:
        PLOG.debug("Mysql Error %d: %s,sql=%s" %(e.args[0], e.args[1],sqltext))