2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "GCSFieldInfo.h"
25 @implementation GCSFieldInfo
27 + (NSArray *)fieldsForPropertyList:(NSArray *)_plist {
28 NSMutableArray *fields;
34 count = [_plist count];
35 fields = [NSMutableArray arrayWithCapacity:count];
36 for (i = 0; i < count; i++) {
39 field = [[GCSFieldInfo alloc] initWithPropertyList:
40 [_plist objectAtIndex:i]];
41 if (field != nil) [fields addObject:field];
47 - (id)initWithPropertyList:(id)_plist {
48 if ((self = [super init])) {
49 self->columnName = [[_plist objectForKey:@"columnName"] copy];
50 self->sqlType = [[_plist objectForKey:@"sqlType"] copy];
52 self->allowsNull = [[_plist objectForKey:@"allowsNull"] boolValue];
53 self->isPrimaryKey = [[_plist objectForKey:@"isPrimaryKey"] boolValue];
55 if (![self->columnName isNotNull] || ![self->sqlType isNotNull]) {
64 [self->columnName release];
65 [self->sqlType release];
71 - (NSString *)columnName {
72 return self->columnName;
74 - (NSString *)sqlType {
78 - (BOOL)doesAllowNull {
79 return self->allowsNull;
81 - (BOOL)isPrimaryKey {
82 return self->isPrimaryKey;
87 - (NSString *)sqlCreateSection {
90 ms = [NSMutableString stringWithCapacity:32];
91 [ms appendString:[self columnName]];
92 [ms appendString:@" "];
93 [ms appendString:[self sqlType]];
95 [ms appendString:@" "];
96 if (![self doesAllowNull]) [ms appendString:@"NOT "];
97 [ms appendString:@"NULL"];
99 if ([self isPrimaryKey]) [ms appendString:@" PRIMARY KEY"];
105 - (void)appendAttributesToDescription:(NSMutableString *)ms {
108 if ((tmp = [self columnName]) != nil) [ms appendFormat:@" column=%@", tmp];
109 if ((tmp = [self sqlType]) != nil) [ms appendFormat:@" sql=%@", tmp];
111 if ([self doesAllowNull]) [ms appendString:@" allows-null"];
112 if ([self isPrimaryKey]) [ms appendString:@" pkey"];
115 - (NSString *)description {
118 ms = [NSMutableString stringWithCapacity:256];
119 [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
120 [self appendAttributesToDescription:ms];
121 [ms appendString:@">"];
125 @end /* GCSFieldInfo */