如何使单词输入忽略数据库中单词的大小写敏感度

xj3cbfub  于 2021-07-26  发布在  Java
关注(0)|答案(1)|浏览(398)

这个问题在这里已经有答案了

在比较字符串时,如何将sqlite3设置为不区分大小写(11个答案)
11个月前关门了。
我正在用tkinter开发一个字典应用程序。我将一些单词及其含义存储在sqlite数据库中,其中一个单词的编写方式类似于“xml”、“access”。现在,每当我在entry widget中输入一个单词(xml或xml或access或access)并单击search按钮时,它就会显示“wordnotfound”。我希望这个词忽略任何大小写敏感。我想显示一个单词的意思,无论我键入的是“xml”还是“xml”或“access”或“access”

  1. import tkinter as tk
  2. import sqlite3
  3. from tkinter import messagebox
  4. from ttkthemes import ThemedStyle
  5. from tkinter import ttk
  6. from PIL import ImageTk, Image
  7. import os
  8. import sys
  9. ########### DEF FOR SEARCH #######
  10. def search(event=''):
  11. if getattr(sys, 'frozen', False):
  12. data_folder=sys._MEIPASS
  13. else:
  14. data_folder=os.getcwd()
  15. conn = sqlite3.connect(os.path.join(data_folder,'GI_DICTION4.db'))
  16. cur = conn.cursor()
  17. tex.delete(1.0, "end")
  18. data = v.get().swapcase()
  19. cur.execute("SELECT Meaning FROM Tables2 WHERE Words= ?", (data.swapcase(),))
  20. var = cur.fetchall()
  21. if var:
  22. tex.insert("end", var[0]) # accessing the meaning
  23. else:
  24. tex.insert("end","Word not found")
  25. def refresh():
  26. entry.delete(0, "end")
  27. tex.delete(1.0, "end")
  28. def fetch_data(word):
  29. if getattr(sys, 'frozen', False):
  30. data_folder=sys._MEIPASS
  31. else:
  32. data_folder=os.getcwd()
  33. conn = sqlite3.connect(os.path.join(data_folder,'GI_DICTION4.db'))
  34. cur = conn.cursor()
  35. cur.execute("select Words from Tables2 where Words like ? || '%'", (word,))
  36. allw = cur.fetchall()
  37. return allw
  38. def on_key_release(event):
  39. qword = event.widget.get()
  40. allw = fetch_data(qword)
  41. listbox.delete(0, tk.END)
  42. for w in allw:
  43. listbox.insert(tk.END, w[0])
  44. def on_select(event):
  45. entry.delete(0, tk.END)
  46. entry.insert(0, event.widget.selection_get())
  47. ########## GUI DESIGN ##############
093gszye

093gszye1#

表中的数据是否全部存储在一个大小写中,例如小写或大写。
如果是,那么可以使用 string.lower() 或者 string.upper() 功能。
您还可以在sql查询中使用collatenocase来忽略单词的大小写。 SELECT Meaning FROM Tables2 WHERE words = 'XML' COLLATE NOCASE 检查这个答案-当比较字符串时,如何将sqlite3设置为不区分大小写?

相关问题