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 NSDictionary *plist = _plist;
51 self->columnName = [[plist objectForKey:@"columnName"] copy];
52 self->sqlType = [[plist objectForKey:@"sqlType"] copy];
54 self->allowsNull = [[plist objectForKey:@"allowsNull"] boolValue];
55 self->isPrimaryKey = [[plist objectForKey:@"isPrimaryKey"] boolValue];
57 if (![self->columnName isNotNull] || ![self->sqlType isNotNull]) {
66 [self->columnName release];
67 [self->sqlType release];
73 - (NSString *)columnName {
74 return self->columnName;
76 - (NSString *)sqlType {
80 - (BOOL)doesAllowNull {
81 return self->allowsNull;
83 - (BOOL)isPrimaryKey {
84 return self->isPrimaryKey;
89 - (NSString *)sqlCreateSection {
92 ms = [NSMutableString stringWithCapacity:32];
93 [ms appendString:[self columnName]];
94 [ms appendString:@" "];
95 [ms appendString:[self sqlType]];
97 [ms appendString:@" "];
98 if (![self doesAllowNull]) [ms appendString:@"NOT "];
99 [ms appendString:@"NULL"];
101 if ([self isPrimaryKey]) [ms appendString:@" PRIMARY KEY"];
107 - (void)appendAttributesToDescription:(NSMutableString *)ms {
110 if ((tmp = [self columnName]) != nil) [ms appendFormat:@" column=%@", tmp];
111 if ((tmp = [self sqlType]) != nil) [ms appendFormat:@" sql=%@", tmp];
113 if ([self doesAllowNull]) [ms appendString:@" allows-null"];
114 if ([self isPrimaryKey]) [ms appendString:@" pkey"];
117 - (NSString *)description {
120 ms = [NSMutableString stringWithCapacity:256];
121 [ms appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])];
122 [self appendAttributesToDescription:ms];
123 [ms appendString:@">"];
127 @end /* GCSFieldInfo */