Package Modeling :: Package DatabaseAdaptors :: Package SQLiteAdaptorLayer :: Module SQLiteSchemaGeneration :: Class SQLiteSchemaGeneration
[show private | hide private]
[frames | no frames]

Class SQLiteSchemaGeneration

SchemaGeneration --+
                   |
                  SQLiteSchemaGeneration


See Modeling.interfaces.SchemaGeneration for further details
Method Summary
  createDatabaseStatementsForConnectionDictionary(self, connectionDictionary, administrativeConnectionDictionary, createUserFlag)
Returns an empty list: connecting to a non existent database is sufficient to create it.
  createTableStatementsForEntityGroup(self, entityGroup)
Extends the default baheviour to add foreign key constraints in the CREATE TABLE sql statement.
  dropDatabaseStatementsForConnectionDictionary(self, connectionDictionary, administrativeConnectionDictionary, dropUserFlag)
Returns an empty list, since there's no way to drop a database within sqlite.
  dropForeignKeyConstraintStatementsForRelationship(self, relationship)
returns an empty list TBD
  dropPrimaryKeyConstraintStatementsForEntityGroup(self, entityGroup)
returns an empty list TBD
  dropPrimaryKeySupportStatementsForEntityGroup(self, entityGroup)
Returns a list containing a single SQLExpression statement, which takes the following form: 'DROP TABLE <SEQUENCE_NAME>', where '<SEQUENCE_NAME>' is:
  foreignKeyConstraintStatementsForRelationship(self, relationship, sqlExpr_for_create)
Overrides the default behaviour so that constraints statements are not generated in a separate 'ALTER TABLE' statement (which is not supported by SQLite), but rather during the createTableStatementsForEntityGroup() phase.
  primaryKeyConstraintStatementsForEntityGroup(self, entityGroup)
Returns an empty list.
  primaryKeySupportStatementsForEntityGroup(self, entityGroup)
Returns a list containing two SQLExpression statements, which take the following form:
    Inherited from SchemaGeneration
  __init__(self, anAdaptor)
See interfaces.SchemaGeneration for details
  appendExpressionToScript(self, expression, script)
Appends the expression to the StringIO script, prepended with a semi-colon (';') and a newline if the StringIO is not empty.
  createTableStatementsForEntityGroups(self, entityGroups)
Invokes createTableStatementsForEntityGroup() for each entityGroup in 'entityGroups', and returns the list of SQLExpressions needed to create the necessary table.
  defaultOrderingsForSchemaCreation()
Used in method SchemaGeneration.schemaCreationScriptForEntities() to order the schema creation statements produced (Static method)
  dropPrimaryKeyConstraintStatementsForEntityGroups(self, entityGroups)
Iterates on each entityGroup in 'entityGroups', sends the message 'dropPrimaryKeyConstraintStatementsForEntityGroup' to each of them, collects the results and returns them in a sequence.
  dropPrimaryKeySupportStatementsForEntityGroups(self, entityGroups)
Iterates on each entityGroup in 'entityGroups', sends the message 'dropPrimaryKeySupportStatementsForEntityGroup' to each of them, collects the results and returns them in a sequence.
  dropTableStatementsForEntityGroup(self, entityGroup)
Parameter:
  dropTableStatementsForEntityGroups(self, entityGroups)
Iterates on each entityGroup in 'entityGroups', sends the message 'dropPrimaryKeySupportStatementsForEntityGroup()' to each of them, collects the results and returns them in a sequence.
  primaryKeyConstraintStatementsForEntityGroups(self, entityGroups)
Iterates on each entityGroup in 'entityGroups', sends the message 'primaryKeyConstraintStatementsForEntityGroup' to each of them, collects the results and returns them in a sequence.
  primaryKeySupportStatementsForEntityGroups(self, entityGroups)
Iterates on each entityGroup in 'entityGroups', sends the message 'primaryKeySupportStatementsForEntityGroup' to each of them, collects the results and returns them in a sequence.
  schemaCreationScriptForEntities(self, allEntities, options, keyOrderings)
__TBD
  schemaCreationStatementsForEntities(self, allEntities, options, keyOrderings)
__TBD doc.
  schemaCreationStatementsForEntitiesByOptions(self, allEntities, options)
__TBD doc.
  setDefaultOrderingsForSchemaCreation(keyOrderings)
Sets the default ordering. (Static method)
  tableEntityGroupsForEntities(self, entities)
Returns a list of entityGroups ; each entityGroup consists of the entities in parameter 'entities' which share the same externalName(), and wich answered positively to the definesTableColumns() message.

Class Variable Summary
    Inherited from SchemaGeneration
