python sqlite_unicode_caseinsensitive_like.py

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python sqlite_unicode_caseinsensitive_like.py相关的知识,希望对你有一定的参考价值。

#!/usr/bin/python

import sqlite3

conn = sqlite3.connect('deleteme.sqlite')

# Create custom function in order to handle non-ASCII case-insensitive LIKE
conn.create_function('custom_upper', 1, lambda x: x.upper() if x else x)

###
### Assume that the connection to the sqlite3 database has been created and is valid
###
###

def find_videos_containing_title_string(conn, searchString):
    curs = conn.cursor()
    # Complete below

    query = 'SELECT id, title FROM videos WHERE custom_upper(title) LIKE custom_upper(?)'
    params = (f'%{searchString}%',)

    curs.execute(query, params)
    return curs.fetchall()


if __name__ == '__main__':
    print(find_videos_containing_title_string(conn, 'über'))  # Finds both "Übergröße" and "überschreitet"

以上是关于python sqlite_unicode_caseinsensitive_like.py的主要内容,如果未能解决你的问题,请参考以下文章

Python代写,Python作业代写,代写Python,代做Python

Python开发

Python,python,python

Python 介绍

Python学习之认识python

python初识