"official/vision/modeling/maskrcnn_model_test.py" did not exist on "3dcc078aa8fed2167d1ab87f0015973b391a7898"
dbop.py 1.1 KB
Newer Older
Sugon_ldc's avatar
Sugon_ldc committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# import pymysql
# import pymongo

def GetDBConn():
    conn = pymysql.connect(
        host="127.0.0.1",
        user="root",
        password="",
        database="",
        charset="utf8")
    return conn

def Runsql(sqlstr, conn):
    ret = []
    cur = conn.cursor()
    cur.execute(sqlstr)
    row = cur.fetchone()
    while row is not None:
        ret.append(row)
        row = cur.fetchone()
    cur.close()
    return ret

def RunsqlMany(sqlstr, conn):
    cur = conn.cursor()
    cur.execute(sqlstr)
    rows = cur.fetchall()
    cur.close()
    return rows

# dbname="huawei2021_w1"
# dbname="huawei2021_w1_core4"    
# def GetMongoCollection(collectionName, dbname="valence_sp2"):
def GetMongoCollection(collectionName, dbname):
    client = pymongo.MongoClient(host='localhost',
                                 port=27017,serverSelectionTimeoutMS=20000,
                                 socketTimeoutMS=20000,connectTimeoutMS=20000)
    db = client[dbname]
    collection = db[collectionName]
    return collection

def CreateIndex(coll, key_order):
    coll.create_index(key_order, unique=False, background=False)