CREATING A SQL QUALIFIER FROM A FORMAT STRING An EOSQLQualifier format may contain keys(attribute names), key paths (attributes referenced through a relationship, format characters (for example %@, %s, etc), and arbitrary text. The format is scanned by the EOSQLQualifier class and the keys, key paths, and format characters. The keys and key paths are substituted with the appropriate column names and the format characters are replaced by the argument indicated by the format characters. All SQL syntax is the responsibility of the coder. EOSQLQualifier does not attempt to understand the contents of the format string.

The following are examples of simple EOSQLQualifier format strings. In these examples, the keys "lastName" and "royalty" will be replaced with the appropriately aliased column names as will the key path "publisher.name".

      lastName = "smith"
      royalty > 2.5
      toPublisher.name = "Eco Publishing House"
  
An EOSQLQualifier's format string recognizes the following format characters.

%s expects a (char ) argument
%A expects an (NSString ) argument, which should be a key or key path
%d expects an integer argument
%f expects a float or double argument
%@ expects an id argument -- valid objects are EOAttribute,
NSString, or anything that responds reasonably to:
valueForSQLExpression:(EOSQLExpression )context
%% is a '%' passed through.
% followed by any other character is ignored

The following examples build qualifiers similar to the above examples but you should use format characters to build the values from a existing EO. In these examples, we assume that the EO has implemented the following accessor methods:
- (NSString )lastName;
- (float)salary;

      myQualifier = [[EOSQLQualifier alloc] initWithEntity:authorEntity
          qualifierFormat:"%A = '%@'", @"last_name", [anAuthur lastName]];
 
      myQualifier = [[EOSQLQualifier alloc] initWithEntity:authorEntity
          qualifierFormat:"%A > %f", @"royalty", [anAuthur salary]];
 

Since it is the responsibility of the programmer to ensure that all formatting is correct in the resulting SQL statement, it is sometimes useful to use a particular adaptor for doing certain formatting tasks like quoting strings, formatting dates, etc.

The next example calls the method formatValue:forAttribute: on the adaptor specific subclass of EOSQLExpression to ensure that certain values are formatted correctly. In this case, since the attribute is a string type, the method will return a quoted copy of the string with any embedded quotes suitably escaped.

      myQualifier = [[EOSQLQualifier alloc] initWithEntity:authorEntity
          qualifierFormat:"%A = %@", [attribute name],
     [[adaptor expressionClass] formatValue:[anAuthor lastName]
   forAttribute:attribute]];
  

Finally, declare the EOSQLQualifier class.