pycrossword  0.2
Pure-Python implementation of a crossword puzzle generator and editor
Public Member Functions | Public Attributes | Private Member Functions | List of all members
pycross.wordsrc.DBWordsource Class Reference

SQLite database word source implementation. More...

Inheritance diagram for pycross.wordsrc.DBWordsource:
pycross.wordsrc.Wordsource

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...
 
- Public Member Functions inherited from pycross.wordsrc.Wordsource
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...
 
- Public Attributes inherited from pycross.wordsrc.Wordsource
 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...
 

Detailed Description

SQLite database word source implementation.

Constructor & Destructor Documentation

◆ __init__()

def pycross.wordsrc.DBWordsource.__init__ (   self,
  tables,
  db,
  diconnect_on_destroy = True,
  max_fetch = None,
  shuffle = True 
)

Constructor.

Parameters
tablesdict DB table and field names for words and parts of speech - see utils::globalvars::SQL_TABLES (default names)
dbdbapi::Sqlitedb SQLite database driver object
diconnect_on_destroybool True (default) to disconnect from database on object destruction
max_fetchint maximum number of suggestions returned from the word source
Warning
None means no limit on suggestions, which may be time/resource consuming!
Parameters
shufflebool if True, fetched words will be shuffled
Exceptions
Exceptionfailed DB connection

◆ __del__()

def pycross.wordsrc.DBWordsource.__del__ (   self)

Destructor: disconnects from database if DBWordsource::diconnect_on_destroy == True

Member Function Documentation

◆ _execsql()

def pycross.wordsrc.DBWordsource._execsql (   self,
  sql 
)
private

Executes an SQL query.

Parameters
sqlstr SQL query string
Returns
DB cursor DB cursor object that has executed the SQL query
Exceptions
Exceptionfailed DB connection

◆ fetch()

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.

◆ isvalid()

def pycross.wordsrc.DBWordsource.isvalid (   self)

Valid only if the DB connection was successful.

Reimplemented from pycross.wordsrc.Wordsource.

Member Data Documentation

◆ conn

pycross.wordsrc.DBWordsource.conn

DB connection object (low-level DB driver)

◆ cur

pycross.wordsrc.DBWordsource.cur

low-level DB cursor object

◆ db

pycross.wordsrc.DBWordsource.db

dbapi::Sqlitedb SQLite database driver object

◆ diconnect_on_destroy

pycross.wordsrc.DBWordsource.diconnect_on_destroy

bool True (default) to disconnect from database on object destruction

◆ tables

pycross.wordsrc.DBWordsource.tables

dict DB table and field names for words and parts of speech - see utils::globalvars::SQL_TABLES (default names)


The documentation for this class was generated from the following file: