1.1.5.1. gnr.sql.gnrsql

Last page update: November 23, 2011

Main classes:

Other classes:

Exceptions classes:

Complete reference:

1.1.5.1.3. TempEnv

there is no public method.

1.1.5.1.4. GnrSqlException

there is no public method.

1.1.5.1.5. GnrSqlExecException

there is no public method.

1.1.5.1.6. gnr.sql.gnrsql - The complete reference list

class gnr.sql.gnrsql.DbStoresHandler(db)

Handler for using multi-database

add_dbstore_config(storename, dbname=None, host=None, user=None, password=None, port=None, save=True)

TODO

Parameters:
  • storename – TODO
  • dbname – the database name
  • host – the database server host
  • user – the username
  • password – the username’s password
  • port – TODO
  • save – TODO
add_store(storename, check=False)

TODO

Parameters:
  • storename – TODO
  • check – TODO
create_stores(check=False)

TODO

dbstore_align(storename, changes=None)

TODO

Parameters:
  • storename – TODO
  • changes – TODO.
dbstore_check(storename, verbose=False)

checks if dbstore exists and if it needs to be aligned

Parameters:
  • storename – TODO
  • verbose – TODO
drop_dbstore_config(storename)

TODO

Parameters:storename – TODO
load_config()

TODO

save_config()

TODO

class gnr.sql.gnrsql.GnrSqlDb(implementation='sqlite', dbname='mydb', host=None, user=None, password=None, port=None, main_schema=None, debugger=None, application=None)

This is the main class of the gnrsql module.

A GnrSqlDb object has the following purposes:

  • manage the logical structure of a database, called database’s model.
  • manage operations on db at high level, hiding adapter’s layer and connections.
analyze()

Analyze db

checkDb(applyChanges=False)

Check if the database structure is compatible with the current model

Parameters:applyChanges – boolean. If True, all the changes are executed and committed
clearCurrentEnv()

Clear the current env

closeConnection()

Close a connection

colToAs(col)

TODO

Parameters:col – a table column
commit()

Commit a transaction

connection

property .connection

If there’s not connection open and return connection to database

createDb(name, encoding='unicode')

Create a database with a given name and an encoding

Parameters:
  • name – the database’s name
  • encoding – The multibyte character encoding you choose
createModel()

TODO

createSchema(name)

Create a database schema

Parameters:name – the schema’s name
currentEnv

property currentEnv - Return the env currently used in this thread

dbstores

TODO

debug

TODO

delete(tblobj, record, **kwargs)

Delete a record from the table

Parameters:
  • tblobj – the table object
  • record – an object implementing dict interface as colname, colvalue
dropDb(name)

Drop a database with a given name

Parameters:name – the database’s name
dropSchema(name)

Drop a db schema

Parameters:name – TODO
dump(filename)

Dump a database to a given path

Parameters:filename – the path on which the database will be dumped
execute(sql, sqlargs=None, cursor=None, cursorname=None, autocommit=False, dbtable=None)

Execute the sql statement using given kwargs. Return the sql cursor

Parameters:
  • sql – the sql statement
  • sqlargs – optional sql arguments
  • cursor – an sql cursor
  • cursorname – the name of the cursor
  • autocommit – if True, at the end of the execution runs the commit() method
  • dbtable – the database table
get_dbname()

TODO

importModelFromDb()

Load the model.src extracting it from the database’s information schema.

importXmlData(path)

Populates a database from an XML file

Parameters:path – the file path
insert(tblobj, record, **kwargs)

Insert a record in a table

Parameters:
  • tblobj – the table object
  • record – an object implementing dict interface as colname, colvalue
listen(*args, **kwargs)

Listen for a database event (postgres)

loadModel(source=None)

Load the model.src from a XML source

Parameters:source – the XML model (diskfile or text or url).
locale

property currentEnv - Return the workdate currently used in this thread

notify(*args, **kwargs)

Database Notify

Parameters:
  • *args – TODO
  • **kwargs – TODO
onDbCommitted()

TODO

package(pkg)

Return a package object

Parameters:pkg – the package object
packageMixin(name, obj)

Register a mixin for a package.

Parameters:
  • name – the target package’s name
  • obj – a class or an object to mixin
packageSrc(name)

Return a DbModelSrc corresponding to the required package

Parameters:name – the package name
query(table, **kwargs)

An sql query

Parameters:table – the database table name on which the query will be executed, in the form packageName.tableName (packageName is the name of the package to which the table belongs to)
relationExplorer(table, prevCaption='', prevRelation='', translator=None, **kwargs)

TODO

Parameters:
  • table – the database table name on which the query will be executed, in the form packageName.tableName (packageName is the name of the package to which the table belongs to)
  • prevCaption – TODO
  • prevRelation – TODO
  • translator – TODO
restore(filename)

Restore db to a given path

Parameters:name – the path on which the database will be restored
rollback()

Rollback a transaction

saveModel(path)

Save the current model in the path as an XML file

Parameters:path – the file path
setConstraintsDeferred()

TODO

startup()

Build the model.obj from the model.src

table(tblname, pkg=None)

Return a table object

Parameters:
tableMixin(tblpath, obj)

Register an object or a class to mixin to a table.

Parameters:
  • tblpath – the path of the table
  • obj – a class or an object to mixin
tableTreeBag(packages=None, omit=None, tabletype=None)

TODO

Parameters:
  • packages – TODO
  • omit – TODO
  • tabletype – TODO
tempEnv(**kwargs)

Return a TempEnv class

unfreezeSelection(fpath)

Get a pickled selection and return it

Parameters:fpath – the file path
update(tblobj, record, old_record=None, pkey=None, **kwargs)

Update a table‘s record

Parameters:
  • tblobj – the table object
  • record – an object implementing dict interface as colname, colvalue
  • old_record – the record to be overwritten
  • pkey – the record primary key
updateEnv(**kwargs)

Update the currentEnv

use_store(storename=None)

TODO

Parameters:storename – TODO.
vacuum()

TODO

workdate

currentEnv TempEnv. Return the workdate used in the current thread

exception gnr.sql.gnrsql.GnrSqlException(description=None, **kwargs)

Standard Gnr Sql Base Exception

  • code: GNRSQL-001
  • description: Genro SQL Base Exception
exception gnr.sql.gnrsql.GnrSqlExecException(description=None, **kwargs)

Standard Gnr Sql Execution Exception

  • code: GNRSQL-002
  • description: Genro SQL Execution Exception
class gnr.sql.gnrsql.TempEnv(db, **kwargs)

TODO

Example:

with db.tempEnv(foo=7) as db:
    # do something
    pass