home *** CD-ROM | disk | FTP | other *** search
/ OpenStep (Enterprise) / OpenStepENTCD.toast / OEDEV / EODEV.Z / FlatFileSQLExpression.m < prev    next >
Encoding:
Text File  |  1996-08-23  |  3.0 KB  |  91 lines

  1. /*
  2.         Copyright (c) 1996, NeXT Software, Inc.
  3.         All rights reserved.
  4.  
  5.         You may freely copy, distribute and reuse the code in this example.
  6.         NeXT disclaims any warranty of any kind, expressed or implied,
  7.         as to its fitness for any particular use.
  8. */
  9.  
  10. #import "FlatFileAdaptor.h"
  11. #import "FlatFileSQLExpression.h"
  12.  
  13. @interface FlatFileSQLExpression (FlatFileSQLExpressionPrivate)
  14.  
  15. + (NSString *)newHeaderForAttribute:(EOAttribute *)attribute;
  16.  
  17. @end
  18.  
  19. @implementation FlatFileSQLExpression
  20.  
  21. + (NSArray *)createTableStatementsForEntityGroup:(NSArray *)entityGroup {
  22.     NSEnumerator *attributeEnumerator, *entityEnumerator = [entityGroup objectEnumerator];
  23.     NSMutableSet *columnNames = [NSMutableSet set];
  24.     NSMutableString *listString = nil;
  25.     NSString *columnName, *tableName = nil;
  26.     EOEntity *entity;
  27.     EOAttribute *attribute;
  28.     FlatFileSQLExpression *expression = nil;
  29.     
  30.     while (entity = [entityEnumerator nextObject]) {
  31.         attributeEnumerator = [[entity attributes] objectEnumerator];
  32.         while (attribute = [attributeEnumerator nextObject]) {
  33.             columnName = [attribute columnName];
  34.             if (columnName) {
  35.                 if (![columnNames containsObject:columnName]) {
  36.                     if (!expression) {
  37.                         expression = [[[self alloc] initWithEntity:entity] autorelease];
  38.                         listString = [expression listString];
  39.                         tableName =  [entity externalName];
  40.                     }
  41.                     [expression appendItem:[self newHeaderForAttribute:attribute] toListString:listString];
  42.                     [columnNames addObject:columnName];
  43.                 }
  44.             }
  45.         }
  46.     }
  47.  
  48.     [expression setStatement:[NSString stringWithFormat:@"create %@ %@", tableName, listString]];
  49.     return [NSArray arrayWithObject:expression];
  50. }
  51.  
  52. + (NSArray *)dropTableStatementsForEntityGroup:(NSArray *)entityGroup {
  53.     EOEntity *entity;
  54.     FlatFileSQLExpression *expression = nil;
  55.  
  56.     if ([entityGroup count]) {
  57.         entity = [entityGroup lastObject];
  58.         expression = [[[self alloc] initWithEntity:entity] autorelease];
  59.         [expression setStatement:[NSString stringWithFormat:@"drop %@", [entity externalName]]];
  60.     }
  61.  
  62.     return [NSArray arrayWithObject:expression];
  63. }
  64.  
  65. + (NSArray *)primaryKeyConstraintStatementsForEntityGroup:(NSArray *)entityGroup {
  66.     return nil;
  67. }
  68.  
  69. + (NSArray *)primaryKeySupportStatementsForEntityGroup:(NSArray *)entityGroup {
  70.     return nil;
  71. }
  72.  
  73. + (NSArray *)foreignKeyConstraintStatementsForEntityGroup:(NSArray *)entityGroup {
  74.     return nil;
  75. }
  76.  
  77. + (NSString *)newHeaderForAttribute:(EOAttribute *)attribute {
  78.     return [NSString stringWithFormat:@"%@%@%@", [attribute columnName], [FlatFileAdaptor columnHeaderSeparator], [attribute externalType]];
  79. }
  80.  
  81. + (NSArray *)dropPrimaryKeySupportStatementsForEntityGroup:(NSArray *)entityGroup {
  82.     return nil;
  83. }
  84.  
  85. + (NSArray *)foreignKeyConstraintStatementsForRelationship:(EORelationship *)relationship {
  86.     return nil;
  87. }
  88.  
  89.  
  90. @end
  91.