uw.sql package

Submodules

uw.sql.dbapi module

uw.sql.escape module

Temporary module for Python 2 bytea support.

Contains a routine for formatting a byte array as a valid PostgreSQL string literal.

uw.sql.escape.escape_bytea(bytes)[source]

Escape a (byte) string so that it can be interpreted as a bytea.

Parameters:bytes – the byte string to escape.
Returns:the byte string as a valid PostgreSQL bytea literal.

This is needed because in Python 2 psycopg2 interprets str as a string and does encoding on it for sending to the database. There is no separate bytes type. In Python 3 we would use bytes for bytea input to the database and this function would not be needed.

uw.sql.sqltools module

class uw.sql.sqltools.SQLWriter(file, delim='t', null='\N')[source]

Bases: object

escape(value)[source]
static openUploadFiles(dir, tables, **kwargs)[source]

Open files corresponding to a list of table names for SQL upload.

Each entry in tables is interpreted as a table name, and a file of that name is opened in directory dir. The result is a dictionary from table/file name to a sqltools.SQLWriter for that table.

write(values)[source]
uw.sql.sqltools.getForeignKeys(db, table)[source]

Get information about the foreign keys of the given table.

The result consists of a list of the foreign keys. Each key is represented by a tuple containing the following items:

  • foreign key constraint name
  • foreign key is deferrable
  • foreign key is initially deferrable
  • target unique constraint
  • match option
  • update rule
  • delete rule
  • target table
  • target constraint type (primary key or unique)
  • target constraint is deferrable
  • target constraint is initially deferrable
uw.sql.sqltools.listFields(db, table)[source]

List the fields of the specified table in the database.

The catalog must match the catalog to which the connection db is connected.

uw.sql.sqltools.listKeyFields(db, constraint)[source]

List, in order, the fields involved in the specified constraint.

uw.sql.sqltools.listPrimaryKey(db, table)[source]

List the fields of the primary key of the given table in the database.

The catalog must match the catalog to which the connection db is connected.

uw.sql.update_tables module

uw.sql.wrap module

Module contents