/* * DB2BindParam object defines the needed conversion of bind parameters * Copyright (C) 2003 Johnathan Ingram, jingram@rogueware.org * * 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 US * */ #include "ibmDB2BindParam.h" #include "dbconnectTypes.h" // ----------------------------------------------------------------------------- // PRIVATE: // ----------------------------------------------------------------------------- // ----------------------------------------------------------------------------- // PUBLIC: // ----------------------------------------------------------------------------- //------------------------------------------------------------------------------ // DB2BindParam::getDB2CType //------------------------------------------------------------------------------ SQLSMALLINT DB2BindParam::getDB2CType() { SQLSMALLINT res; switch(type) { case BP_NULL: res = SQL_C_DEFAULT; break; case BP_STRING: res = SQL_C_CHAR; break; case BP_LONG: res = SQL_C_LONG; break; case BP_ULONG: res = SQL_C_ULONG; break; case BP_DOUBLE: res = SQL_C_DOUBLE; break; case BP_BOOLEAN: res = SQL_C_BIT; break; case BP_DATETIME: res = SQL_C_TIMESTAMP; break; case BP_DATE: res = SQL_C_DATE; break; case BP_TIME: res = SQL_C_TIME; break; case BP_BINARY: res = SQL_C_BINARY; break; case BP_UNKNOWN: default: throw BindParameterError("getDB2CType(): Unable to determine DB2 \"C\" bind parameter type for paramter value stored"); break; } return res; } // DB2BindParam::getDB2CType //------------------------------------------------------------------------------ // DB2BindParam::getDB2DataPointer //------------------------------------------------------------------------------ SQLPOINTER DB2BindParam::getDB2DataPointer() { SQLPOINTER res = NULL; // This will use the baseValue internals switch(type) { case BP_NULL: res = NULL; break; case BP_STRING: res = valuePtr.charPtr; break; case BP_LONG: // Make a local copy of the value as types are different. _db2LongInt = (long int)*(valuePtr.longPtr); res = &_db2LongInt; break; case BP_ULONG: // Make a local copy of the value as types are different. _db2ULongInt = (unsigned long int)*(valuePtr.unsignedLongPtr); res = &_db2ULongInt; break; case BP_DOUBLE: res = valuePtr.doublePtr; break; case BP_BOOLEAN: _db2Bool = (unsigned char)asBoolean(); res = &_db2Bool; break; case BP_DATETIME: // Make a local copy of the value as types are different. _db2TimeStamp.year = asDateTime().asComponent(JDate::YEARS); _db2TimeStamp.month = asDateTime().asComponent(JDate::MONTHS); _db2TimeStamp.day = asDateTime().asComponent(JDate::DAYS); _db2TimeStamp.hour = asDateTime().asComponent(JDate::HOURS); _db2TimeStamp.minute = asDateTime().asComponent(JDate::MINUTES); _db2TimeStamp.second = asDateTime().asComponent(JDate::SECONDS); _db2TimeStamp.fraction = 0; // TODO: Get JDate to support fraction of a second res = &_db2TimeStamp; break; case BP_DATE: // Make a local copy of the value as types are different. _db2Date.year = asDateTime().asComponent(JDate::YEARS); _db2Date.month = asDateTime().asComponent(JDate::MONTHS); _db2Date.day = asDateTime().asComponent(JDate::DAYS); res = &_db2Date; break; case BP_TIME: // Make a local copy of the value as types are different. _db2Time.hour = asDateTime().asComponent(JDate::HOURS); _db2Time.minute = asDateTime().asComponent(JDate::MINUTES); _db2Time.second = asDateTime().asComponent(JDate::SECONDS); res = &_db2Time; break; case BP_BINARY: res = (unsigned char*)valuePtr.ptr; break; case BP_UNKNOWN: default: throw BindParameterError("getDB2DataPointer(): Unable to create DB2 bind parameter data pointer"); break; } return res; } // DB2BindParam::getDB2DataPointer //------------------------------------------------------------------------------ // DB2BindParam::getDB2DataPointerLength //------------------------------------------------------------------------------ SQLINTEGER DB2BindParam::getDB2DataPointerLength() { // TODO: For OUTPUT Params this function will be required to change SQLINTEGER res = 0; switch(type) { case BP_STRING: case BP_BINARY: res = valueSize; break; case BP_UNKNOWN: throw BindParameterError("getDB2DataPointerLength(): Unable to determine DB2 bind parameter data length"); break; default: res = 0; break; } return res; } // DB2BindParam::getDB2DataPointerLength //------------------------------------------------------------------------------ // DB2BindParam::getDB2StrLenIndPtr //------------------------------------------------------------------------------ SQLINTEGER* DB2BindParam::getDB2StrLenIndPtr() { _strlenIndPtr = 0; switch(type) { case BP_NULL: _strlenIndPtr = SQL_NULL_DATA; break; case BP_STRING: _strlenIndPtr = SQL_NTS; break; case BP_BINARY: _strlenIndPtr = valueSize; break; case BP_UNKNOWN: throw BindParameterError("getDB2StrLenIndPtr(): Unable to determine DB2 bind parameter Str Len/Ind Ptr"); break; default: _strlenIndPtr = 0; break; } if (_strlenIndPtr == 0) return NULL; else return &_strlenIndPtr; } // DB2BindParam::getDB2StrLenIndPtr