Package Modeling :: Package DatabaseAdaptors :: Package MySQLAdaptorLayer :: Module MySQLSQLExpression :: Class MySQLSQLExpression
[show private | hide private]
[frames | no frames]

Type MySQLSQLExpression

   object --+    
            |    
SQLExpression --+
                |
               MySQLSQLExpression


Sub-class of SQLExpression for the MySQLAdaptor. It overrides valueTypeForExternalTypeMapping() to remove the TIMESTAMP type from the available SQL data types.
Method Summary
  columnTypeStringForAttribute(self, attribute)
Overrides default implementation to handle TEXT field properly.
  prepareSelectCountExpressionWithAttributes(self, attributes, lock, fetchSpec)
Overrides the default method and prepares a SQL expression suitable for MySQL, counting the rows qualified by 'fetchSpec'.
  sqlStringForSelector(self, selector, value)
Overrides the default behaviour to ensure that Qualifier operator 'LIKE' matches case-sensitively.
  valueTypeForExternalTypeMapping(self)
REMOVES 'timestamp' from the available SQL types returned by Modeling.SQLExpression, and adds 'datetime' and 'text'.
    Inherited from SQLExpression
  __init__(self, anEntity)
Initializer
  addBindVariableDictionary(self, binding)
  addCreateClauseForAttribute(self, attribute)
Adds the create clause for the supplied 'attribute' to the receiver's listString.
  addInsertListAttribute(self, attribute, value)
Parameters:
  addJoinClause(self, leftName, rightName, semantic)
  addOrderByAttributeOrdering(self, sortOrdering)
  addSelectListAttribute(self, attribute)
Adds the sqlStringForAttributeNamed(attribute.name()) to the SQLExpression's listString().
  addUpdateListAttribute(self, attribute, value)
Uses appendItemToListString() to add to listString() a string formatted that way:
  aliasesByRelationshipPath(self)
Returns the dictionary of table aliases used by the SQLExpression ; the keys are relationshipPath and the values are the corresponding table aliases.
  allowsNullClauseForConstraint(self, flag)
Returns 'NOT NULL' is flag is false, '' (empty string) otherwise.
  appendItemToListString(self, itemString, aStringIO)
Appends 'itemString' to 'aStringIO' ; if aStringIO is not empty, a comma is appended to aStringIO before 'itemString'
  assembleDeleteStatementWithQualifier(self, aQualifier, tableList, whereClause)
Generates the SQL DELETE statement and assigns it to self's statement() The generated statement has the following format:
  assembleInsertStatementWithRow(self, row, tableList, columnList, valueList)
Generates the SQL INSERT statement and assigns it to self's statement() The generated statement has the following format:
  assembleSelectStatementWithAttributes(self, attributes, lock, qualifier, fetchOrder, selectString, columnList, tableList, whereClause, joinClause, orderByClause, lockClause)
  assembleUpdateStatementWithRow(self, row, aQualifier, tableList, updateList, whereClause)
Generates the SQL INSERT statement and assigns it to self's statement() The generated statement has the following format:
  bindVariableDictionaries(self)
  bindVariableDictionaryForAttribute(self, attribute, value)
  entity(self)
Returns the Entity bound to that SQLExpression
  entityExternalNamesByAliases(self)
  externalNameQuoteCharacter(self)
Unimplemented
  formatSQLString(self, sqlString, format)
Unimplemented
  formatStringValue(self, string)
Unimplemented
  formatValueForAttribute(self, value, attribute)
Examines the attribute's externalType and forwards the request to the appropriate method.
  joinClauseString(self)
Unimplemented and unused: the joinClause is not used in this implementation of SQLExpression.
  joinExpression(self)
Unimplemented and not used: cf.
  listString(self)
Has a different meaning depending on what the SQLExpression was made for:
  lockClause(self)
  mustUseBindVariableForAttribute(self, attribute)
  orderByString(self)
  prepareConstraintStatementForRelationship(self, relationship, sourceColumns, destinationColumns)
  prepareDeleteExpressionForQualifier(self, aQualifier)
