Package Modeling :: Module SQLExpression :: Class SQLExpression
[show private | hide private]
[frames | no frames]

Type SQLExpression

object --+
         |
        SQLExpression

Known Subclasses:
MySQLSQLExpression, OracleSQLExpression, PostgresqlSQLExpression, SQLiteSQLExpression

Method Summary
  __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)
  columnTypeStringForAttribute(self, attribute)
Returns the string corresponding to the attribute's column type definition when creating a table.
  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().
  prepareSelectCountExpressionWithAttributes(self, attributes, lock, fetchSpec)
Prepares a 'SELECT' statement from retrieving the number of rows corresponding to the request.
  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
  sqlStringForSelector(self, selector, value)
Returns the appropriate SQL string corresponding to 'selector'
  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'.
  valueTypeForExternalTypeMapping(self)
Returns a dictionary consisting of the valid SQL types, each of which being a key bound to either 'BinaryType', 'CharacterType', 'DateType' or 'NumericType' (module's constants)
  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
classobj Internals = Modeling.SQLExpression.Internals
int SQL92_join = 1                                                                     

Method Details

__init__(self, anEntity=None)
(Constructor)

Initializer
Overrides:
__builtin__.object.__init__

addCreateClauseForAttribute(self, attribute)

Adds the create clause for the supplied 'attribute' to the receiver's listString. The default implementation appends a line of the following form:

<newline><COLUMN_NAME> <COLUMN_TYPE_STRING> <ALLOWS_NULL_CLAUSE>

where <COLUMN_NAME> is the attribute's columnName(), <COLUMN_TYPE_STRING> is 'columnTypeStringForAttribute(attribute)' and <ALLOWS_NULL_CLAUSE> is 'allowsNullClauseForConstraint(attribute.allowsNull())'.

See also:
appendItemToListString() listString() allowsNullClauseForConstraint() columnTypeStringForAttribute() SchemaGeneration.createTableStatementsForEntityGroup()

addInsertListAttribute(self, attribute, value)

Parameters:

attribute -- an Attribute object

value -- the value to store

addSelectListAttribute(self, attribute)

Adds the sqlStringForAttributeNamed(attribute.name()) to the SQLExpression's listString().

See also: sqlStringForAttributeNamed(), appendItemToListString(),
listString()

addUpdateListAttribute(self, attribute, value)

Uses appendItemToListString() to add to listString() a string formatted that way:

<attribute's columnName()> = <value>

See also: prepareUpdateExpressionWithRow(), listString()

aliasesByRelationshipPath(self)

Returns the dictionary of table aliases used by the SQLExpression ; the keys are relationshipPath and the values are the corresponding table aliases.

If useAliases() is true, the dictionary contains at least one entry with an empty string as the key and 't0' being the corresponding value. Otherwise, it may be None.

That dictionary is built upon successive invocation of sqlStringForAttributePath().

See also: setUseAliases(),
sqlStringForAttributePath(), sqlStringForAttributeNamed()

allowsNullClauseForConstraint(self, flag)

Returns 'NOT NULL' is flag is false, '' (empty string) otherwise.

Subclasses should override this method, without calling it, if the underlying database uses a different syntax for such a clause.

See: addCreateClauseForAttribute()

appendItemToListString(self, itemString, aStringIO)

Appends 'itemString' to 'aStringIO' ; if aStringIO is not empty, a comma is appended to aStringIO before 'itemString'

Parameters:

  • itemString is the string to append
  • aStringIO is a StringIO object
See:
addCreateClauseForAttribute()

assembleDeleteStatementWithQualifier(self, aQualifier, tableList, whereClause)

Generates the SQL DELETE statement and assigns it to self's statement() The generated statement has the following format:

DELETE FROM <tableList> WHERE <whereClause>

Parameters:

aQualifier -- identifies the rows to be deleted. This is usually the
parameter that prepareDeleteExpressionForQualifier() received before this method is called. It is not used here but might be useful for subclasses' implementation

tableList -- the name of the table in which the row should be deleted

whereClause -- the SQL where clause to use in the DELETE statement.

See also: statement(), prepareDeleteExpressionForQualifier()

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:

INSERT INTO <tableList> [<columnList>] VALUES <valueList>

<columnList> will be omitted

Parameters:

row -- the 'row' parameter that was passed to
prepareInsertExpressionWithRow(). It is not used here but might be useful for subclasses' implementation

tableList -- the name of the table in which the row should be inserted

columnList -- a comma-separated string containing the name of the
columns (order: see below)
valueList -- a comma-separated string of values to be inserted in the
'tableList'. 'columnList' and 'valueList' should have the same order, i.e. entries in the former correspond one-to-one to entries in the latter.

See also: statement(), prepareInsertExpressionWithRow()

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:

UPDATE <tableList> SET <updateList> WHERE <whereClause>

Parameters:

row --

aQualifier -- identifies the rows to be deleted. This is usually the
parameter that prepareDeleteExpressionForQualifier() received before this method is called. It is not used here but might be useful for subclasses' implementation

tableList -- the name of the table in which the row should be updated

updateList -- the SQL where clause to use in the UPDATE's SET statement.

whereClause -- the SQL where clause to use in the UPDATE's WHERE
statement.

See also: statement(), prepareUpdateExpressionWithRow()

columnTypeStringForAttribute(self, attribute)

Returns the string corresponding to the attribute's column type definition when creating a table.

Default implementation 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: 'externalType(width)'
  • otherwise returns: 'externalType'

Subclasses should override this method, without calling it, if the underlying database uses a different syntax for column types.

See also:
addCreateClauseForAttribute() SchemaGeneration.createTableStatementsForEntityGroup()

entity(self)

Returns the Entity bound to that SQLExpression

See: __init__()

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.

The methods to which the message is forwarded are:

  • for BinaryType: sqlStringForData()
  • for CharacterType: sqlStringForString()
  • for DateType: sqlStringForDate()
  • for NumericType: sqlStringForNumber()

Raises InvalidSQLTypeError is the attribute's external type is unknown for the concrete adaptor.

See also: valueTypeForExternalType(), sqlStringForValue()

joinClauseString(self)

Unimplemented and unused: the joinClause is not used in this implementation of SQLExpression. The statements necessary to support joins (for SELECT, mainly) are generated in the whereClause when the tables and their aliases are examined.

joinExpression(self)

Unimplemented and not used: cf. joinClauseString()

listString(self)

Has a different meaning depending on what the SQLExpression was made for:

  • for createTableStatements, it holds the list of columns' type declarations
  • for insert statements, it holds the list of column's names (see also: valueList())
  • for update statements, contains the SQL clause suitable for the SET

statement (in: 'UPDATE ... SET ... WHERE ...')

prepareDeleteExpressionForQualifier(self, aQualifier)

Prepares the internal state to generate a SQL delete statement, according to entity() and parameter 'aQualifier'.

The process is the following:

  • the use of aliases is disabled (see setUseAliases())

  • the whereClauseString() is compuuted ans set by calling

    'sqlStringForQualifier(aQualifier)' on itself,

  • the database table is computed by calling tableListWithRootEntity()

  • Finally, we send to oneself 'assembleDeleteStatementWithQualifier()'

See also: assembleDeleteStatementWithQualifier(), whereClauseString()

prepareInsertExpressionWithRow(self, row)

Generates an INSERT statement for the supplied 'row' and the SQLExpression's entity().

The process is the following:

  • the use of aliases is disabled (see setUseAliases())
  • it calls addInsertListAttribute() on 'self' for each item in 'row'. Afterwards, listString() contains a comma-separated list of column's name, and valueList() a comma-separated list of their values, both following the same order, of course.
  • it gets the name of the table by sending the message tableListWithRootEntity to itself
  • finally, it calls assembleInsertStatementWithRow() with the elements calculated above.

The generated INSERT statement is then available through 'statement()'

Parameter:

row -- a dictionary, with keys as Attribute's names, which are bound to
their corresponding values.
See also: assembleInsertStatementWithRow(), listString(), valueList(),
statement()

prepareSelectCountExpressionWithAttributes(self, attributes, lock, fetchSpec)

Prepares a 'SELECT' statement from retrieving the number of rows corresponding to the request. The statement is then available as a string in self.statement().

See also: AdaptorChannel.rowCountForSelectAttributes()

prepareSelectExpressionWithAttributes(self, attributes, lock, fetchSpec)

Prepares a 'SELECT' statement. The statement is then available as a string in self.statement().

See also: AdaptorChannel.selectAttributes()

prepareUpdateExpressionWithRow(self, row, aQualifier)

Parameters:

row -- a dictionary {key==attributeName: value==value to update}

aQualifier -- identifies the rows to be updated.

setStatement(self, statement)

Sets the object's SQL statement.

setUseAliases(self, useAliases)

Tells the SQLExpression whether it should use table aliases.

This method has a side-effect: if flag 'useAliases' is true and the SQLExpression's aliasesByRelationshipPath() is empty, the latter gets value 't0' for key '""' (empty string) ; if the flag is false, aliasesByRelationshipPath() is reset.

See also: useAliases()

setUseBindVariables(self, flag)

Bind variables are not supported yet

shouldUseBindVariableForAttribute(self, attribute)

Bind variables are not supported yet

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.

Details: '%' in 'pattern' becomes '%', '_' becomes '_',
'*' becomes '*', '*' becomes '%', '?' becomes '?' and '?' becomes '_'.

sqlStringForAttribute(self, attribute)

Returns the attribute's columnName, prepended with the table alias for the empty string if the SQLExpression uses table aliases.

For example, the returned value for an attribute 'title' whose columnName is 'TITLE' is 'TITLE', or 't0.TITLE' if useAliases() is true.

See also: useAliases(), aliasesByRelationshipPath(), Attribute.columnName()

sqlStringForAttributeNamed(self, name)

Returns the sql string for the attribute 'name'. If the corresponding attribute is a regular Attribute (non flattened), it triggers sqlStringForAttribute() ; otherwise, it builds the path and triggers sqlStringForAttributePath() (see sqlStringForAttributePath() for a description of what 'building the path' means).

Raises ValueError in case 'name' is not a valid attribute's name.

See also: sqlStringForAttribute, sqlStringForAttributePath()
Attribute.isFlattened(), Attribute.relationshipPathObjects(), Attribute.finalAttribute()

sqlStringForAttributePath(self, path)

Given a path (see below), builds the corresponding sql string, completed with a table alias if the SQLExpression useAliases().

Parameter 'path' is a list composed of Relationship objects that has to be traversed to access the final Attribute, which is the last element of the list.

If table aliases is on and aliasesByRelationshipPath() has no key corresponding to the relationshipPath, that key is set with a new table alias.

Example: say we have two entities 'Book' and 'Writer', a toOne relationship 'toBook' from 'Writer' to 'Book', and 'Writer' defined an attribute 'bookTitle' flattening 'toBook.title' (title being a regular attribute of 'Book'). When table aliases is on, this methods returns something like 't1.TITLE' --in that case, aliasesByRelationshipPath() has a key 'toBook' corresponding to the value 't1'.

Important note:

It seems that derived attribute should not be used except to support inheritance and the vertical-mapping approach. This is not supported for the moment being, thus this method is desactivated and will unconditionnally raise when invoked. See the project's TODO file for a more complete explanation.
See also: useAliases(), sqlStringForAttribute(),
aliasesByRelationshipPath(), Attribute.relationshipPathObjects(), Attribute.finalAttribute()

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.

Default implementation returns the following string:

UPPER(<keyString>) LIKE UPPER(<valueString>)

Parameters:

keyString -- the left value

valueString -- the right value

See also: sqlStringForKeyValueQualifier(),
sqlStringForKeyComparisonQualifier()

sqlStringForConjoinedQualifiers(self, qualifiers)

Returns the SQL string, to be inserted in a WHERE clause, for the supplied ``to-be-conjoined'' qualifiers.

Default implementation returns:

<qualifierString1> AND <qualifierString2> AND ...
      ... AND <qualifierString_i>

where '<qualifierString_i>' is 'sqlStringForQualifier(qualifiers[i])'

Parameter:

qualifiers -- a sequence of qualifier that should be conjoined. If you
have a 'Qualifier.AndQualifier' instance 'andQualifier', you should supply 'andQualifier.qualifiers()' as the argument

See also: sqlStringForQualifier()

sqlStringForData(self, data)

Not supported yet

sqlStringForDate(self, aDate)

Formats the 'mxDateTime.DateTime' object 'aDate'. SQLExpression's implementation simply returns 'str(aDate)', or 'NULL' if 'aDate' is None.

See also: formatValueForAttribute()

sqlStringForDisjoinedQualifiers(self, qualifiers)

Returns the SQL string, to be inserted in a WHERE clause, for the supplied ``to-be-disjoined'' qualifiers.

Default implementation returns:

<qualifierString1> OR <qualifierString2> OR ... OR <qualifierString_i>

where '<qualifierString_i>' is 'sqlStringForQualifier(qualifiers[i])'

Parameter:

qualifiers -- a sequence of qualifier that should be disjoined. If you
have a 'Qualifier.OrQualifier' instance 'orQualifier', you should supply 'orQualifier.qualifiers()' as the argument

See also: sqlStringForQualifier()

sqlStringForInOperatorValue(self, aList, key)

Returns the SQL string suitable for operator IN and NOT IN. The returned string is a comma-separated list of the values in aList, surrounded by brackets.

Example: aList=[1], return '(1)'
aList=(1,2,4), return '(1, 2, 4)'

sqlStringForKeyComparisonQualifier(self, aQualifier)

Returns the SQL string for the KeyComparisonQualifier supplied.

It is of the form:

<left_columnName> <operator> <right_columnName>

such as in:

t0.LAST_NAME != t2.FIRST_NAME

Both column names are returned by sqlStringForAttributeNamed(), and the operator is computed by sqlStringForSelector().

When the quelifier's operator is Qualifier.QualifierOperatorCaseInsensitiveLike, the returned string is calculated by sqlStringForCaseInsensitiveLike.

Parameter:

aQualifier -- a Qualifier.KeyComparisonQualifier instance

See also: sqlStringForQualifier()

sqlStringForKeyValueQualifier(self, aQualifier)

Returns the SQL string for the KeyValueQualifier supplied.

It is of the form:

<key> <operator> <value>

such as in:

t0.LAST_NAME LIKE 'R%'

'key' is returned by sqlStringForAttributeNamed(), 'operator', by sqlStringForSelector(), and 'value': by sqlStringForValue(), or by sqlPatternFromShellPattern() is the qualifier's operator is 'LIKE' or case-insensitive-LIKE (and, when the case-insensitive form of 'LIKE' is used, the returned string is computed by sqlStringForCaseInsensitiveLike)

Parameter:

aQualifier -- a Qualifier.KeyValueQualifier instance

See also: sqlStringForQualifier()

sqlStringForNegatedQualifier(self, aQualifier)

Returns the SQL string for the supplied Qualifier

The string returned is:

NOT (<qualification>)

where 'qualification' is 'sqlStringForQualifier(aQualifier)'

Parameter:

aQualifier -- the qualifier to negate, NOT the corresponding
'NotQualifier'. If 'notQualifier' is is Qualifier.NotQualifier, you should supply 'notQualifier.qualifier()' as the argument.

sqlStringForNumber(self, aNumber, keyPath='')

Formats 'aNumber' and returns the string suitable for inclusion in a SQL statement. SQLExpression's implementation simply returns 'str(aNumber)', or 'NULL' if 'aDate' is None.

See also: formatValueForAttribute()

sqlStringForQualifier(self, aQualifier)

Returns the SQL WHERE clause string built from 'aQualifier' ; NB: the generated statement does not include the 'WHERE' SQL keyword.

Default implementation delegates the actual generation of the SQL string to the appropriate method [sqlStringFor...Qualifier()], depending on aQualifier's type/class.

Note that this method does not set the whereClauseString() ; it is the responsability for the caller to set it when appropriate.

See also: whereClauseString(),
sqlStringForKeyValueQualifier(), sqlStringForNegatedQualifier(), sqlStringForKeyComparisonQualifier(), sqlStringForDisjoinedQualifiers(), sqlStringForConjoinedQualifiers(), prepareInsertExpressionWithRow(), prepareSelectExpressionWithAttributes()

sqlStringForSchemaObjectName(self, name)

Unimplemented

sqlStringForSelector(self, selector, value)

Returns the appropriate SQL string corresponding to 'selector'

Parameters:

selector -- an operator of module Qualifier (QualifierOperatorEqual,
etc.)

value -- the right-value used with the operator

Depending on 'operator', the returned value is:

  • for 'QualifierOperatorEqual': '=' is 'value' is not None, 'IS' otherwise
  • for 'QualifierOperatorNotEqual': '<>' is 'value' is not None, 'IS NOT' otherwise
  • for 'QualifierOperatorGreaterThan': '>'
  • for 'QualifierOperatorGreaterThanOrEqualTo': '>='
  • for 'QualifierOperatorLessThan': '<'
  • for 'QualifierOperatorLessThanOrEqualTo': '<='
  • for 'QualifierOperatorLike': 'LIKE'

Raise 'ValueError' if 'selector' is not in that list. Note that 'QualifierOperatorCaseInsensitiveLike' is not in the list: this is intended. Specific transformations for this operator are handled by the specific methods sqlStringForKeyValueQualifier(), etc.

See also: sqlStringForKeyValueQualifier() and others related methods

sqlStringForString(self, aString)

Formats 'aString' and returns the string suitable for inclusion in a SQL statement. SQLExpression's implementation surrounds the string with simple quotes, and back-quotes any simple quotes 'aString' may have. It returns 'NULL' if 'aString' is None.

See also: formatValueForAttribute()

sqlStringForValue(self, value, keyPath)

Simply calls formatValueForAttribute() and return the formatted string

Implementation note: when SQL bind variable are supported this should update the bindings dictionary and return the name of the bind variable.

statement(self)

Returns the statement assigned to this object. The statement could have been set either with 'setStatement()' or by any of the following methods:

  • prepareDeleteExpressionForQualifier()
  • prepareInsertExpressionWithRow()
  • prepareSelectExpressionWithAttributes()
  • prepareUpdateExpressionWithRow()

toString(self)

Simply returns self.statement()

useAliases(self)

Returns whether the SQLExpression uses table aliases.

See also: setUseAliases()

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.

Returned value is a string, such as:

"12, 'Hugo', 'Victor', NULL"

See also: listString(), prepareInsertExpressionWithRow()

valueTypeForExternalType(self, externalTypeName)

Returns the value type corresponding to 'externalTypeName'.

The correspondance table is the following:

  • char, varchar: CharacterType
  • int, integer: NumericType
  • float, numeric: NumericType
  • date, time, timestamp: DateType

Returns None when no corresponding value type can be found.

Parameter:

externalTypeName -- a SQL datatype. It is lower-cased before
valueTypeForExternalTypeMapping() is asked for the corresponding value type.

See also: formatValueForAttribute(), valueTypeForExternalTypeMapping()

valueTypeForExternalTypeMapping(self)

Returns a dictionary consisting of the valid SQL types, each of which being a key bound to either 'BinaryType', 'CharacterType', 'DateType' or 'NumericType' (module's constants)

Important: the SQL types should be lower-cased

Default implementation returns:

{ 'char': CharacterType,
  'float': NumericType,
  'int': NumericType,
  'integer': NumericType,
  'numeric': NumericType,
  'date': DateType,
  'time': DateType,
  'timestamp': DateType,
  'varchar': CharacterType,
  }

See also: valueTypeForExternalType()

whereClauseString(self)

Returns the WHERE clause string generated for a given SQL statement.

This is set by: prepareInsertExpressionWithRow(), prepareSelectExpressionWithAttributes()

_addTableJoinsForAlias(self, alias, str)

Calculates the SQL statements for JOIN.

The default returns:

table0 alias0 INNER JOIN [ (some other nested join) | table1 alias1 ]
              ON (join condition)

except if self.SQL92_join is false: in this case, what is identified as the "join condition" here above is appended to self._joinClauseString (for use inside a WHERE clause), and the returned string is simply "table0 alias0, table1 alias1, ..."

Returns: (str, aliases): a string (see above) and the list of aliases that
were used to compute the string.

_prepareSelectExpressionWithAttributes(self, attributes, lock, fetchSpec, count=0)

Prepares the SELECT statement for prepareSelectCountExpressionWithAttributes() and prepareSelectExpressionWithAttributes().

Parameters:

attributes, lock, fetchSpec -- see prepareSelectExpressionWithAttributes

count -- integer '0' for prepareSelectExpressionWithAttributes(),
integer '1' for prepareSelectCountExpressionWithAttributes()

Class Variable Details

SQL92_join

Type:
int
Value:
1                                                                     

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