Previous topic

pycrtools.io

Next topic

pycrtools.io.interfaces

This Page

pycrtools.io.database

Database([filename, host, user, password, ...]) Class to handle all python communication with a database.

Provide a simple database interface to access sqlite3 and PostgreSQL databases.

If the database object is initialized with a host variable, the database object assumes a PostgreSQL database connection.

class pycrtools.io.database.Database(filename=':memory:', host=None, user=None, password=None, dbname=None, autoclose=True)

Class to handle all python communication with a database.

close()

Close the database.

execute(sql='')

Execute an sql statement

Properties

Parameter Description
sql SQL statement to execute.
executelist(sql_list=, []blocksize=128, verbose=False)

Execute a list of SQL statements.

Properties

Parameter Description
sql_list List of SQL commands to process.
blocksize Maximum size of a block os SQL commands that gets processed in one go. Longer lists are split in multiple blocks [default=128].
verbose Boolean that [default=False].
insert(sql='')

Insert a new record into the database and return the new primary key.

Properties

Parameter Description
sql SQL statement to execute.
isPostgresql()

Check if database is a PostgreSQL database.

isSqlite()

Check if database is an SQLite3 database.

open()

Open the database.

select(sql='')

Select records from the database.

Properties

Parameter Description
sql SQL statement to execute.
selectone(sql='')

Select one record from the database.

Properties

Parameter Description
sql SQL statement to execute.
tableExists(table)

Select records from the database.

Properties

Parameter Description
table Check if table exists
writescript(filename, sql_script)

Write SQL script to a file.

Properties

Parameter Description
filename Name of the file to which to write the sql_script.
sql_script Script with SQL statements.