/* Copyright (C) 2004 SKYRIX Software AG This file is part of OpenGroupware.org. OGo is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. OGo is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with OGo; see the file COPYING. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ // $Id$ #include "OCSFieldInfo.h" #include "common.h" @implementation OCSFieldInfo + (NSArray *)fieldsForPropertyList:(NSArray *)_plist { NSMutableArray *fields; unsigned i, count; if (_plist == nil) return nil; count = [_plist count]; fields = [NSMutableArray arrayWithCapacity:count]; for (i = 0; i < count; i++) { OCSFieldInfo *field; field = [[OCSFieldInfo alloc] initWithPropertyList: [_plist objectAtIndex:i]]; if (field) [fields addObject:field]; [field release]; } return fields; } - (id)initWithPropertyList:(id)_plist { if ((self = [super init])) { } return self; } - (void)dealloc { [self->columnName release]; [self->sqlType release]; [super dealloc]; } /* accessors */ - (NSString *)columnName { return self->columnName; } - (NSString *)sqlType { return self->sqlType; } - (BOOL)doesAllowNull { return self->allowsNull; } - (BOOL)isPrimaryKey { return self->isPrimaryKey; } /* generating SQL */ - (NSString *)sqlCreateSection { NSMutableString *ms; ms = [NSMutableString stringWithCapacity:32]; [ms appendString:[self columnName]]; [ms appendString:@" "]; [ms appendString:[self sqlType]]; [ms appendString:@" "]; if (![self doesAllowNull]) [ms appendString:@"NOT "]; [ms appendString:@"NULL"]; if ([self isPrimaryKey]) [ms appendString:@" PRIMARY KEY"]; return ms; } /* description */ - (NSString *)description { NSMutableString *ms; id tmp; ms = [NSMutableString stringWithCapacity:256]; [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])]; if ((tmp = [self columnName])) [ms appendFormat:@" column=%@", tmp]; if ((tmp = [self sqlType])) [ms appendFormat:@" sql=%@", tmp]; if ([self doesAllowNull]) [ms appendString:@" allows-null"]; if ([self isPrimaryKey]) [ms appendString:@" pkey"]; [ms appendString:@">"]; return ms; } @end /* OCSFieldInfo */