/*
**  OracleValues.m
**
**  Copyright (c) 2007  Inverse groupe conseil inc. and Ludovic Marcotte
**
**  Author: Ludovic Marcotte <ludovic@inverse.ca>
**
**  This library 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.1 of the License, or (at your option) any later version.
**
**  This library 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 this library; if not, write to the Free Software
**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#include "OracleValues.h"

//
//
//
@implementation NSNumber (OracleExtensions)

- (NSString *) stringValueForOracleType: (ub2) theType
                              attribute: (EOAttribute *) theAttribute
{
#if GNUSTEP_BASE_LIBRARY
  /*
    on gstep-base -stringValue of bool's return YES or NO, which seems to
    be different on Cocoa and liBFoundation.
  */
  if (theType == SQLT_INT)
    {
      static Class BoolClass = Nil;
  
      if (BoolClass == Nil) BoolClass = NSClassFromString(@"NSBoolNumber");
      if ([self isKindOfClass: BoolClass])
        return [self boolValue] ? @"1" : @"0";
    }
#endif

  return [self stringValue];
}

@end

//
//
//
@implementation NSString (OracleExtensions)

- (NSString *) stringValueForOracleType: (ub2) theType
                              attribute: (EOAttribute *) theAttribute
{
  NSString *value;

  if (theType == SQLT_CHR || theType == SQLT_STR || theType == SQLT_CLOB || theType == SQLT_VCS || theType == SQLT_LVC)
    value = [NSString stringWithFormat: @"'%@'",
                      [self stringByReplacingString: @"'" withString: @"''"]];
  else
    value = self;

  return value;
}

@end
