#!/user/bin/env python # @Time :2018/6/8 14:44 # @Author :PGIDYSQ #@File :CreateFunTest.py
'''如何在sqlite3連接中創建並調用自定義函數'''
import sqlite3,hashlib #自定義函數
def md5sum(t): return hashlib.md5(t).hexdigest() #在內存中創建臨時數據庫
conn = sqlite3.connect(":memory:") #創建可在SQL語句中調用的函數
conn.create_function("md5",1,md5sum) cur = conn.cursor() #在SQL語句中調用自定義函數
cur.execute("SELECT md5(?)",["上單打野ad".encode()]) print(cur.fetchone()[0])
