How to create and invoke a custom function in a sqlite3 connection

Source: Internet
Author: User
Tags md5

#!/user/bin/env python#@Time: 2018/6/8 14:44#@Author:P gidysq#@File: createfuntest.py" "how to create and invoke a custom function in a sqlite3 connection" "ImportSqlite3,hashlib#Custom Functionsdefmd5sum (t):returnhashlib.md5 (t). Hexdigest ()#Create a staging database in memoryconn = Sqlite3.connect (": Memory:")#Create a function that can be called in an SQL statementConn.create_function ("MD5", 1, md5sum) cur=conn.cursor ()#calling a custom function in an SQL statementCur.execute ("SELECT MD5 (?)",["ad on the singles wild". Encode ()])Print(Cur.fetchone () [0])

How to create and invoke a custom function in a sqlite3 connection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.