home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / EODEV.Z / EOSQLQualifier.h < prev    next >
Encoding:
Text File  |  1996-09-09  |  6.2 KB  |  154 lines

  1. // EOSQLQualifier.h
  2. // Copyright (c) 1994, NeXT Software, Inc. All rights reserved.
  3.  
  4. #import <EOControl/EOControl.h>
  5.  
  6. @class EOExpressionArray;
  7. @class EOSQLExpression;
  8. @class EOEntity;
  9. @class EOModel;
  10.  
  11.  
  12. //
  13. // This file contains the declarations needed for EOSQLQualifier as well as the
  14. // access layer specific categories of EOQualifier.
  15. //
  16. // EOSQLQualifier contains unstructured text that can be transformed into a SQL
  17. // expression. EOSQLQualifier is provided for backwards compatibility with EOF 1.x
  18. // products and to provide a way that programmers can create SQL expressions with any
  19. // arbitrary SQL. In general, programmers should use EOQualifier whenever possible and
  20. // use EOSQLQualifier only in cases that absolutely require it.
  21. //
  22.  
  23.  
  24. // All qualifiers that can be used to generate SQL queries implement this protocol
  25. @protocol EOQualifierSQLGeneration
  26. - (NSString *)sqlStringForSQLExpression:(EOSQLExpression *)sqlExpression;
  27. - (EOQualifier *)schemaBasedQualifierWithRootEntity:(EOEntity *)entity;
  28.     // Returns an equivalent qualifier with object references replaced by foreign
  29.     // key references.
  30. @end
  31.  
  32.  
  33. // An EOSQLQualifier holds qualifications expressed in the target query language
  34. // and rooted in a single EOEntity. EOSQLQualifier formats differ from EOQualifier
  35. // formats. EOSQLQualifier formats are not parsed, they are simply scanned for
  36. // keys and format characters. EOSQLQualifiers should be used only when you want
  37. // to use a query available in the database query language that cannot be expressed
  38. // using the EOQualifier formats.
  39. //
  40. // EOSQLQualifiers cannot be applied to objects in memory.
  41. //
  42. // CREATING A SQL QUALIFIER FROM A FORMAT STRING
  43. //
  44. // An EOSQLQualifier format may contain keys(attribute names), key paths
  45. // (attributes referenced through a relationship, format characters
  46. // (e.g. %@, %s, etc), and arbitrary text. The format is scanned by the
  47. // EOSQLQualifier class and the keys, key paths, and format characters.
  48. // The keys and key paths are substituted with the appropriate column
  49. // names and the format characters are replaced by the argument
  50. // indicated by the format characters. All SQL syntax is the
  51. // responsibility of the coder. EOSQLQualifier does not attempt to
  52. // understand the contents of the format string.
  53.  
  54. // The following are examples of simple EOSQLQualifier format strings.
  55. // In these examples, the keys "lastName" and "royalty" will be replaced
  56. // with the appropriately aliased column names as will the key path
  57. // "publisher.name". 
  58. //     lastName = "smith"
  59. //     royalty > 2.5
  60. //     toPublisher.name = "Eco Publishing House"
  61. //
  62. // An EOSQLQualifier's format string recognizes the following format characters.
  63. //
  64. //    %s expects a (char *) argument
  65. //    %A expects an (NSString *) argument, which should be a key or key path
  66. //    %d expects an integer argument
  67. //    %f expects a float or double argument
  68. //    %@ expects an id argument -- valid objects are EOAttribute,
  69. //         NSString, or anything that responds reasonably to:
  70. //       valueForSQLExpression:(EOSQLExpression *)context
  71. //    %% is a '%' passed through.
  72. //    % followed by any other character is ignored
  73. //
  74.  
  75. // The following examples build qualifiers similar to the above examples but
  76. // use format characters to build the values from a existing EO. In these
  77. // examples, we assume that the EO has implemented the following accessor methods:
  78. //    - (NSString *)lastName;
  79. //    - (float)salary;
  80. //
  81. //     myQualifier = [[EOSQLQualifier alloc] initWithEntity:authorEntity
  82. //         qualifierFormat:"%A = '%@'", @"last_name", [anAuthur lastName]];
  83. //
  84. //     myQualifier = [[EOSQLQualifier alloc] initWithEntity:authorEntity
  85. //         qualifierFormat:"%A > %f", @"royalty", [anAuthur salary]];
  86. //
  87. // Since it is the responsibility of the programmer to ensure that all formatting
  88. // is correct in the resulting SQL statement, it is sometimes useful to use a
  89. // particular adaptor for doing certain formatting tasks like quoting strings,
  90. // formatting dates, etc.
  91. //
  92. // The next example calls the method formatValue:forAttribute: on the adaptor
  93. // specific subclass of EOSQLExpression to ensure that certain values are
  94. // formatted correctly. In this case, since the attribute is a string type,
  95. // the method will return a quoted copy of the with any embedded quotes suitably
  96. // escaped.
  97. //     myQualifier = [[EOSQLQualifier alloc] initWithEntity:authorEntity
  98. //         qualifierFormat:"%A = %@", [attribute name],
  99. //       [[adaptor expressionClass] formatValue:[anAuthor lastName]
  100. //        forAttribute:attribute]];
  101.  
  102.  
  103. //
  104. // This category is access layer specific since it uses information contained in an EOModel
  105. //
  106. @interface EOQualifier (EOModelExtensions)
  107. - (EOQualifier *)qualifierMigratedFromEntity:(EOEntity *)entity relationshipPath:(NSString *)relationshipPath;
  108.     // Create a new qualifier by moving the qualifier from the source entity to
  109.     // the destination of the relationship path. This method a returns a copy
  110.     // the reciever with all of the keys translated to work with the specified
  111.     // relationshipPath.
  112. @end
  113.  
  114.  
  115. //
  116. // All of the EOF supplied qualifiers conform to the EOQualifierSQLGeneration
  117. // protocol, so we declare that here.
  118. //
  119. @interface EOAndQualifier (EOQualifierSQLGeneration) <EOQualifierSQLGeneration>
  120. @end
  121. @interface EOOrQualifier (EOQualifierSQLGeneration) <EOQualifierSQLGeneration>
  122. @end
  123. @interface EOKeyComparisonQualifier (EOQualifierSQLGeneration) <EOQualifierSQLGeneration>
  124. @end
  125. @interface EOKeyValueQualifier (EOQualifierSQLGeneration) <EOQualifierSQLGeneration>
  126. @end
  127. @interface EONotQualifier (EOQualifierSQLGeneration) <EOQualifierSQLGeneration>
  128. @end
  129.  
  130.  
  131. //
  132. // Finally, declare the EOSQLQualifier class.
  133. //
  134. @interface EOSQLQualifier : EOQualifier <EOQualifierSQLGeneration> {
  135.     EOEntity *_entity;
  136.     EOExpressionArray *_contents;
  137.     struct {
  138.     unsigned int usesDistinct:1;
  139.     unsigned int _RESERVED:31;
  140.     } _flags;
  141. }
  142.  
  143. + (EOQualifier *)qualifierWithQualifierFormat:(NSString *)format, ...;
  144.     // This method overrides the superclass method and always raises an exception.
  145.     // EOSQLQualifier must be initialized with an entity and this method does not
  146.     // provide one. Creators of EOSQLQualifier should invoke the
  147.     // initWithEntity:qualifierFormat: method.
  148.  
  149. - initWithEntity:(EOEntity *)entity qualifierFormat:(NSString *)qualifierFormat, ...;
  150.     // This is the designated initializer for EOSQLQualifier.
  151.  
  152. @end
  153.  
  154.