예제 #1
0
def dbDelete(db, table):
    # DROP TABLE table_name
    db = dbutil.dbUtils(dbname)
    sql = "drop table %s" % (table)
    if db.db_action(sql, 0) == True:
        print("%s delete done." % (table))
    db.close()
예제 #2
0
def checkUserList(table):
    db = dbutil.dbUtils(dbname)
    sql = "select * from " + table
    userList = db.db_action(sql, 1)
    for user in userList:
        print(user)
    db.close()
예제 #3
0
def dbInsertMovie(movieid, movie, tag, score, introduction):
    db = dbutil.dbUtils(dbname)
    movie = "(" + movieid + ",'" + movie + "','" + tag + "'," + score + ",'" + introduction + "')"
    sql = 'insert into movie_info values ' + movie
    if db.db_action(sql, 0) == True:
        print("User insert done.")
    db.close()
    return "insert done."
예제 #4
0
def addDbColumn(table, column, columnAttri):
    db = dbutil.dbUtils(dbname)
    sql = "alter table %s add column %s %s" % (table, column, columnAttri)
    try:
        db.db_action(sql, 0)
        print("Column insert done.")
    except:
        print("Exst column!")
    db.close()
예제 #5
0
def dbTableDelete(table, condition=''):
	db = dbutil.dbUtils('userdb.db')
	sql = "delete from %s %s;" % (table, condition)
	try:
		db.db_action(sql, 0)
		print("Delete done.")
	except:
		print("Failed")
	db.close()
예제 #6
0
def dbInsertUser(userid, username, passwd):
    db = dbutil.dbUtils(dbname)
    if checkUserExist(username):
        return "Exist user!!!"
    user = "******" + userid + ",'" + username + "','" + passwd + "')"
    sql = 'insert into user values ' + user
    if db.db_action(sql, 0) == True:
        print("User insert done.")
    db.close()
    return "insert done."
예제 #7
0
def likeDbProcess(filename, n):
	db = dbutil.dbUtils('userdb.db')
	sql = "select liken from img where imgname = '%s'" % (filename)
	likeL = db.db_action(sql, 1)
	like = likeL[0][0]
	like += n
	sql = "update img set liken = %d where imgname = '%s'" % (like, filename)
	flag = db.db_action(sql, 0)
	db.close()
	return flag
예제 #8
0
def dbInsertReview(imgid, userid, username, content):
    db = dbutil.dbUtils(dbname)
    created_at = time.time()
    sql = "insert into reviews values (null, '%s', '%s', '%s', '%s', '%f')" % (
        imgid, userid, username, content, created_at)
    try:
        db.db_action(sql, 0)
        print("Review insert done.")
    except:
        print("Failed")
    db.close()
예제 #9
0
def dbInsertImg(imgname, uploader, categroy, author, intro, tag='null'):
    db = dbutil.dbUtils(dbname)
    # sql = "I love %s" % ('piano') | 'insert into img values '+ imgInfo
    sql = "insert into img values (null, '%s', '%s', '%s', '%s', '%s', '%s', 0)" % (
        imgname, uploader, categroy, author, intro, tag)
    #if db.db_action(sql, 0) == True:
    #	print("User insert done.")
    try:
        db.db_action(sql, 0)
        print("Img insert done.")
    except:
        print("Exst img name!")
    db.close()
예제 #10
0
def dbTableDelete(table, condition):
    db = dbutil.dbUtils(dbname)
    sql = "delete from %s %s;" % (table, condition)
    print(sql)
    #sql = "PRAGMA  table_info(img)"
    db.db_action(sql, 0)
    for i in l:
        print(i)
    """try:
		db.db_action(sql, 0)
		print("Delete done.")
	except:
		print("Failed")"""
    db.close()
예제 #11
0
def dbInsertImg(imgname, uploader, categroy='unknow', author='unknow', intro='', tag='', expectedprice='0'):
	db = dbutil.dbUtils('userdb.db')
	sql = 'insert into img values (null, "%s", "%s", "%s", "%s", "%s", "%s", 0, %s)' % (imgname, uploader, categroy, author, intro, tag, expectedprice)
	#print("dbinsertImg: %s" % imgname)
	#print(sql)
	try:
		db.db_action(sql, 0)
		db.close()
		return True
	except:
		falseinfo = "Exist image name!"
		print(falseinfo)
		db.close()
		return falseinfo
예제 #12
0
def dbInsertUser(userid, username, passwd, isArtist):
    db = dbutil.dbUtils('userdb.db')
    userList = dbQuery("username", "user")
    # check exist user
    if checkUserExist(username):
        return "Exist user!!!"
    # insert
    #user = "******" + userid + ",'" + username + "','" + passwd + "')"
    user = "******" % (username, passwd, isArtist)
    sql = 'insert into user values ' + user
    if db.db_action(sql, 0) == True:
        print("User insert done.")
        db.close()
        return True
    else:
        db.close()
        return False
예제 #13
0
def dbUpdate(moviename, moviescore):
    db = dbutil.dbUtils(dbname)
    sql = "select score, numberOfScoring from movie_info where movie_name = '" + moviename + "'"
    scoreL = db.db_action(sql, 1)
    score = float(scoreL[0][0])
    n = float(scoreL[0][1])
    if score == -1 and n == 0:
        score = moviescore
    else:
        score = (moviescore + (score * n)) / (n + 1)
    # only keep one decimal point
    score = int(score * 10) / 10
    n += 1

    #UPDATE COMPANY SET ADDRESS = 'Texas' WHERE ID = 6
    sql = "update movie_info set score = " + str(
        score) + ", numberOfScoring = " + str(
            n) + " where movie_name = '" + moviename + "'"
    flag = db.db_action(sql, 0)
    db.close()
예제 #14
0
def dbQuery(choice, table):
    db = dbutil.dbUtils(dbname)
    sql = "select " + choice + " from " + table
    userList = db.db_action(sql, 1)
    db.close()
    return userList
예제 #15
0
def dbImgSelect(condition=''):
    db = dbutil.dbUtils(dbname)
    sql = "select imgname from img %s" % (condition)
    imgList = db.db_action(sql, 1)
    db.close()
    return imgList
예제 #16
0
파일: mateProcess.py 프로젝트: Lin-CX/team6
def dbQuery(choice, table):
    db = dbutil.dbUtils('userdb.db')
    sql = "select " + choice + " from " + table
    movieList = db.db_action(sql, 1)
    db.close()
    return movieList