Example #1
0
def do_finish(dbconn, cur, sock):
    if dbconn:
        cur.close()
    dbManager.close_db_connect(dbconn)
    # close socket
    sock.close()
    return
Example #2
0
def do_finish(dbconn, cur, sock):

    if dbconn:
        cur.close()

    dbManager.close_db_connect(dbconn)

    remove_list(threading.get_ident())

    # close socket
    sock.close()

    return
Example #3
0
def do_finish(dbconn, cur, sock):

    if dbconn:
        cur.close()

    dbManager.close_db_connect(dbconn)

    remove_list(threading.get_ident())

    # close socket
    sock.close()

    return
Example #4
0
def read_data_from_db():
    ret = False
    conn = dbManager.get_db_connect()
    if conn:
        cur = conn.cursor()
        # read arcpoints & # read arcinfo
        if initRoadGPS_db(cur) and initRoadArc_db(cur):
            print('Read gps info from db done!')
            ret = True
        else:
            ret = False

    dbManager.close_db_connect(conn)
    return ret
Example #5
0
def read_data_from_db():
    ret = False
    conn = dbManager.get_db_connect()
    if conn:
        cur = conn.cursor()
        # read arcpoints & # read arcinfo
        if initRoadGPS_db(cur) and initRoadArc_db(cur):
            print('Read gps info from db done!')
            ret = True
        else:
            ret = False
    
    dbManager.close_db_connect(conn)
    return ret
Example #6
0
def read_data_from_db():
    global LAST_UPDATE_TIME
    ret = False
    conn = dbManager.get_db_connect()
    if conn:
        cur = conn.cursor()
        initRoadGPS_db(cur)
        initRoadArc_db(cur)
        print('read gps info from db done!')

        LAST_UPDATE_TIME = datetime.datetime.now()
        ret = True

    dbManager.close_db_connect(conn)
    return ret
Example #7
0
def read_data_from_db():
    global LAST_UPDATE_TIME
    ret = False
    conn = dbManager.get_db_connect()
    if conn:
        cur = conn.cursor()
        initRoadGPS_db(cur)
        initRoadArc_db(cur)
        print('read gps info from db done!')
        
        LAST_UPDATE_TIME = datetime.datetime.now()
        ret = True
    
    dbManager.close_db_connect(conn)
    return ret
Example #8
0
def update_db_server():
    if_sql = "if not exists( select * from tbl_heartbeatinfo_new where camera_id = ?)"
    insert_sql = "insert into tbl_heartbeatinfo_new (id, camera_id, gpx, gpy, gpstime, roadname, mph, createtime) values ( newid(),?,?,?,?,?,?,?)"
    else_sql = "else update tbl_heartbeatinfo_new set gpx = ?, gpy = ?, gpstime = ?, roadname = ?, mph = ?, createtime = ? where (camera_id = ?)"
    sql = if_sql+insert_sql+else_sql
    conn = dbManager.get_db_connect()
    cur = conn.cursor()
    arg_list = list()
    print('update_db_server running')
    time_wait = 1
    get_num =100
    while True:
        #print('in while update db')
        for i in range(get_num):
            try:
                gpx, gpy, gpstime, roadname, mph, createtime, camera_id = q.get(False)
                q.task_done()
                
                sql_param = (camera_id, camera_id, gpx, gpy, gpstime, roadname, mph, createtime, gpx, gpy, gpstime, roadname, mph, createtime, camera_id)
                arg_list.append(sql_param)
                
            except queue.Empty:
                print('empty')#
                get_num = max(5, len(arg_list))
                break
        
        if get_num == len(arg_list):
            get_num += 10
        
        #print(gpx, gpy, gpstime, roadname, mph, createtime, camera_id)
        #print(arg_list)
        if len(arg_list) != 0:
            #print(arg_list)
            try:
                start = time.time()
                cur.executemany(sql, arg_list)
                conn.commit()
                end = time.time()
                print('execute success, time :', end - start)
            except:
                print('update db excute error!\n')
            arg_list.clear()
        print('time_wait', time_wait, 'get_num', get_num)
        time.sleep(time_wait)
    
    dbManager.close_db_connect(conn)
    return
Example #9
0
def get_last_update_db():
    luu = datetime.datetime(1, 1, 1)
    conn = dbManager.get_db_connect()
    if conn:
        cur = conn.cursor()
        sql = "SELECT last_user_update FROM sys.dm_db_index_usage_stats WHERE object_id=object_id('t_arcinfo') and database_id = db_id('CDMTCP')"
        cur.execute(sql)
        rec = cur.fetchone()
        t_arcinfo_luu = rec[0]

        sql = "SELECT last_user_update FROM sys.dm_db_index_usage_stats WHERE object_id=object_id('t_arcpoints') and database_id = db_id('CDMTCP')"
        cur.execute(sql)
        rec = cur.fetchone()
        t_arcpoints_luu = rec[0]

        if t_arcinfo_luu > t_arcpoints_luu:
            luu = t_arcinfo_luu
        else:
            luu = t_arcpoints_luu

    dbManager.close_db_connect(conn)
    return luu
Example #10
0
def get_last_update_db():
    luu = datetime.datetime(1, 1, 1)
    conn = dbManager.get_db_connect()
    if conn:
        cur = conn.cursor()
        sql = "SELECT last_user_update FROM sys.dm_db_index_usage_stats WHERE object_id=object_id('t_arcinfo') and database_id = db_id('CDMTCP')"
        cur.execute(sql)
        rec = cur.fetchone()
        t_arcinfo_luu  = rec[0]
        
        sql = "SELECT last_user_update FROM sys.dm_db_index_usage_stats WHERE object_id=object_id('t_arcpoints') and database_id = db_id('CDMTCP')"
        cur.execute(sql)
        rec = cur.fetchone()
        t_arcpoints_luu = rec[0]
        
        if t_arcinfo_luu > t_arcpoints_luu:
            luu = t_arcinfo_luu
        else:
            luu = t_arcpoints_luu
        
        
        
    dbManager.close_db_connect(conn)
    return luu