tuple __implements__ = (<class Modeling.interfaces.SchemaGener...

Instance Method Details

createDatabaseStatementsForConnectionDictionary(self, connectionDictionary, administrativeConnectionDictionary, createUserFlag=0)

Returns an empty list: connecting to a non existent database is sufficient to create it.

See also: interfaces.SchemaGeneration for details

Overrides:
Modeling.SchemaGeneration.SchemaGeneration.createDatabaseStatementsForConnectionDictionary

createTableStatementsForEntityGroup(self, entityGroup)

Extends the default baheviour to add foreign key constraints in the CREATE TABLE sql statement. This is because SQLite does not support ALTER TABLE.

It uses the overridden foreignKeyConstraintStatementsForRelationship() for that purpose, seee its docstring for details.

Parameter:

entityGroup -- a list of entities whose externalNames are identical.
Overrides:
Modeling.SchemaGeneration.SchemaGeneration.createTableStatementsForEntityGroup

dropDatabaseStatementsForConnectionDictionary(self, connectionDictionary, administrativeConnectionDictionary, dropUserFlag=0)

Returns an empty list, since there's no way to drop a database within sqlite. The only thing to do is to os.unlink() the database file.

See also: SQLiteAdaptor.dropDatabaseWithAdministrativeConnectionDictionary

See Modeling.interfaces.SchemaGeneration for details

Overrides:
Modeling.SchemaGeneration.SchemaGeneration.dropDatabaseStatementsForConnectionDictionary

dropForeignKeyConstraintStatementsForRelationship(self, relationship)

returns an empty list TBD
Overrides:
Modeling.SchemaGeneration.SchemaGeneration.dropForeignKeyConstraintStatementsForRelationship

dropPrimaryKeyConstraintStatementsForEntityGroup(self, entityGroup)

returns an empty list TBD
Overrides:
Modeling.SchemaGeneration.SchemaGeneration.dropPrimaryKeyConstraintStatementsForEntityGroup

dropPrimaryKeySupportStatementsForEntityGroup(self, entityGroup)

Returns a list containing a single SQLExpression statement, which takes the following form: 'DROP TABLE <SEQUENCE_NAME>', where '<SEQUENCE_NAME>' is:

'PK_SEQ_%s'%entityGroup[0].primaryKeyRootName()

See primaryKeySupportStatementsForEntityGroup() for further details on how sequences can be emulated with SQLite databases.

See Modeling.interfaces.SchemaGeneration for further details

Overrides:
Modeling.SchemaGeneration.SchemaGeneration.dropPrimaryKeySupportStatementsForEntityGroup

foreignKeyConstraintStatementsForRelationship(self, relationship, sqlExpr_for_create=None)

Overrides the default behaviour so that constraints statements are not generated in a separate 'ALTER TABLE' statement (which is not supported by SQLite), but rather during the createTableStatementsForEntityGroup() phase.

When 'sqlExpr_for_create' is supplied (see below), the following constraint is appended to its listString():

CONSTRAINT <REL_NAME> FOREIGN KEY (<FKS>)
  REFERENCES <DESTINATION_TABLE>(<DESTINATION_PK>)
where REL_NAME is the relationship's source attribute columnName(),
FKS is a comma-separated list of the relationship's source
attributes.columnName(),
DESTINATION_TABLE is the relationship.destinationEntity() 's
externalName()
DESTINATION_PKS is a comma-separated list of the rel.'s
destinationAttributes().columnName(),

The conditions under which the statement above is returned are:

  • the relationship is a toOne rel. and it is not flattened,
  • its inverseRelationship, if any, is a toMany relationship,
  • its source and destinationEntity share the same model,
  • the destinationEntity has no sub-entity.

If any of these conditions is not fulfilled the method returns an empty sequence.

Parameters:

relationship -- a Relationship instance from which the constraint is
derived
sqlExpr_for_create -- when None, simply returns an empty list. Otherwise
this is the SQLiteSQLExpression used in the createTableStatementsForEntityGroup() phase. The foreign key constraint is appended to the sqlExpression's listString, to be later retrieved with sqlExpression.listString()
Overrides:
Modeling.SchemaGeneration.SchemaGeneration.foreignKeyConstraintStatementsForRelationship

primaryKeyConstraintStatementsForEntityGroup(self, entityGroup)

Returns an empty list. __TBD

Parameter 'entityGroup' is a list of entities whose externalNames are identical.

See also: dropPrimaryKeyConstraintStatementsForEntityGroup
primaryKeyConstraintStatementsForEntityGroups dropPrimaryKeySupportStatementsForEntityGroup
Overrides:
Modeling.SchemaGeneration.SchemaGeneration.primaryKeyConstraintStatementsForEntityGroup

primaryKeySupportStatementsForEntityGroup(self, entityGroup)

Returns a list containing two SQLExpression statements, which take the following form:

CREATE TABLE <SEQUENCE_NAME> (id INT NOT NULL)
INSERT INTO <SEQUENCE_NAME> VALUES(0)

where '<SEQUENCE_NAME>' is:

'PK_SEQ_%s'%entityGroup[0].primaryKeyRootName()

The statements used by SQLiteAdaptorChannel.primaryKeysForNewRowsWithEntity are the following:

'UPDATE PK_SEQ_%s SET id=((select max(col1) from table1)+1'%pkRootName
'select id FROM PK_SEQ_%s'%pkRootName

See Modeling.interfaces.SchemaGeneration for further details

See also:
dropPrimaryKeySupportStatementsForEntityGroup() SQLiteAdaptorChannel.primaryKeysForNewRowsWithEntity()
Overrides:
Modeling.SchemaGeneration.SchemaGeneration.primaryKeySupportStatementsForEntityGroup

Generated by Epydoc 2.1 on Sat Mar 4 13:36:25 2006 http://epydoc.sf.net