pytable.sqlgeneration
index
p:\table\pytable\sqlgeneration.py

Mechanisms for generating SQL from DBSchema objects
 
Currently supported:
        Create:
                database, table, field, index, default records,
                table/field constraints
        Drop/Grant/Revoke:
                everything
 
XXX Should eventually allow for "database diff", that is
        generating SQL for adding new fields, indices,
        constraints etc.

 
Modules
       
basicproperty.basic
basicproperty.common
pytable.dbschema
basicproperty.propertied
pytable.sqlquery
pytable.sqlutils

 
Classes
       
Propertied(object)
SQLStatements
SQLCreateStatements
SQLDropStatements
SQLGrantStatements
SQLRevokeStatements

 
class SQLCreateStatements(SQLStatements)
    Class providing schema-SQL-create-statements for SQL databases
 
 
Method resolution order:
SQLCreateStatements
SQLStatements
Propertied
object

Methods defined here:
constraintCheck(self, constraint, target)
Check that the constraint is applicable to the target
 
Will also fix up the constraint so that it
matches the target's name if there is no
declared field-name and the target is a field.
database(self, schema, *arguments, **named)
Generate SQL for a whole database schema (minus database setup itself)
fieldConstraint(self, constraint, target)
Create constraint-specifying SQL code fragment
fieldDataType(self, schema)
Create the data type declaration for the field
foreignKey(self, constraint, target)
Generate constraint sub-clause for foreign-key
records(self, table, dictionaries)
Create SQL to insert record in dictionary into table
table(self, schema, **named)
Generate SQL to create table in database
tableConstraint(self, constraint, target)
Create constraint-specifying SQL code fragment
tableField(self, schema, **named)
Generate in-table fragment for generating a field
tableIndex(self, schema, target=None)
Generate SQL to create index described by schema

Data and other attributes defined here:
dispatchMapping = {<class 'pytable.dbschema.FieldSchema'>: <function tableField at 0x01C86BB0>, <class 'pytable.dbschema.TableSchema'>: <function table at 0x01C86B30>, <class 'pytable.dbschema.IndexSchema'>: <function tableIndex at 0x01C86D30>, <class 'pytable.dbschema.DatabaseSchema'>: <function database at 0x01C86AF0>}
fieldPrefixToTypeMap = [('int', 'INT'), ('float', 'FLOAT'), ('bool', 'BOOLEAN'), ('str.classname', 'VARCHAR')]
fieldSQLTemplate = '%(fieldName)s %(dbDataType)s %(default)s %(constraints)s'
tableSQLTemplate = 'CREATE TABLE %(temporary)s %(tableName)s (\n\t%(subelements)s\n) %(inherits)s %(withoutoids)s;'

Methods inherited from SQLStatements:
__call__(self, schema, *arguments, **named)
Create SQL creation statements for given schema
 
Returns the statements as a series of strings.
__init__(self, driver=None, **named)
Initialise the statement-generator
 
