]> err.no Git - scalable-opengroupware.org/blob - OGoContentStore/OCSFieldInfo.m
bugfixes and performance upgrade for recurrent events
[scalable-opengroupware.org] / OGoContentStore / OCSFieldInfo.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$
22
23 #include "OCSFieldInfo.h"
24 #include "common.h"
25
26 @implementation OCSFieldInfo
27
28 + (NSArray *)fieldsForPropertyList:(NSArray *)_plist {
29   NSMutableArray *fields;
30   unsigned i, count;
31   
32   if (_plist == nil)
33     return nil;
34   
35   count = [_plist count];
36   fields = [NSMutableArray arrayWithCapacity:count];
37   for (i = 0; i < count; i++) {
38     OCSFieldInfo *field;
39
40     field = [[OCSFieldInfo alloc] initWithPropertyList:
41                                     [_plist objectAtIndex:i]];
42     if (field) [fields addObject:field];
43     [field release];
44   }
45   return fields;
46 }
47
48 - (id)initWithPropertyList:(id)_plist {
49   if ((self = [super init])) {
50   }
51   return self;
52 }
53
54 - (void)dealloc {
55   [self->columnName release];
56   [self->sqlType    release];
57   [super dealloc];
58 }
59
60 /* accessors */
61
62 - (NSString *)columnName {
63   return self->columnName;
64 }
65 - (NSString *)sqlType {
66   return self->sqlType;
67 }
68
69 - (BOOL)doesAllowNull {
70   return self->allowsNull;
71 }
72 - (BOOL)isPrimaryKey {
73   return self->isPrimaryKey;
74 }
75
76 /* generating SQL */
77
78 - (NSString *)sqlCreateSection {
79   NSMutableString *ms;
80   
81   ms = [NSMutableString stringWithCapacity:32];
82   [ms appendString:[self columnName]];
83   [ms appendString:@" "];
84   [ms appendString:[self sqlType]];
85   
86   [ms appendString:@" "];
87   if (![self doesAllowNull]) [ms appendString:@"NOT "];
88   [ms appendString:@"NULL"];
89   
90   if ([self isPrimaryKey]) [ms appendString:@" PRIMARY KEY"];
91   return ms;
92 }
93
94 /* description */
95
96 - (NSString *)description {
97   NSMutableString *ms;
98   id tmp;
99   
100   ms = [NSMutableString stringWithCapacity:256];
101   [ms appendFormat:@"<0x%08X[%@]:", self, NSStringFromClass([self class])];
102   
103   if ((tmp = [self columnName])) [ms appendFormat:@" column=%@", tmp];
104   if ((tmp = [self sqlType]))    [ms appendFormat:@" sql=%@",    tmp];
105   if ([self doesAllowNull]) [ms appendString:@" allows-null"];
106   if ([self isPrimaryKey])  [ms appendString:@" pkey"];
107   
108   [ms appendString:@">"];
109   return ms;
110 }
111
112 @end /* OCSFieldInfo */