Exemple #1
0
def default_exception_handler(type, value, tb):
    import helper_mail
    import helper_regex
    import traceback

    title='stat python exception: '+helper_regex.get_script_file_name()
    content='<br/>'.join(traceback.format_exception(type, value, tb))
    #print content

    helper_mail.send_mail(title=title,content_html=content)
def fetch_row(conn_config,sql):
    
    start_time=helper_regex.get_time_clock_time()
    start_time_str=helper_regex.get_time_str_now()
    script_file_name=helper_regex.get_script_file_name()

    try:
        conn = get_db(conn_config)
        helper_mysql.log_execution_info(script_file_name,sql,start_time,error_msg='',start_time_str=start_time_str)
        return conn.execute_row(sql)
    except Exception,e:
        print 'failed:'+str(e)
        print "Unexpected error:", sys.exc_info()[0]
        print sql
        print 'SQL Server error happened !!!'
        helper_mysql.log_execution_info(script_file_name,sql,start_time,error_msg=sys.exc_info()[0],start_time_str=start_time_str)
        return -1
def execute(conn_config,sql,log_sql=True):
    conn = get_db(conn_config)
    
    start_time=helper_regex.get_time_clock_time()
    start_time_str=helper_regex.get_time_str_now()
    script_file_name=helper_regex.get_script_file_name()

    #print dir(conn)
    conn.execute_non_query(sql)
    if log_sql:
        helper_mysql.log_execution_info(script_file_name,sql,start_time,error_msg='',start_time_str=start_time_str)
    return conn.identity or conn.rows_affected
    try:
        pass
    except Exception,e:
        print 'failed:'+str(e)
        print "Unexpected error:", sys.exc_info()[0]
        print sql
        print 'SQL Server error happened !!!'
        helper_mysql.log_execution_info(script_file_name,sql,start_time,error_msg=sys.exc_info()[0],start_time_str=start_time_str)
        return -1
def fetch_joined_array(conn_config,sql,seperator=''):
    
    start_time=helper_regex.get_time_clock_time()
    start_time_str=helper_regex.get_time_str_now()
    script_file_name=helper_regex.get_script_file_name()

    try:
        conn = get_db(conn_config)
        rows=conn.execute_query(sql)
        helper_mysql.log_execution_info(script_file_name,sql,start_time,error_msg='',start_time_str=start_time_str)

        array=[]
        for row in conn:
            array.append(row[0])
                
        return seperator.join(array)
    except Exception,e:
        print 'failed:'+str(e)
        print "Unexpected error:", sys.exc_info()[0]
        print sql
        print 'SQL Server error happened !!!'
        helper_mysql.log_execution_info(script_file_name,sql,start_time,error_msg=sys.exc_info()[0],start_time_str=start_time_str)
        return -1
def fetch_rows_dict(conn_config,sql,key_name=0):
    
    start_time=helper_regex.get_time_clock_time()
    start_time_str=helper_regex.get_time_str_now()
    script_file_name=helper_regex.get_script_file_name()

    try:
        conn = get_db(conn_config)
        rows=conn.execute_query(sql)
        helper_mysql.log_execution_info(script_file_name,sql,start_time,error_msg='',start_time_str=start_time_str)
        dict={}
        for row in conn:
            dict[str(row[key_name])]=row
                
        return dict

    except Exception,e:
        print 'failed:'+str(e)
        print "Unexpected error:", sys.exc_info()[0]
        print sql
        print 'SQL Server error happened !!!'
        helper_mysql.log_execution_info(script_file_name,sql,start_time,error_msg=sys.exc_info()[0],start_time_str=start_time_str)
        return -1
def fetch_set(conn_config,sql):
    
    start_time=helper_regex.get_time_clock_time()
    start_time_str=helper_regex.get_time_str_now()
    script_file_name=helper_regex.get_script_file_name()

    conn = get_db(conn_config)
    rows=conn.execute_query(sql)
    helper_mysql.log_execution_info(script_file_name,sql,start_time,error_msg='',start_time_str=start_time_str)
    ret=set([])
    for row in conn:
        ret.add(row[0])
    return ret

    try:
        pass
    except Exception,e:
        print 'failed:'+str(e)
        print "Unexpected error:", sys.exc_info()[0]
        print sql
        print 'SQL Server error happened !!!'
        helper_mysql.log_execution_info(script_file_name,sql,start_time,error_msg=sys.exc_info()[0],start_time_str=start_time_str)
        return -1
def fetch_dict(conn_config,sql,key_name=0,value_name=1,use_interger_key=False):
    
    start_time=helper_regex.get_time_clock_time()
    start_time_str=helper_regex.get_time_str_now()
    script_file_name=helper_regex.get_script_file_name()

    sql=str(sql)

    conn = get_db(conn_config)
    rows=conn.execute_query(sql)
    helper_mysql.log_execution_info(script_file_name,sql,start_time,error_msg='',start_time_str=start_time_str)
    dict={}
    counter=0
    if use_interger_key:
        for row in conn:
            dict[row[key_name]]=row[value_name]
            #counter+=1
            #if counter % 100000 ==0:
            #    print counter
            
    else:
        for row in conn:
            dict[str(row[key_name])]=row[value_name]
            #counter+=1
            #if counter % 100000 ==0:
            #    print counter
            
    return dict
    try:
        pass
    except Exception,e:
        print 'failed:'+str(e)
        print "Unexpected error:", sys.exc_info()[0]
        print sql
        print 'SQL Server error happened !!!'
        helper_mysql.log_execution_info(script_file_name,sql,start_time,error_msg=sys.exc_info()[0],start_time_str=start_time_str)
        return -1