~ubuntu-branches/ubuntu/saucy/sope/saucy

« back to all changes in this revision

Viewing changes to sope-gdl1/Oracle8/EOAttribute+Oracle.m

  • Committer: Package Import Robot
  • Author(s): Jeroen Dekkers
  • Date: 2012-05-09 15:39:17 UTC
  • Revision ID: package-import@ubuntu.com-20120509153917-nr4jlm8mktma1yv3
Tags: upstream-1.3.14
ImportĀ upstreamĀ versionĀ 1.3.14

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
**  OracleEOAttribute.m
 
3
**
 
4
**  Copyright (c) 2007  Inverse groupe conseil inc. and Ludovic Marcotte
 
5
**
 
6
**  Author: Ludovic Marcotte <ludovic@inverse.ca>
 
7
**
 
8
**  This library is free software; you can redistribute it and/or
 
9
**  modify it under the terms of the GNU Lesser General Public
 
10
**  License as published by the Free Software Foundation; either
 
11
**  version 2.1 of the License, or (at your option) any later version.
 
12
**
 
13
**  This library is distributed in the hope that it will be useful,
 
14
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 
16
**  Lesser General Public License for more details.
 
17
**
 
18
**  You should have received a copy of the GNU Lesser General Public
 
19
**  License along with this library; if not, write to the Free Software
 
20
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
21
*/
 
22
 
 
23
#import "EOAttribute+Oracle.h"
 
24
 
 
25
@implementation EOAttribute (OracleExtensions)
 
26
 
 
27
+ (id) attributeWithOracleType: (ub2) theType
 
28
                          name: (text *) theName
 
29
                        length: (ub4) theLength
 
30
                         width: (ub4) theWidth
 
31
{
 
32
  EOAttribute *attr;
 
33
  NSString *s;
 
34
 
 
35
  attr = [[EOAttribute alloc] init];
 
36
  s = AUTORELEASE([[NSString alloc] initWithBytes: theName  length: theLength  encoding: NSASCIIStringEncoding]);
 
37
 
 
38
  // Oracle returns us the column names using uppercase strings.
 
39
  // We change that to avoid lameness in other parts of GDL.
 
40
  s = [s lowercaseString];
 
41
 
 
42
  [attr setName: s];
 
43
  [attr setColumnName: s];
 
44
  [attr setWidth: (unsigned)theWidth];
 
45
 
 
46
  switch (theType)
 
47
    {
 
48
    case SQLT_CHR:
 
49
      [attr setExternalType: @"VARCHAR2"];
 
50
      [attr setValueClassName: @"NSString"];
 
51
      break;
 
52
    case SQLT_CLOB:
 
53
      [attr setExternalType: @"CLOB"];
 
54
      [attr setValueClassName: @"NSString"];
 
55
      break;
 
56
    case SQLT_DAT:
 
57
      // char[7] that contains the date and time but no time zone information.
 
58
      [attr setExternalType: @"DATE"];
 
59
      [attr setValueClassName: @"NSDate"];
 
60
      break;
 
61
    case SQLT_INT:
 
62
      [attr setExternalType: @"INTEGER"];
 
63
      [attr setValueClassName: @"NSNumber"];
 
64
      [attr setValueType: @"d"];
 
65
      break;
 
66
    case SQLT_NUM:
 
67
      // char[22]
 
68
      [attr setExternalType: @"NUMBER"];
 
69
      [attr setValueClassName: @"NSNumber"];
 
70
      [attr setValueType: @"d"];
 
71
      break;
 
72
    case SQLT_STR:
 
73
      [attr setExternalType: @"STRING"];
 
74
      [attr setValueClassName: @"NSString"];
 
75
      break;
 
76
    case SQLT_TIMESTAMP:
 
77
      [attr setExternalType: @"TIMESTAMP"];
 
78
      [attr setValueClassName: @"NSCalendarDate"];
 
79
      break;
 
80
    case SQLT_TIMESTAMP_TZ:
 
81
      [attr setExternalType: @"TIMESTAMP WITH TIME ZONE"];
 
82
      [attr setValueClassName: @"NSCalendarDate"];
 
83
      break;
 
84
    case SQLT_TIMESTAMP_LTZ:
 
85
      [attr setExternalType: @"TIMESTAMP WITH LOCAL TIME ZONE"];
 
86
      [attr setValueClassName: @"NSCalendarDate"];
 
87
      break;
 
88
    default:
 
89
      NSLog(@"Unsupported type! %d\n", theType);
 
90
    }
 
91
 
 
92
  return AUTORELEASE(attr);
 
93
}
 
94
 
 
95
@end