You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
781 B
32 lines
781 B
import pymysql |
|
from pymysql.cursors import DictCursor |
|
|
|
db_config = { |
|
'host': 'home.rogersun.cn', |
|
'user': 'root', |
|
'password': 'Sxzgx1209', |
|
'database': 'file_md5' |
|
} |
|
|
|
db_connection = pymysql.Connect(**db_config) |
|
db_cursor = db_connection.cursor(cursor=DictCursor) |
|
|
|
|
|
def insert_data(_data): |
|
insert_sql = "INSERT INTO files VALUES (NUAL, %s, %s, %s, %s);" |
|
db_cursor.execute(insert_sql, _data) |
|
db_connection.commit() |
|
|
|
|
|
def get_md5_by_path(_path): |
|
get_md5_sql = "SELECT md5 FROM files WHERE path = %s;" |
|
db_cursor.execute(get_md5_sql, (_path,)) |
|
r = db_cursor.fetchone() |
|
return r |
|
|
|
|
|
def is_exist(_md5): |
|
is_exist_sql = "SELECT * FROM files WHERE md5 = %s;" |
|
db_cursor.execute(is_exist_sql, (_md5,)) |
|
r = db_cursor.fetchone() |
|
return r
|
|
|