# 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)