pycrossword
0.3
Pure-Python implementation of a crossword puzzle generator and editor
|
SQLite database word source implementation. More...
Public Member Functions | |
def | __init__ (self, tables, db, diconnect_on_destroy=True, max_fetch=None, shuffle=True) |
Constructor. More... | |
def | __del__ (self) |
Destructor: disconnects from database if DBWordsource::diconnect_on_destroy == True More... | |
def | isvalid (self) |
Valid only if the DB connection was successful. More... | |
def | fetch (self, word=None, blank=' ', pos=None, filter_func=None, shuffle=True, truncate=True) |
Fetches results from the current SQLite DB. More... | |
![]() | |
def | __init__ (self, max_fetch=None, shuffle=True) |
Constructor. More... | |
def | truncate (self, suggestions) |
Truncates the results by the threshold number stored in Wordsource::max_fetch. More... | |
def | shuffle (self, suggestions) |
Shuffles the results randomly. More... | |
def | check (self, word, pos=None, filter_func=None) |
Checks if a given word or word pattern is found in the word source. More... | |
def | pop_word (self, suggestions) |
Retrieves the last suggestion (word) from the list of suggestions, removing that word from the original results. More... | |
def | __repr__ (self) |
Python repr() overload. More... | |
def | __bool__ (self) |
Python bool() overload. More... | |
Public Attributes | |
db | |
dbapi::Sqlitedb SQLite database driver object More... | |
conn | |
DB connection object (low-level DB driver) More... | |
tables | |
dict DB table and field names for words and parts of speech - see utils::globalvars::SQL_TABLES (default names) More... | |
diconnect_on_destroy | |
bool True (default) to disconnect from database on object destruction More... | |
cur | |
low-level DB cursor object More... | |
![]() | |
max_fetch | |
int maximum number of suggestions returned from the word source More... | |
shuffle_words | |
bool if True , fetched words will be shuffled More... | |
active | |
bool if True , this word source will be used; otherwise it will be ignored More... | |
Private Member Functions | |
def | _execsql (self, sql) |
Executes an SQL query. More... | |
SQLite database word source implementation.
def pycross.wordsrc.DBWordsource.__init__ | ( | self, | |
tables, | |||
db, | |||
diconnect_on_destroy = True , |
|||
max_fetch = None , |
|||
shuffle = True |
|||
) |
Constructor.
tables | dict DB table and field names for words and parts of speech - see utils::globalvars::SQL_TABLES (default names) |
db | dbapi::Sqlitedb SQLite database driver object |
diconnect_on_destroy | bool True (default) to disconnect from database on object destruction |
max_fetch | int maximum number of suggestions returned from the word source |
None
means no limit on suggestions, which may be time/resource consuming! shuffle | bool if True , fetched words will be shuffled |
Exception | failed DB connection |
def pycross.wordsrc.DBWordsource.__del__ | ( | self | ) |
Destructor: disconnects from database if DBWordsource::diconnect_on_destroy == True
|
private |
Executes an SQL query.
sql | str SQL query string |
DB cursor
DB cursor object that has executed the SQL query Exception | failed DB connection |
def pycross.wordsrc.DBWordsource.fetch | ( | self, | |
word = None , |
|||
blank = ' ' , |
|||
pos = None , |
|||
filter_func = None , |
|||
shuffle = True , |
|||
truncate = True |
|||
) |
Fetches results from the current SQLite DB.
Reimplemented from pycross.wordsrc.Wordsource.
def pycross.wordsrc.DBWordsource.isvalid | ( | self | ) |
Valid only if the DB connection was successful.
Reimplemented from pycross.wordsrc.Wordsource.
pycross.wordsrc.DBWordsource.conn |
DB connection object (low-level DB driver)
pycross.wordsrc.DBWordsource.cur |
low-level DB cursor object
pycross.wordsrc.DBWordsource.db |
dbapi::Sqlitedb
SQLite database driver object
pycross.wordsrc.DBWordsource.diconnect_on_destroy |
bool
True
(default) to disconnect from database on object destruction
pycross.wordsrc.DBWordsource.tables |
dict
DB table and field names for words and parts of speech - see utils::globalvars::SQL_TABLES (default names)