Prepares the internal state to generate a SQL delete statement, according to entity() and parameter 'aQualifier'.
  prepareInsertExpressionWithRow(self, row)
Generates an INSERT statement for the supplied 'row' and the SQLExpression's entity().
  prepareSelectExpressionWithAttributes(self, attributes, lock, fetchSpec)
Prepares a 'SELECT' statement.
  prepareUpdateExpressionWithRow(self, row, aQualifier)
Parameters:
  setStatement(self, statement)
Sets the object's SQL statement.
  setUseAliases(self, useAliases)
Tells the SQLExpression whether it should use table aliases.
  setUseBindVariables(self, flag)
Bind variables are not supported yet
  shouldUseBindVariableForAttribute(self, attribute)
Bind variables are not supported yet
  sqlEscapeChar(self)
  sqlPatternFromShellPattern(self, pattern)
Simply calls sqlPatternFromShellPatternWithEscapeCharacter() with 'escapeChar' equal to 'self.sqlEscapeChar()'
  sqlPatternFromShellPatternWithEscapeCharacter(self, pattern, escapeChar)
Transforms the shell 'pattern', using '*' and '?' as wildcards (the former matches 0 to many characters while the second matches one character) to an valid SQL pattern.
  sqlStringForAttribute(self, attribute)
Returns the attribute's columnName, prepended with the table alias for the empty string if the SQLExpression uses table aliases.
  sqlStringForAttributeNamed(self, name)
Returns the sql string for the attribute 'name'.
  sqlStringForAttributePath(self, path)
Given a path (see below), builds the corresponding sql string, completed with a table alias if the SQLExpression useAliases().
  sqlStringForCaseInsensitiveLike(self, keyString, valueString)
Returns the SQL string, to be inserted in a WHERE clause, for case-insensitive comparison between a lvalue and a rvalue.
  sqlStringForConjoinedQualifiers(self, qualifiers)
Returns the SQL string, to be inserted in a WHERE clause, for the supplied ``to-be-conjoined'' qualifiers.
  sqlStringForData(self, data)
Not supported yet
  sqlStringForDate(self, aDate)
Formats the 'mxDateTime.DateTime' object 'aDate'.
  sqlStringForDisjoinedQualifiers(self, qualifiers)
Returns the SQL string, to be inserted in a WHERE clause, for the supplied ``to-be-disjoined'' qualifiers.
  sqlStringForInOperatorValue(self, aList, key)
Returns the SQL string suitable for operator IN and NOT IN.
  sqlStringForJoinSemantic(self, joinSemantic)
  sqlStringForKeyComparisonQualifier(self, aQualifier)
Returns the SQL string for the KeyComparisonQualifier supplied.
  sqlStringForKeyValueQualifier(self, aQualifier)
Returns the SQL string for the KeyValueQualifier supplied.
  sqlStringForNegatedQualifier(self, aQualifier)
Returns the SQL string for the supplied Qualifier
  sqlStringForNumber(self, aNumber, keyPath)
Formats 'aNumber' and returns the string suitable for inclusion in a SQL statement.
  sqlStringForQualifier(self, aQualifier)
Returns the SQL WHERE clause string built from 'aQualifier' ; NB: the generated statement does not include the 'WHERE' SQL keyword.
  sqlStringForSchemaObjectName(self, name)
Unimplemented
  sqlStringForString(self, aString)
Formats 'aString' and returns the string suitable for inclusion in a SQL statement.
  sqlStringForValue(self, value, keyPath)
Simply calls formatValueForAttribute() and return the formatted string
  statement(self)
Returns the statement assigned to this object.
  tableListWithRootEntity(self, anEntity)
  toString(self)
Simply returns self.statement()
  useAliases(self)
Returns whether the SQLExpression uses table aliases.
  useBindVariables(self)
Bind variables are not supported yet: return '0' (false)
  valueList(self)
This is set when prepareInsertExpressionWithRow() is called, and it holds the list of values to insert.
  valueTypeForExternalType(self, externalTypeName)
Returns the value type corresponding to 'externalTypeName'.
  whereClauseString(self)