Driver will be used to determine features for
generation (when that's implemented).
dispatch(self, schema, *arguments, **named)
Dispatch to the appropriate handler and return value
expand(self, schema, *arguments, **named)
Get the results of all items within an item

Methods inherited from Propertied:
__str__(self)
Get a friendly representation of the object
clone(self, **newValues)
Clone this object, with optional new property values
 
This method calls the __init__ method of your class with
the current property values of your class.  Providing newValues
(a dictionary) overrides property settings with new values.
getCloneProperties(self)
Get properties dictionary (key:value) for use in cloning of the instance
 
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
toString(self, indentation='', alreadyDone=None, indentString=' ')
Get a nicely formatted representation of this object
 
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
 
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
 
XXX Needs a far better API, likely a stand-alone class
        without the automatic inheritance problems here :(

Class methods inherited from Propertied:
getProperties(cls) from type
Get the BasicProperty properties for a particular object's class

Data and other attributes inherited from Propertied:
__dict__ = <dictproxy object at 0x01E9DD10>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Propertied' objects>
list of weak references to the object (if defined)

 
class SQLDropStatements(SQLStatements)
    Class generating SQL drop statements for schemas
 
 
Method resolution order:
SQLDropStatements
SQLStatements
Propertied
object

Methods defined here:
standAlone(self, schema, *arguments, **named)
Drop a stand-alone object

Data and other attributes defined here:
dispatchMapping = {<class 'pytable.dbschema.TableSchema'>: <function standAlone at 0x01C86DB0>, <class 'pytable.dbschema.IndexSchema'>: <function standAlone at 0x01C86DB0>, <class 'pytable.dbschema.DatabaseSchema'>: <unbound method SQLStatements.expand>}
standAlone_template = 'DROP %(dbObjectType)s %(name)s;'

Methods inherited from SQLStatements:
__call__(self, schema, *arguments, **named)
Create SQL creation statements for given schema
 
Returns the statements as a series of strings.
__init__(self, driver=None, **named)
Initialise the statement-generator
 
Driver will be used to determine features for
generation (when that's implemented).
dispatch(self, schema, *arguments, **named)
Dispatch to the appropriate handler and return value
expand(self, schema, *arguments, **named)
Get the results of all items within an item

Methods inherited from Propertied:
__str__(self)
Get a friendly representation of the object
clone(self, **newValues)
Clone this object, with optional new property values
 
This method calls the __init__ method of your class with
the current property values of your class.  Providing newValues
(a dictionary) overrides property settings with new values.
getCloneProperties(self)
Get properties dictionary (key:value) for use in cloning of the instance
 
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
toString(self, indentation='', alreadyDone=None, indentString=' ')
Get a nicely formatted representation of this object
 
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
 
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
 
XXX Needs a far better API, likely a stand-alone class
        without the automatic inheritance problems here :(

Class methods inherited from Propertied:
getProperties(cls) from type
Get the BasicProperty properties for a particular object's class

Data and other attributes inherited from Propertied:
__dict__ = <dictproxy object at 0x01E9DD30>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Propertied' objects>
list of weak references to the object (if defined)

 
class SQLGrantStatements(SQLStatements)
    Class generating SQL grant statements for schemas
 
 
Method resolution order:
SQLGrantStatements
SQLStatements
Propertied
object

Methods defined here:
general(self, schema, *arguments, **named)
Get the results of all items within an item

Data and other attributes defined here:
dispatchMapping = {<class 'pytable.dbschema.TableSchema'>: <function general at 0x01C86DF0>, <class 'pytable.dbschema.IndexSchema'>: <function general at 0x01C86DF0>, <class 'pytable.dbschema.DatabaseSchema'>: <unbound method SQLStatements.expand>}
isGroup = <BooleanProperty 'isGroup'>
Whether 'user' is a group, rather than a regular user
privileges = <StringsProperty 'privileges'>
List of strings specifying the privileges to grant
 
Tables: select, insert, update, delete, rule, references, trigger
Databases: create, temporary, temp
Functions: execute
Languages: usage
Schemas: create, usage
 
ALL or ALL privileges grants all for the type, and
is the default value for the property.  That is, by
default all privileges will be granted to the user.
template = 'GRANT %(privileges)s ON %(dbObjectType)s %(name)s TO %(users)s;'
users = <StringsProperty 'users'>
List of users/groups to which to grant privileges
 
'PUBLIC' refers to everyone, otherwise is just the
user-name/group-name, groups are specified as 'group groupname',
regular users are just 'username'

Methods inherited from SQLStatements:
__call__(self, schema, *arguments, **named)
Create SQL creation statements for given schema
 
Returns the statements as a series of strings.
__init__(self, driver=None, **named)
Initialise the statement-generator
 
Driver will be used to determine features for
generation (when that's implemented).
dispatch(self, schema, *arguments, **named)
Dispatch to the appropriate handler and return value
expand(self, schema, *arguments, **named)
Get the results of all items within an item

Methods inherited from Propertied:
__str__(self)
Get a friendly representation of the object
clone(self, **newValues)
Clone this object, with optional new property values
 
This method calls the __init__ method of your class with
the current property values of your class.  Providing newValues
(a dictionary) overrides property settings with new values.
getCloneProperties(self)
Get properties dictionary (key:value) for use in cloning of the instance
 
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
toString(self, indentation='', alreadyDone=None, indentString=' ')
Get a nicely formatted representation of this object
 
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
 
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
 
XXX Needs a far better API, likely a stand-alone class
        without the automatic inheritance problems here :(

Class methods inherited from Propertied:
getProperties(cls) from type
Get the BasicProperty properties for a particular object's class

Data and other attributes inherited from Propertied:
__dict__ = <dictproxy object at 0x01E9DD10>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Propertied' objects>
list of weak references to the object (if defined)

 
class SQLRevokeStatements(SQLGrantStatements)
    Class generating SQL revoke statements for schemas
 
 
Method resolution order:
SQLRevokeStatements
SQLGrantStatements
SQLStatements
Propertied
object

Data and other attributes defined here:
template = 'REVOKE %(privileges)s ON %(dbObjectType)s %(name)s FROM %(users)s;'

Methods inherited from SQLGrantStatements:
general(self, schema, *arguments, **named)
Get the results of all items within an item

Data and other attributes inherited from SQLGrantStatements:
dispatchMapping = {<class 'pytable.dbschema.TableSchema'>: <function general at 0x01C86DF0>, <class 'pytable.dbschema.IndexSchema'>: <function general at 0x01C86DF0>, <class 'pytable.dbschema.DatabaseSchema'>: <unbound method SQLStatements.expand>}
isGroup = <BooleanProperty 'isGroup'>
Whether 'user' is a group, rather than a regular user
privileges = <StringsProperty 'privileges'>
List of strings specifying the privileges to grant
 
Tables: select, insert, update, delete, rule, references, trigger
Databases: create, temporary, temp
Functions: execute
Languages: usage
Schemas: create, usage
 
ALL or ALL privileges grants all for the type, and
is the default value for the property.  That is, by
default all privileges will be granted to the user.
users = <StringsProperty 'users'>
List of users/groups to which to grant privileges
 
'PUBLIC' refers to everyone, otherwise is just the
user-name/group-name, groups are specified as 'group groupname',
regular users are just 'username'

Methods inherited from SQLStatements:
__call__(self, schema, *arguments, **named)
Create SQL creation statements for given schema
 
Returns the statements as a series of strings.
__init__(self, driver=None, **named)
Initialise the statement-generator
 
Driver will be used to determine features for
generation (when that's implemented).
dispatch(self, schema, *arguments, **named)
Dispatch to the appropriate handler and return value
expand(self, schema, *arguments, **named)
Get the results of all items within an item

Methods inherited from Propertied:
__str__(self)
Get a friendly representation of the object
clone(self, **newValues)
Clone this object, with optional new property values
 
This method calls the __init__ method of your class with
the current property values of your class.  Providing newValues
(a dictionary) overrides property settings with new values.
getCloneProperties(self)
Get properties dictionary (key:value) for use in cloning of the instance
 
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
toString(self, indentation='', alreadyDone=None, indentString=' ')
Get a nicely formatted representation of this object
 
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
 
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
 
XXX Needs a far better API, likely a stand-alone class
        without the automatic inheritance problems here :(

Class methods inherited from Propertied:
getProperties(cls) from type
Get the BasicProperty properties for a particular object's class

Data and other attributes inherited from Propertied:
__dict__ = <dictproxy object at 0x01E9DD10>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Propertied' objects>
list of weak references to the object (if defined)

 
class SQLStatements(Propertied)
    Base-class for SQL-generating objects
 
XXX Should be doing a topological sort in order to
        resolve any dependencies between items.
 
 
Method resolution order:
SQLStatements
Propertied
object

Methods defined here:
__call__(self, schema, *arguments, **named)
Create SQL creation statements for given schema
 
Returns the statements as a series of strings.
__init__(self, driver=None, **named)
Initialise the statement-generator
 
Driver will be used to determine features for
generation (when that's implemented).
dispatch(self, schema, *arguments, **named)
Dispatch to the appropriate handler and return value
expand(self, schema, *arguments, **named)
Get the results of all items within an item

Data and other attributes defined here:
dispatchMapping = {}

Methods inherited from Propertied:
__str__(self)
Get a friendly representation of the object
clone(self, **newValues)
Clone this object, with optional new property values
 
This method calls the __init__ method of your class with
the current property values of your class.  Providing newValues
(a dictionary) overrides property settings with new values.
getCloneProperties(self)
Get properties dictionary (key:value) for use in cloning of the instance
 
By default you get getProperties()' values, with an
attempt made to use the property's name, then the property's
direct "__get__" method.
toString(self, indentation='', alreadyDone=None, indentString=' ')
Get a nicely formatted representation of this object
 
This version assumes that getProperties returns
the list of properties which should be presented,
it recursively calls it's children with greater
indents to get their representations.
 
indentation -- current string indentation level
alreadyDone -- set of object ids which are already finished
 
XXX Needs a far better API, likely a stand-alone class
        without the automatic inheritance problems here :(

Class methods inherited from Propertied:
getProperties(cls) from type
Get the BasicProperty properties for a particular object's class

Data and other attributes inherited from Propertied:
__dict__ = <dictproxy object at 0x01E9DD90>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'Propertied' objects>
list of weak references to the object (if defined)