EOSQLExpression
Inherits from: NSObject
Package: com.apple.yellow.eoaccess
Class Description
EOSQLExpression is an abstract superclass that defines how to build SQL statements for adaptor channels. You don't typically use instances of EOSQLExpression; rather, you use EOSQLExpression subclasses written to work with a particular RDBMS and corresponding adaptor. A concrete subclass of EOSQLExpression overrides many of its methods in terms of the query language syntax for its specific RDBMS. EOSQLExpression objects are used internally by the Framework, and unless you're creating a concrete adaptor, you won't ordinarily need to interact with EOSQLExpression objects yourself. You most commonly create and use an EOSQLExpression object when you want to send an SQL statement directly to the server. In this case, you simply create an expression with the EOSQLExpression static method expressionForString, and send the expression object to an adaptor channel using EOAdaptorChannel's evaluateExpression method.
For more information on using EOSQLExpressions, see the following sections:
Constants
EOSQLExpression defines the following String constants.
Constant | Description |
BindVariableNameKey | The key for the name of a bind variable in a bind variable dictionary. |
BindVariablePlaceHolderKey | A key for use in bind variable dictionaries. The corresponding value is the placeholder string to be used in SQL. |
BindVariableAttributeKey | A key for use in bind variable dictionaries. The corresponding value is the attribute that uses the bind variable. |
BindVariableValueKey | A key for use in bind variable dictionaries. The corresponding value is the value for the bind variable. |
CreateTablesKey | Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to create tables. |
DropTablesKey | Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to drop tables. |
CreatePrimaryKeySupportKey | Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to create primary key support. |
DropPrimaryKeySupportKey | Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to drop primary key support. |
PrimaryKeyConstraintsKey | Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to create primary key constraints. |
ForeignKeyConstraintsKey | Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to create foreign key constraints. |
CreateDatabaseKey | Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to create a database. |
DropDatabaseKey | Key for use in options dictionaries. A corresponding value of "YES" indicates that the EOSQLExpression should generate SQL to drop a database. |
AllowsNullKey | Key for use in change dictionaries. A corresponding value indicates that the column's allows NULL value should be changed from. |
ColumnNameKey | Key for use in change dictionaries. A corresponding value indicates that the column's allows NULL value should be changed from. |
ExternalNameKey | Key for use in change dictionaries. A corresponding value indicates that the column's allows NULL value should be changed from. |
ExternalTypeKey | Key for use in change dictionaries. A corresponding value indicates that the column's allows NULL value should be changed from. |
NameKey | Key for use in change dictionaries. A corresponding value indicates the old value of the table or column. |
PrecisionKey | Key for use in change dictionaries. A corresponding value indicates the value a column's precision should be changed from. |
RelationshipsKey | Key for use in change dictionaries. The corresponding value is a dictionary of relationships which have been modified since the last time the model and schema were sychronized. For more information see "The Change Dictionary" . |
ScaleKey | Key for use in change dictionaries. A corresponding value indicates the value the column's scale should be changed from. |
WidthKey | Key for use in change dictionaries. A corresponding value indicates the value the column's width should be changed from. |
Method Types
- Constructors
- EOSQLExpression
- Creating an EOSQLExpression object
- selectStatementForAttributes
- insertStatementForRow
- updateStatementForRow
- deleteStatementWithQualifier
- expressionForString
- Building SQL Expressions
- prepareSelectExpressionWithAttributes
- prepareInsertExpressionWithRow
- prepareUpdateExpressionWithRow
- prepareDeleteExpressionForQualifier
- setStatement
- statement
- Generating SQL for attributes and values
- formatSQLString
- formatValueForAttribute
- formatStringValue
- sqlStringForValue
- sqlStringForAttributeNamed
- sqlStringForAttribute
- sqlStringForAttributePath
- sqlStringForNumber
- sqlStringForString
- Generating SQL for names of database objects
- sqlStringForSchemaObjectName
- setUseQuotedExternalNames
- useQuotedExternalNames
- externalNameQuoteCharacter
- Generating an attribute list
- addSelectListAttribute
- addInsertListAttribute
- addUpdateListAttribute
- appendItemToListString
- listString
- Generating a value list
- addInsertListAttribute
- addUpdateListAttribute
- valueList
- Generating a table list
- tableListWithRootEntity
- aliasesByRelationshipPath
- Generating the join clause
- joinExpression
- addJoinClause
- assembleJoinClause
- joinClauseString
- Generating a search pattern
- sqlPatternFromShellPattern
- sqlPatternFromShellPatternWithEscapeCharacter
- Generating a relational operator
- sqlStringForSelector
- Accessing the where clause
- whereClauseString
- Generating an order by clause
- addOrderByAttributeOrdering
- orderByString
- Accessing the lock clause
- lockClause
- Assembling a statement
- assembleSelectStatementWithAttributes
- assembleInsertStatementWithRow
- assembleUpdateStatementWithRow
- assembleDeleteStatementWithQualifier
- Generating SQL for qualifiers
- sqlStringForQualifier
- sqlStringForConjoinedQualifiers
- sqlStringForDisjoinedQualifiers
- sqlStringForKeyComparisonQualifier
- sqlStringForKeyValueQualifier
- sqlStringForNegatedQualifier
- Managing bind variables
- setUseBindVariables
- useBindVariables
- addBindVariableDictionary
- bindVariableDictionaries
- bindVariableDictionaryForAttribute
- mustUseBindVariableForAttribute
- shouldUseBindVariableForAttribute
- Using table aliases
- setUseAliases
- useAliases
- Accessing the entity
- entity
- Creating a schema generation script
- schemaCreationScriptForEntities
- schemaCreationStatementsForEntities
- appendExpression
- createTableStatementsForEntityGroup
- createTableStatementsForEntityGroups
- dropTableStatementsForEntityGroup
- dropTableStatementsForEntityGroups
- primaryKeyConstraintStatementsForEntityGroup
- primaryKeyConstraintStatementsForEntityGroups
- primaryKeySupportStatementsForEntityGroup
- primaryKeySupportStatementsForEntityGroups
- dropPrimaryKeySupportStatementsForEntityGroup
- dropPrimaryKeySupportStatementsForEntityGroups
- addCreateClauseForAttribute
- columnTypeStringForAttribute
- allowsNullClauseForConstraint
- foreignKeyConstraintStatementsForRelationship
- prepareConstraintStatementForRelationship
- createDatabaseStatementsForConnectionDictionary
- dropDatabaseStatementsForConnectionDictionary
- Synchronizing the database with a model
- statementsToUpdateObjectStoreForModel
- statementsToUpdateObjectStoreForEntityGroup
- statementsToCopyTableNamed
- phraseCastingColumnNamed
- statementsToRenameTableNamed
- statementsToInsertColumnForAttribute
- statementsToDeleteColumnNamed
- statementsToRenameColumnNamed
- statementsToModifyColumnNullRule
- statementsToConvertColumnType
- isColumnTypeEquivalentToColumnType
- statementsToDropForeignKeyConstraintsOnEntityGroup
- statementsToDropPrimaryKeyConstraintsOnEntityGroup
- statementsToDropPrimaryKeySupportForEntityGroup
- statementsToImplementForeignKeyConstraintsOnEntityGroup
- statementsToImplementPrimaryKeyConstraintsOnEntityGroup
- statementsToImplementPrimaryKeySupportForEntityGroup
- Querying about database synchronization support
- supportsSchemaSynchronization
- supportsDirectColumnCoercion
- supportsDirectColumnDeletion
- supportsDirectColumnInsertion
- supportsDirectColumnNullRuleModification
- supportsDirectColumnRenaming
Constructors
EOSQLExpression
public EOSQLExpression(EOEntity anEntity)
See Also: entity
Static Methods
appendExpression
public static void appendExpression(
EOSQLExpression anSQLExpression,
String script)
See Also: createTableStatementsForEntityGroup
createDatabaseStatementsForConnectionDictionary
public static NSArray createDatabaseStatementsForConnectionDictionary(
NSDictionary connectionDictionary,
NSDictionary adminDictionary)
See Also: dropDatabaseStatementsForConnectionDictionary
createTableStatementsForEntityGroup
public static NSArray createTableStatementsForEntityGroup(NSArray entityGroup)
EOSQLExpression's implementation does the following:
- Creates an EOSQLExpression object.
- Sets the expression's entity to the first entity in entityGroup.
- Adds a create clause for each Attribute in entityGroup's Entities.
- Sets the expression's statement to CREATE TABLE TABLE_NAME (LIST_STRING), where TABLE_NAME is the externalName of the Entity objects in entityGroup and LIST_STRING is the expression's listString.
- Adds the expression to an array.
- Returns the array.
The following is an example of a CREATE TABLE statement produced by the default implementation:
create table EMPLOYEE ( EMP_ID int not null, DEPT_ID int null, LAST_NAME varchar(40) not null, PHONE char(12) null, HIRE_DATE date null, SALARY number(7, 2) null )
If a subclass's database server's table creation semantics are different, the subclass should override this method or one or more of the following methods as appropriate:
See Also: createTableStatementsForEntityGroup, dropTableStatementsForEntityGroup
createTableStatementsForEntityGroups
public static NSArray createTableStatementsForEntityGroups(NSArray entityGroups)
See Also: schemaCreationStatementsForEntities
deleteStatementWithQualifier
public static EOSQLExpression deleteStatementWithQualifier(
com.apple.yellow.eocontrol.EOQualifier qualifier,
Object entity)
exception
if
qualifier is null.The expression created with this method
does not use table aliases because Enterprise Objects Framework
assumes that all INSERT, UPDATE, and DELETE statements are single-table
operations. As a result, all keys in qualifier should
be simple key names; no key paths are allowed. To generate DELETE
statements that do use table aliases, you must override prepareDeleteExpressionForQualifier to
send a setUseAliases(true)
message
prior to invoking
super
's
version.
dropDatabaseStatementsForConnectionDictionary
public static NSArray dropDatabaseStatementsForConnectionDictionary(
NSDictionary connectionDictionary,
NSDictionary adminDictionary)
See Also: createDatabaseStatementsForConnectionDictionary
dropPrimaryKeySupportStatementsForEntityGroup
public static NSArray dropPrimaryKeySupportStatementsForEntityGroup(NSArray entityGroup)
EOSQLExpression's implementation creates a statement of the following form:
drop sequence SEQUENCE_NAME
Where SEQUENCE_NAME is the primaryKeyRootName for the first entity in entityGroup concatenated with "_SEQ" (EMP_ID_SEQ, for example).
If a subclass uses a different primary key generation mechanism or if the subclass's database server's drop semantics are different, the subclass should override this method.
dropPrimaryKeySupportStatementsForEntityGroups
public static NSArray dropPrimaryKeySupportStatementsForEntityGroups(NSArray entityGroups)
See Also: schemaCreationStatementsForEntities
dropTableStatementsForEntityGroup
public static NSArray dropTableStatementsForEntityGroup(NSArray entityGroup)
EOSQLExpression's implementation creates a statement of the following form:
DROP TABLE TABLE_NAME
Where TABLE_NAME is the externalName of the first entity in entityGroup.
If a subclass's database server's drop semantics are different, the subclass should override this method.
dropTableStatementsForEntityGroups
public static NSArray dropTableStatementsForEntityGroups(NSArray entityGroups)
See Also: schemaCreationStatementsForEntities
expressionForString
public static EOSQLExpression expressionForString(String string)
See Also: setStatement
foreignKeyConstraintStatementsForRelationship
public static NSArray foreignKeyConstraintStatementsForRelationship(EORelationship aRelationship)
ALTER TABLE EMPLOYEE ADD CONSTRAINT TO_DEPARTMENT FOREIGN KEY (DEPT_ID) REFERENCES DEPARTMENT(DEPT_ID)
It returns an empty array if either of the following are true:
- aRelationship spans models (if aRelationship's destinationEntity is in a different model than aRelationship's source entity)
- aRelationship is a to-many relationship, or if the inverse relationship of aRelationship is not a to-many. In other words, foreign key constraint statements are only created for to-one relationships whose inverse is a to-many.
If neither of the above are true, this method creates a new EOSQLExpression, assigns its entity to aRelationship's entity, invokes prepareConstraintStatementForRelationship, and returns an array containing the expression.
If a subclass's database server's foreign key constraint semantics are different, the subclass should override this method or override the method prepareConstraintStatementForRelationship.
See Also: schemaCreationStatementsForEntities
formatSQLString
public static String formatSQLString(
String sqlString,
String format)
See Also: readFormat (EOAttribute), writeFormat (EOAttribute)
formatStringValue
public static String formatStringValue(String string)
if string is null.formatValueForAttribute
public static String formatValueForAttribute(
Object value,
EOAttribute attribute)
insertStatementForRow
public static EOSQLExpression insertStatementForRow(
NSDictionary row,
EOEntity entity)
if
entity is null.The expression created with this method does
not use table aliases because Enterprise Objects Framework assumes
that all INSERT, UPDATE, and DELETE statements are single-table
operations. To generate INSERT statements that do use table aliases,
you must override prepareInsertExpressionWithRow to
send a setUseAliases(true)
message
prior to invoking
super
's version.
isColumnTypeEquivalentToColumnType
public static boolean isColumnTypeEquivalentToColumnType(
EOSQLExpression.EOColumnTypes columnTypeA,
EOSQLExpression.EOColumnTypes columnTypeB,
NSDictionary options)
phraseCastingColumnNamed
public static String phraseCastingColumnNamed(
String columnName,
EOSQLExpression.EOColumnTypes fromType,
EOSQLExpression.EOColumnTypes castType
NSDictionary options)
primaryKeyConstraintStatementsForEntityGroup
public static NSArray primaryKeyConstraintStatementsForEntityGroup(NSArray entityGroup)
EOSQLExpression's implementation creates a statement of the following form:
ALTER TABLE TABLE_NAME ADD PRIMARY KEY (PRIMARY_KEY_COLUMN_NAMES)
Where TABLE_NAME is the externalName for the first entity in entityGroup and PRIMARY_KEY_COLUMN_NAMES is a comma-separated list of the columnNames of the first entity's primaryKeyAttributes.
If the subclass's database server's primary key constraint semantics are different, the subclass should override this method.
primaryKeyConstraintStatementsForEntityGroups
public static NSArray primaryKeyConstraintStatementsForEntityGroups(NSArray entityGroups)
primaryKeySupportStatementsForEntityGroup
public static NSArray primaryKeySupportStatementsForEntityGroup(NSArray entityGroup)
create sequence SEQUENCE_NAME
Where SEQUENCE_NAME is the primaryKeyRootName for the first entity in entityGroup concatenated with "_SEQ" (EMP_ID_SEQ, for example).
If a subclass uses a different primary key generation mechanism or if the subclass's database server's drop semantics are different, the subclass should override this method.
See Also: dropPrimaryKeySupportStatementsForEntityGroup, primaryKeyForNewRowWithEntity (EOAdaptorChannel)
primaryKeySupportStatementsForEntityGroups
public static NSArray primaryKeySupportStatementsForEntityGroups(NSArray entityGroups)
schemaCreationScriptForEntities
public static String schemaCreationScriptForEntities(
NSArray entities,
NSDictionary options)
schemaCreationStatementsForEntities
public static NSArray schemaCreationStatementsForEntities(
NSArray entities,
NSDictionary options)
EOSQLExpression's implementation uses the following methods:
- createTableStatementsForEntityGroups
- dropTableStatementsForEntityGroups
- primaryKeySupportStatementsForEntityGroups
- dropPrimaryKeySupportStatementsForEntityGroups
- primaryKeyConstraintStatementsForEntityGroups
- foreignKeyConstraintStatementsForRelationship
to generate EOSQLExpressions for the support identified in options.
See Also: schemaCreationScriptForEntities
selectStatementForAttributes
public static EOSQLExpression selectStatementForAttributes(
NSArray attributes,
boolean flag,
com.apple.yellow.eocontrol.EOFetchSpecification fetchSpecification,
EOEntity entity)
if
attributes is null or empty, fetchSpecification is null,
or entity is null.The expression
created with this method uses table aliases. To generate SELECT
statements that don't use them, you must override prepareSelectExpressionWithAttributes to
send a setUseAliases(false)
message
prior to invoking
super
's
version.
setUseBindVariables
public static void setUseBindVariables(boolean flag)
EOAdaptorUseBindVariables
is true,
though, instances do use them. For more information on bind variables,
see the discussion in the class description.See Also: useBindVariables
setUseQuotedExternalNames
public static void setUseQuotedExternalNames(boolean flag)
EOAdaptorQuotesExternalNames
is true,
though, instances do use quotes.See Also: useQuotedExternalNames, sqlStringForSchemaObjectName, externalNameQuoteCharacter
sqlPatternFromShellPattern
public static String sqlPatternFromShellPattern(String pattern)
EOQualifier.QualifierOperatorLike
.
EOSQLExpression's implementation performs the following substitutionsCharacter in pattern | Substitution string |
* | % |
? | _ |
% | [%] (unless the percent character appears in square brackets) |
_ | [_] (unless the underscore character appears in square brackets) |
See Also: sqlPatternFromShellPatternWithEscapeCharacter
sqlPatternFromShellPatternWithEscapeCharacter
public static String sqlPatternFromShellPatternWithEscapeCharacter(
String pattern,
char escapeCharacter)
statementsToConvertColumnType
public static NSArray statementsToConvertColumnType(
String columnName,
String tableName,
EOSQLExpression.EOColumnTypes type,
EOSQLExpression.EOColumnTypes newType,
NSDictionary options)
statementsToCopyTableNamed
public static NSArray statementsToCopyTableNamed(
String tableName,
NSArray entityGroup,
NSDictionary changes,
NSDictionary options)
The changes dictionary identifies the changes to make to the database schema; for more information, see "The Change Dictionary" . The options dictionary describes the aspects of the schema for which to create SQL statements; for more information, see "The Options Dictionary" .
statementsToDeleteColumnNamed
public static NSArray statementsToDeleteColumnNamed(
String columnName,
String tableName,
NSDictionary options)
statementsToDropForeignKeyConstraintsOnEntityGroup
public static NSArray statementsToDropForeignKeyConstraintsOnEntityGroup(
NSArray entityGroup,
NSDictionary changes,
NSDictionary options)
statementsToDropPrimaryKeyConstraintsOnEntityGroup
public static NSArray statementsToDropPrimaryKeyConstraintsOnEntityGroup(
NSArray entityGroup,
NSDictionary changes,
NSDictionary options)
statementsToDropPrimaryKeySupportForEntityGroup
public static NSArray statementsToDropPrimaryKeySupportForEntityGroup(
NSArray entityGroup,
NSDictionary changes,
NSDictionary options)
statementsToImplementForeignKeyConstraintsOnEntityGroup
public static NSArray statementsToImplementForeignKeyConstraintsOnEntityGroup(
NSArray entityGroup,
NSDictionary changes,
NSDictionary options)
statementsToImplementPrimaryKeyConstraintsOnEntityGroup
public static NSArray statementsToImplementPrimaryKeyConstraintsOnEntityGroup(
NSArray entityGroup,
NSDictionary changes,
NSDictionary options)
statementsToImplementPrimaryKeySupportForEntityGroup
public static NSArray statementsToImplementPrimaryKeySupportForEntityGroup(
NSArray entityGroup,
NSDictionary changes,
NSDictionary options)
statementsToInsertColumnForAttribute
public static NSArray statementsToInsertColumnForAttribute(
EOAttribute attribute,
NSDictionary options)
statementsToModifyColumnNullRule
public static NSArray statementsToModifyColumnNullRule(
String columnName,
String tableName,
boolean allowsNull,
NSDictionary options)
statementsToRenameColumnNamed
public static NSArray statementsToRenameColumnNamed(
String columnName,
String tableName,
String newName,
NSDictionary options)
statementsToRenameTableNamed
public static NSArray statementsToRenameTableNamed(
String tableName,
String newName,
NSDictionary options)
statementsToUpdateObjectStoreForEntityGroup
public static NSArray statementsToUpdateObjectStoreForEntityGroup(
NSArray entityGroup,
NSDictionary changes,
NSDictionary options)
statementsToUpdateObjectStoreForModel
public static NSArray statementsToUpdateObjectStoreForModel(
EOModel model,
NSDictionary changes,
NSDictionary options)
sqlStringForNumber
public static String sqlStringForNumber(Number aNumber)
sqlStringForString
public static String sqlStringForString(String aString)
supportsDirectColumnCoercion
public static boolean supportsDirectColumnCoercion()
supportsDirectColumnDeletion
public static boolean supportsDirectColumnDeletion()
supportsDirectColumnInsertion
public static boolean supportsDirectColumnInsertion()
supportsDirectColumnNullRuleModification
public static boolean supportsDirectColumnNullRuleModification()
supportsDirectColumnRenaming
public static boolean supportsDirectColumnRenaming()
supportsSchemaSynchronization
public static boolean supportsSchemaSynchronization()
updateStatementForRow
public static EOSQLExpression updateStatementForRow(
NSDictionary row,
com.apple.yellow.eocontrol.EOQualifier qualifier,
EOEntity entity)
The
expression created with this method does not use table aliases because
Enterprise Objects Framework assumes that all INSERT, UPDATE, and
DELETE statements are single-table operations. As a result, all
keys in qualifier should be simple
key names; no key paths are allowed. To generate UPDATE statements
that do use table aliases, you must override prepareUpdateExpressionWithRow to send
a setUseAliases(true)
message
prior to invoking
super
's
version.
See Also: setUseAliases
useBindVariables
public static boolean useBindVariables()
See Also: setUseBindVariables
useQuotedExternalNames
public static boolean useQuotedExternalNames()
See Also: setUseQuotedExternalNames, sqlStringForSchemaObjectName, externalNameQuoteCharacter
Instance Methods
addBindVariableDictionary
public void addBindVariableDictionary(NSMutableDictionary binding)
See Also: bindVariableDictionaries
addCreateClauseForAttribute
public void addCreateClauseForAttribute(EOAttribute attribute)
EOSQLExpression's implementation creates clauses in the following form:
COLUMN_NAME COLUMN_TYPE ALLOWS_NULL_CLAUSE
Where
- COLUMN_TYPE is the string returned from columnTypeStringForAttribute for anAttribute.
- ALLOWS_NULL_CLAUSE is the string returned from allowsNullClauseForConstraint with true if anAttribute allowsNull or with false if anAttribute doesn't.
addInsertListAttribute
public void addInsertListAttribute(
EOAttribute attribute,
String value)
Invokes appendItemToListString to add an SQL string for attribute to the receiver's listString, and again to add a formatted SQL string for value to the receiver's valueList.
See Also: sqlStringForAttribute, sqlStringForValue, formatValueForAttribute
addJoinClause
public void addJoinClause(
String leftName,
String rightName,
int semantic)
See Also: joinClauseString
addOrderByAttributeOrdering
public void addOrderByAttributeOrdering(com.apple.yellow.eocontrol.EOSortOrdering sortOrdering)
EOSortOrdering.CompareCaseInsensitiveAscending
or EOSortOrdering.CompareCaseInsensitiveAscending
,
the string generated has the format "upper(attribute) direction".
Use the method orderByString to
access the ORDER BY string. addOrderByAttributeOrdering invokes appendItemToListString to add the
attribute-direction pair.See Also: sqlStringForAttributeNamed
addSelectListAttribute
public void addSelectListAttribute(EOAttribute attribute)
See Also: sqlStringForAttribute, formatSQLString, readFormat (EOAttribute)
addUpdateListAttribute
public void addUpdateListAttribute(
EOAttribute attribute,
String value)
See Also: formatSQLString
aliasesByRelationshipPath
public NSMutableDictionary aliasesByRelationshipPath()
See Also: tableListWithRootEntity
allowsNullClauseForConstraint
public String allowsNullClauseForConstraint(boolean flag)
See Also: addCreateClauseForAttribute
appendItemToListString
public void appendItemToListString(
String itemString,
String listString)
assembleDeleteStatementWithQualifier
public String assembleDeleteStatementWithQualifier(
com.apple.yellow.eocontrol.EOQualifier qualifier,
String tableList,
String whereClause)
DELETE FROM tableList SQL_WHERE whereClause
qualifier is the argument to prepareDeleteExpressionForQualifier from which whereClause was derived. It is provided for subclasses that need to generate the WHERE clause in a particular way.
assembleInsertStatementWithRow
public String assembleInsertStatementWithRow(
NSDictionary row,
String tableList,
String columnList,
String valueList)
INSERT INTO tableList (columnList) VALUES valueList
or, if columnList is null:
INSERT INTO tableList VALUES valueList
row is the argument to prepareInsertExpressionWithRow from which columnList and valueList were derived. It is provided for subclasses that need to generate the list of columns and values in a particular way.
assembleJoinClause
public String assembleJoinClause(
String leftName,
String rightName,
int semantic)
leftName operator rightName
Where operator is "=" for an inner join, "*=" for a left-outer join, and "=*" for a right-outer join. Invoked from addJoinClause.
assembleSelectStatementWithAttributes
public String assembleSelectStatementWithAttributes(
NSArray attributes,
boolean lock,
com.apple.yellow.eocontrol.EOQualifier qualifier,
NSArray fetchOrder,
String selectString,
String columnList,
String tableList,
String whereClause,
String joinClause,
String orderByClause,
String lockClause)
SELECT columnList FROM tableList lockClause WHERE whereClause AND joinClause ORDER BY orderByClause
If lockClause is null, it is omitted from the statement. Similarly, if orderByClause is null, the "ORDER BY orderByClause" is omitted. If either whereClause or joinClause is null, the "AND" and null-valued argument are omitted. If both are null, the entire WHERE clause is omitted.
attributes, lock, qualifier, and fetchOrder are the arguments to prepareSelectExpressionWithAttributes from which the other assembleSelect... arguments were derived. They are provided for subclasses that need to generate the clauses of the SELECT statement in a particular way.
assembleUpdateStatementWithRow
public String assembleUpdateStatementWithRow(
NSDictionary row,
com.apple.yellow.eocontrol.EOQualifier qualifier,
String tableList,
String updateList,
String whereClause)
UPDATE tableList SET updateList WHERE whereClause
row and qualifier are the arguments to prepareUpdateExpressionWithRow from which updateList and whereClause were derived. They are provided for subclasses that need to generate the clauses of the UPDATE statement in a particular way.
bindVariableDictionaries
public NSArray bindVariableDictionaries()
See Also: addBindVariableDictionary
bindVariableDictionaryForAttribute
public NSMutableDictionary bindVariableDictionaryForAttribute(
EOAttribute attribute,
Object value)
Key | Corresponding Value |
BindVariableNameKey |
Name of the bind variable for attribute |
BindVariablePlaceHolderKey |
Placeholder string used in the SQL statement |
BindVariableAttributeKey |
attribute |
BindVariableValueKey |
value |
An adaptor subclass may define additional entries as required by its RDBMS.
Invoked from sqlStringForValue when the message mustUseBindVariableForAttribute(attribute) returns true or when the receiver's class uses bind variables and the message shouldUseBindVariableForAttribute(attribute) returns true. For more information on bind variables, see the discussion in the class description.
A subclass that uses bind variables should implement this method without invoking EOSQLExpression's implementation. The subclass implementation must return a dictionary with entries for the keys listed above and may add additional keys.
See Also: bindVariableDictionaryForAttribute, useBindVariables
columnTypeStringForAttribute
public String columnTypeStringForAttribute(EOAttribute anAttribute)
If Condition | Generated String |
precision is non-zero | externalType(precision, scale) |
precision is zero and width is non-zero | externalType(scale) |
precision and width are zero | externalType |
A subclass should override the default implementation if its database server requires column types in a different format.
See Also: addCreateClauseForAttribute
entity
public EOEntity entity()
See Also: EOSQLExpression constructor
externalNameQuoteCharacter
public String externalNameQuoteCharacter()
See Also: useQuotedExternalNames, sqlStringForSchemaObjectName
joinClauseString
public String joinClauseString()
An EOSQLExpression's joinClauseString is generally set by invoking joinExpression.
See Also: addJoinClause
joinExpression
public void joinExpression()
If the aliasesByRelationshipPath dictionary only has one entry (the entry for the EOSQLExpression's entity), the joinClauseString is empty.
You
must invoke this method after invoking addSelectListAttribute for each attribute
to be selected and after sending sqlStringForSQLExpression(this)
to
the qualifier for the SELECT statement. (These methods build up
the aliasesByRelationshipPath dictionary
by invoking sqlStringForAttributePath.)
See Also: whereClauseString
listString
public String listString()
Type of Statement | Sample listString Contents |
INSERT | FIRST_NAME, LAST_NAME, EMPLOYEE_ID |
UPDATE | FIRST_NAME = "Timothy", LAST_NAME = "Richardson" |
SELECT | t0.FIRST_NAME, t0.LAST_NAME, t1.DEPARTMENT_NAME |
lockClause
public String lockClause()
mustUseBindVariableForAttribute
public boolean mustUseBindVariableForAttribute(EOAttribute attribute)
See Also: shouldUseBindVariableForAttribute, bindVariableDictionaryForAttribute
orderByString
public String orderByString()
See Also: addOrderByAttributeOrdering
prepareConstraintStatementForRelationship
public void prepareConstraintStatementForRelationship(
EORelationship relationship,
NSArray sourceColumns,
NSArray destinationColumns)
ALTER TABLE TABLE_NAME ADD CONSTRAINT CONSTRAINT_NAME FOREIGN KEY (SOURCE_KEY_LIST) REFERENCES DESTINATION_TABLE_NAME (DESTINATION_KEY_LIST)
Where
- TABLE_NAME is the external name of the receiver's entity.
- CONSTRAINT_NAME is the external name of the receiver's entity, relationship's name, and the string "FK", concatenated with underbars between them (EMPLOYEE_MANAGER_FK, for example),
- SOURCE_KEY_LIST is a comma-separated list of the source columns in sourceColumns.
- DESTINATION_TABLE_NAME is the external name of relationship's destination entity.
- DESTINATION_KEY_LIST is a comma-separated list of the destination columns in destinationColumns
See Also: foreignKeyConstraintStatementsForRelationship
prepareDeleteExpressionForQualifier
public void prepareDeleteExpressionForQualifier(
com.apple.yellow.eocontrol.EOQualifier qualifier)
- Sends an sqlStringForSQLExpression
(this)
message to qualifier to generate the receiver's whereClauseString. - Invokes tableListWithRootEntity to get the table name for the FROM clause.
- Invokes assembleDeleteStatementWithQualifier.
See Also: deleteStatementWithQualifier
prepareInsertExpressionWithRow
public void prepareInsertExpressionWithRow(NSDictionary row)
- Invokes addInsertListAttribute for each entry in row to prepare the comma-separated list of attributes and the corresponding list of values.
- Invokes tableListWithRootEntity to get the table name.
- Invokes assembleInsertStatementWithRow.
See Also: insertStatementForRow
prepareSelectExpressionWithAttributes
public void prepareSelectExpressionWithAttributes(
NSArray attributes,
boolean flag,
com.apple.yellow.eocontrol.EOFetchSpecification fetchSpecification)
- Invokes addSelectListAttribute for each entry in attributes to prepare the comma-separated list of attributes.
- Sends an sqlStringForSQLExpression
(this)
message to fetchSpecification's qualifier to generate the receiver's whereClauseString. - Invokes addOrderByAttributeOrdering for each EOAttributeOrdering object in fetchSpecification. First conjoins the qualifier in fetchSpecification with the restricting qualifier, if any, of the receiver's entity.
- Invokes joinExpression to generate the receiver's joinClauseString.
- Invokes tableListWithRootEntity to get the comma-separated list of tables for the FROM clause.
- If flag is true, invokes lockClause to get the SQL string to lock selected rows.
- Invokes assembleSelectStatementWithAttributes.
See Also: selectStatementForAttributes
prepareUpdateExpressionWithRow
public void prepareUpdateExpressionWithRow(
NSDictionary row,
com.apple.yellow.eocontrol.EOQualifier qualifier)
- Invokes addUpdateListAttribute for each entry in row to prepare the comma-separated list of "attribute = value" assignments.
- Sends an sqlStringForSQLExpression
(this)
message to qualifier to generate the receiver's whereClauseString. - Invokes tableListWithRootEntity to get the table name for the FROM clause.
- Invokes assembleUpdateStatementWithRow.
See Also: updateStatementForRow
setStatement
public void setStatement(String string)
See Also: expressionForString, statement
setUseAliases
public void setUseAliases(boolean flag)
See Also: useAliases
shouldUseBindVariableForAttribute
public boolean shouldUseBindVariableForAttribute(EOAttribute attribute)
See Also: mustUseBindVariableForAttribute
sqlStringForAttribute
public String sqlStringForAttribute(EOAttribute attribute)
See Also: sqlStringForAttributePath
sqlStringForAttributeNamed
public String sqlStringForAttributeNamed(String name)
sqlStringForAttributePath
public String sqlStringForAttributePath(NSArray path)
- The EORelationship object in the receiver's entity named "department". (Assume the relationship's destination entity is named "Department".)
- The EORelationship object in the Department entity named "location". (Assume the relationship's destination entity is named "Location".)
- The EOAttribute object in the Location entity named "officeNumber".
Assuming that the receiver uses aliases and the alias for the Location table is t2, the SQL string for this sample attribute path is "t2.officeNumber".
If the receiver uses table aliases, this method has the side effect of adding a "relationship path"-"alias name" entry to the aliasesByRelationshipPath dictionary.
See Also: sqlStringForAttribute, aliasesByRelationshipPath
sqlStringForCaseInsensitiveLike
public String sqlStringForCaseInsensitiveLike(
String valueString,
String keyString)
sqlStringForConjoinedQualifiers
public String sqlStringForConjoinedQualifiers(NSArray qualifiers)
this
as
the argument. If the SQL string for a qualifier contains only white
space, it isn't included in the return value. The return value
is enclosed in parentheses if the SQL strings for two or more qualifiers
were ANDed together.sqlStringForDisjoinedQualifiers
public String sqlStringForDisjoinedQualifiers(NSArray qualifiers)
sqlStringForKeyComparisonQualifier
public String sqlStringForKeyComparisonQualifier(
com.apple.yellow.eocontrol.EOKeyComparisonQualifier qualifier)
sqlStringForKeyValueQualifier
public String sqlStringForKeyValueQualifier(
com.apple.yellow.eocontrol.EOKeyValueQualifier qualifier)
EOQualifier.QualifierOperatorLike
.)sqlStringForNegatedQualifier
public String sqlStringForNegatedQualifier(com.apple.yellow.eocontrol.EOQualifier qualifier)
Generates an SQL string for qualifier by sending an sqlStringForSQLExpression: message to qualifier with this as the argument. If the SQL string for qualifier contains only white space, this method returns null.
sqlStringForQualifier
public String sqlStringForQualifier(com.apple.yellow.eocontrol.EOQualifier aQualifier)
See Also: whereClauseString
sqlStringForSchemaObjectName
public String sqlStringForSchemaObjectName(String name)
See Also: useQuotedExternalNames, externalNameQuoteCharacter
sqlStringForSelector
public String sqlStringForSelector(
NSSelector selector,
Object value)
Selector (Constant) | SQL Operator |
EOQualifier.QualifierOperatorIsEqual |
"is" if value is an EONullValue, "=" otherwise |
EOQualifier.QualifierOperatorNotEqual |
"is not" if value is an EONullValue, "<>" otherwise |
EOQualifier.QualifierOperatorLessThan |
"<" |
EOQualifier.QualifierOperatorGreaterThan |
">" |
EOQualifier.QualifierOperatorLessThanOrEqualTo |
"<=" |
EOQualifier.QualifierOperatorGreaterThanOrEqualTo |
">=" |
EOQualifier.QualifierOperatorLike |
"like" |
Throws an exception if selector is an unknown operator.
See Also: sqlStringForKeyComparisonQualifier, sqlStringForKeyValueQualifier
sqlStringForValue
public String sqlStringForValue(
Object value,
String name)
See Also: mustUseBindVariableForAttribute, shouldUseBindVariableForAttribute, useBindVariables, bindVariableDictionaries, addBindVariableDictionary
statement
public String statement()
- prepareSelectExpressionWithAttributes
- prepareInsertExpressionWithRow
- prepareUpdateExpressionWithRow
- prepareDeleteExpressionForQualifier
tableListWithRootEntity
public String tableListWithRootEntity(EOEntity entity)
EMPLOYEE t0, DEPARTMENT t1
tableListWithRootEntity creates a string containing the table name for entity and a corresponding table alias ("EMPLOYEE t0", for example). For each entry in aliasesByRelationshipPath, this method appends a new table name and table alias.
See Also: useAliases, aliasesByRelationshipPath
useAliases
public boolean useAliases()
SELECT t0.FIRST_NAME, t0.LAST_NAME, t1.NAME FROM EMPLOYEE t0, DEPARTMENT t1 WHERE t0.DEPARTMENT_ID = t1.DEPARTMENT_ID
The EMPLOYEE table has the alias t0, and the DEPARTMENT table has the alias t1.
By default, EOSQLExpression uses table aliases only in SELECT statements. Enterprise Objects Framework assumes that INSERT, UPDATE, and DELETE statements are single-table operations. For more information, see the discussion in the class description.
See Also: setUseAliases, aliasesByRelationshipPath
valueList
public String valueList()
INSERT EMPLOYEE (FIRST_NAME, LAST_NAME, EMPLOYEE_ID, DEPARTMENT_ID, SALARY) VALUES ('Shaun', 'Hayes', 1319, 23, 4600)
is
"‘Shaun', ‘Hayes', 1319, 23, 4600". An EOSQLExpression's valueList
is
generated a value at a time with addInsertListAttribute messages.
whereClauseString
public String whereClauseString()
WHERE EMPLOYEE.SALARY > 4500 AND DEPARTMENT.NAME = ‘Finance' AND EMPLOYEE.DEPARTMENT_ID = DEPARTMENT.DEPARTMENT_ID
EOSQLExpression generates both a whereClauseString and a joinClauseString for this qualifier. The whereClauseString qualifies the rows and looks like this:
EMPLOYEE.SALARY > 4500 AND DEPARTMENT.NAME = ‘Finance'
The joinClauseString specifies the join conditions between the EMPLOYEE table and the DEPARTMENT table and looks like this:
EMPLOYEE.DEPARTMENT_ID = DEPARTMENT.DEPARTMENT_ID
An EOSQLExpression's whereClauseString is generally set by sending a sqlStringForSQLExpression: message to an EOQualifier object.
See Also: sqlStringForSQLExpression: (EOQualifierSQLGeneration protocol)