Returns the WHERE clause string generated for a given SQL statement.
  _addTableJoinsForAlias(self, alias, str)
Calculates the SQL statements for JOIN.
  _prepareSelectExpressionWithAttributes(self, attributes, lock, fetchSpec, count)
Prepares the SELECT statement for prepareSelectCountExpressionWithAttributes() and prepareSelectExpressionWithAttributes().
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
int SQL92_join = 1                                                                     

Method Details

columnTypeStringForAttribute(self, attribute)

Overrides default implementation to handle TEXT field properly.

It returns a different string depending on some of the attribute's properties:

  • if attribute's precision is not zero: 'externalType(precision, scale)'
  • if attribute's width is not zero and its externalType is not TEXT: 'externalType(width)'
  • otherwise returns: 'externalType'

About 'TEXT': a model can define a width for a TEXT field. It should be ignored when generating the database schema (for example, TEXT(30) is an invalid data type), however it might be set to request the validation mechanism to check the attribute's length at runtime, typically before an EditingContext saves its changes.

See also:
addCreateClauseForAttribute() SchemaGeneration.createTableStatementsForEntityGroup()
Overrides:
Modeling.SQLExpression.SQLExpression.columnTypeStringForAttribute

prepareSelectCountExpressionWithAttributes(self, attributes, lock, fetchSpec)

Overrides the default method and prepares a SQL expression suitable for MySQL, counting the rows qualified by 'fetchSpec'.

The SQL statement depends on whether 'fetchSpec' implies joining two or more tables:

  • if at least a join is needed, the statement is like:

    SELECT COUNT(DISTINCT t0.pk1, t0.pk2, ...) FROM ...
    INNER JOIN ...
    [WHERE <fetchSpec's condition>]
    

    where pk1, pk2 are the primary keys in the fetchSpec's entity,

  • otherwise, it is like:

    SELECT COUNT(*) FROM <table> [WHERE <fetchSpec's condition>]

Parameters:

attributes -- the attributes to fetch (they do not appear in the sql)

lock -- Unimplemented, should be false

fetchSpec -- the FetchSpecification qualifying the rows to be counted

Overrides:
Modeling.SQLExpression.SQLExpression.prepareSelectCountExpressionWithAttributes

sqlStringForSelector(self, selector, value)

Overrides the default behaviour to ensure that Qualifier operator 'LIKE' matches case-sensitively.

Note: this is because the SQL LIKE operator is case-insensitive by default in MySQL.

Returns:

  • if selector is Modeling.Qualifier.QualifierOperatorLike, returns "LIKE BINARY"
  • otherwise returns SQLExpression.sqlStringForSelector()

See also: SQLExpression.sqlStringForSelector()

Overrides:
Modeling.SQLExpression.SQLExpression.sqlStringForSelector

valueTypeForExternalTypeMapping(self)

REMOVES 'timestamp' from the available SQL types returned by Modeling.SQLExpression, and adds 'datetime' and 'text'.

The reason for the removal of 'timestamp' is that, in MySQL, a DateTime field is likely to be modified during an update operation, completely implicitly. This would cause weird bugs, because the framework does not expect values to change implicitly.

Quoted from http://www.mysql.com/documentation/mysql/bychapter/manual_Reference.html#DATETIME:

The TIMESTAMP column type provides a type that you can use to automatically mark INSERT or UPDATE operations with the current date and time. If you have multiple TIMESTAMP columns, only the first one is updated automatically.

Automatic updating of the first TIMESTAMP column occurs under any of the following conditions:

  • The column is not specified explicitly in an INSERT or LOAD DATA INFILE statement.
  • The column is not specified explicitly in an UPDATE statement and some other column changes value. (Note that an UPDATE that sets a column to the value it already has will not cause the TIMESTAMP column to be updated, because if you set a column to its current value, MySQL ignores the update for efficiency.)
  • You explicitly set the TIMESTAMP column to NULL.

(end of quote)

Overrides:
Modeling.SQLExpression.SQLExpression.valueTypeForExternalTypeMapping

Class Variable Details

SQL92_join

Type:
int
Value:
1                                                                     

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