#!/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])

 

相关文章:

  • 2022-01-10
  • 2021-10-11
  • 2022-12-23
  • 2021-10-13
  • 2021-06-17
  • 2022-01-21
  • 2021-07-02
  • 2022-12-23
猜你喜欢
  • 2021-09-19
  • 2022-12-23
  • 2021-04-28
  • 2022-02-08
  • 2022-12-23
  • 2021-09-04
  • 2021-07-08
相关资源
相似解决方案