pycrossword  0.4
Pure-Python implementation of a crossword puzzle generator and editor
Public Member Functions | Public Attributes | List of all members
pycross.dbapi.Sqlitedb Class Reference

SQLite database driver implementation wrapping the standard Python sqlite3 methods. More...

Public Member Functions

def __init__ (self, dbname=None, fullpath=False, recreate=False, connect=True)
 Constructor initializes DB driver connection. More...
 
def __del__ (self)
 Destructor disconnects from DB. More...
 
def setpath (self, dbname, fullpath=False, recreate=False, connect=True)
 Initializes the path to the DB file and establishes a connection if required. More...
 
def connect (self)
 Connects to the DB file (Sqlitedb::dbpath). More...
 
def disconnect (self, commit_trailing=True)
 Disconnects from the currently open DB. More...
 
def create_db (self, overwrite=False)
 Creates the DB in Sqlitedb::dbpath, optionally overwriting the existing file. More...
 
def create_tables (self)
 Creates the default table structure in the DB. More...
 
def get_words (self)
 Retrieves all words from the database. More...
 
def get_pos (self)
 Retrieves all parts of speech from the database. More...
 

Public Attributes

 dbpath
 str full path to the DB More...
 
 conn
 internal DB connection object (SQLite driver) More...
 

Detailed Description

SQLite database driver implementation wrapping the standard Python sqlite3 methods.

Some handy methods are added to connect / disconnect to / from the DB, create / recreate the DB with the default set of tables (to use as a word source), and import Hunspell dictionary data.

Constructor & Destructor Documentation

◆ __init__()

def pycross.dbapi.Sqlitedb.__init__ (   self,
  dbname = None,
  fullpath = False,
  recreate = False,
  connect = True 
)

Constructor initializes DB driver connection.

Parameters
dbnamestr path to database file (*.db) or an abbreviated language name for preinstalled DB files stored in 'assets/dic', e.g. 'en' (='assets/dic/en.db')

◆ __del__()

def pycross.dbapi.Sqlitedb.__del__ (   self)

Destructor disconnects from DB.

Member Function Documentation

◆ connect()

def pycross.dbapi.Sqlitedb.connect (   self)

Connects to the DB file (Sqlitedb::dbpath).

Returns
bool True on success, False on failure

◆ create_db()

def pycross.dbapi.Sqlitedb.create_db (   self,
  overwrite = False 
)

Creates the DB in Sqlitedb::dbpath, optionally overwriting the existing file.

Parameters
overwritebool True to overwrite the existing file (default = False)
Warning
If set to True, all data in the DB file (if present) will be lost!
Returns
bool True on success, False on failure

◆ create_tables()

def pycross.dbapi.Sqlitedb.create_tables (   self)

Creates the default table structure in the DB.

Returns
bool True on success, False on failure
See also
utils::globalvars::SQL_TABLES

◆ disconnect()

def pycross.dbapi.Sqlitedb.disconnect (   self,
  commit_trailing = True 
)

Disconnects from the currently open DB.

Parameters
commit_trailingbool True (default) to commit all pending changes to the DB before disconnecting

◆ get_pos()

def pycross.dbapi.Sqlitedb.get_pos (   self)

Retrieves all parts of speech from the database.

Returns
list list of POS as tuples: (ID, POS SHORT NAME, POS FULL NAME)

◆ get_words()

def pycross.dbapi.Sqlitedb.get_words (   self)

Retrieves all words from the database.

Returns
list list of retrieved words as tuples: (ID, WORD, POS SHORT NAME, POS FULL NAME)

◆ setpath()

def pycross.dbapi.Sqlitedb.setpath (   self,
  dbname,
  fullpath = False,
  recreate = False,
  connect = True 
)

Initializes the path to the DB file and establishes a connection if required.

Parameters
dbnamestr path to database file (*.db) or an abbreviated language name - see init()
fullpathbool True to indicate that the 'dbname' argument is the full file path (default = False)
recreatebool True to recreate the database file with the default table structure (default = False).
Warning
If set to True, all data in the DB file (if present) will be lost!
Parameters
connectbool True (default) to attempt connecting to the DB immediately
Returns
bool True on success, False on failure

Member Data Documentation

◆ conn

pycross.dbapi.Sqlitedb.conn

internal DB connection object (SQLite driver)

◆ dbpath

pycross.dbapi.Sqlitedb.dbpath

str full path to the DB


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