12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- from connect import connect
- conn = connect()
- def query_select(query, args=(), one=False):
- try:
- with conn.cursor() as cursor:
- cursor.execute(query, args)
- r = [dict((cursor.description[i][0], value) \
- for i, value in enumerate(row)) for row in cursor.fetchall()]
- return (r[0] if r else None) if one else r
- except:
- return "Error"
- def query_insert(query, args=()):
- try:
- with conn.cursor() as cursor:
- cursor.execute(query, args)
- #id = cursor.fetchone()[0]
- conn.commit()
- return cursor.fetchone()[0]
- except:
- return "Error"
- def query_delete(query, args=()):
- try:
- with conn.cursor() as cursor:
- cursor.execute(query, args)
- if(cursor.rowcount != 0):
- conn.commit()
- return True
- return False
- except:
- return False
- def query_update(query, args=()):
- try:
- with conn.cursor() as cursor:
- cursor.execute(query, args)
- print(cursor.rowcount)
- if(cursor.rowcount != 0):
- conn.commit()
- return True
- return False
- except:
- return False
|