用法:
create_function(name, num_params, func, *, deterministic=False)
創建一個用戶定義的函數,您以後可以在函數名稱
name
下在 SQL 語句中使用該函數。num_params
是函數接受的參數數量(如果num_params
為 -1,則函數可以接受任意數量的參數),而func
是作為 SQL 函數調用的 Python 可調用對象。如果deterministic
為真,則創建的函數被標記為 deterministic ,這允許 SQLite 執行額外的優化。 SQLite 3.8.3 或更高版本支持此標誌,如果與舊版本一起使用,將引發NotSupportedError
。該函數可以返回 SQLite 支持的任何類型:bytes、str、int float 和
None
。在 3.8 版中更改:
deterministic
添加了參數。例子:
import sqlite3 import hashlib def md5sum(t): return hashlib.md5(t).hexdigest() con = sqlite3.connect(":memory:") con.create_function("md5", 1, md5sum) cur = con.cursor() cur.execute("select md5(?)", (b"foo",)) print(cur.fetchone()[0]) con.close()
相關用法
- Python sqlite3.Connection.create_collation用法及代碼示例
- Python sqlite3.Connection.create_aggregate用法及代碼示例
- Python sqlite3.Connection.text_factory用法及代碼示例
- Python sqlite3.Connection.enable_load_extension用法及代碼示例
- Python sqlite3.Connection.iterdump用法及代碼示例
- Python sqlite3.Connection.row_factory用法及代碼示例
- Python sqlite3.Connection.backup用法及代碼示例
- Python sqlite3.Cursor.executescript用法及代碼示例
- Python sqlite3.Cursor.connection用法及代碼示例
- Python sqlite3.Cursor.executemany用法及代碼示例
- Python sqlite3.threadsafety用法及代碼示例
- Python sqlite3.complete_statement用法及代碼示例
- Python sqlite3.connect用法及代碼示例
- Python math sqrt()用法及代碼示例
- Python sklearn.cluster.MiniBatchKMeans用法及代碼示例
- Python scipy.ndimage.binary_opening用法及代碼示例
- Python scipy.signal.windows.tukey用法及代碼示例
- Python scipy.stats.mood用法及代碼示例
- Python str.isidentifier用法及代碼示例
- Python sklearn.metrics.fbeta_score用法及代碼示例
注:本文由純淨天空篩選整理自python.org大神的英文原創作品 sqlite3.Connection.create_function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。