bool CDBL_BCPInCmd::x_AssignParams(void* pb) { RETCODE r; if (!m_WasBound) { for (unsigned int i = 0; i < GetBindParamsImpl().NofParams(); i++) { if (GetBindParamsImpl().GetParamStatus(i) == 0) continue; CDB_Object& param = *GetBindParamsImpl().GetParam(i); switch ( param.GetType() ) { case eDB_Bit: DATABASE_DRIVER_ERROR("Bit data type is not supported", 10005); break; case eDB_Int: { CDB_Int& val = dynamic_cast<CDB_Int&> (param); // DBINT v = (DBINT) val.Value(); r = Check(bcp_bind(GetCmd(), (BYTE*) val.BindVal(), 0, val.IsNULL() ? 0 : -1, 0, 0, SYBINT4, i + 1)); } break; case eDB_SmallInt: { CDB_SmallInt& val = dynamic_cast<CDB_SmallInt&> (param); // DBSMALLINT v = (DBSMALLINT) val.Value(); r = Check(bcp_bind(GetCmd(), (BYTE*) val.BindVal(), 0, val.IsNULL() ? 0 : -1, 0, 0, SYBINT2, i + 1)); } break; case eDB_TinyInt: { CDB_TinyInt& val = dynamic_cast<CDB_TinyInt&> (param); // DBTINYINT v = (DBTINYINT) val.Value(); r = Check(bcp_bind(GetCmd(), (BYTE*) val.BindVal(), 0, val.IsNULL() ? 0 : -1, 0, 0, SYBINT1, i + 1)); } break; case eDB_BigInt: { CDB_BigInt& val = dynamic_cast<CDB_BigInt&> (param); DBNUMERIC* v = reinterpret_cast<DBNUMERIC*> (pb); Int8 v8 = val.Value(); v->precision= 18; v->scale= 0; if (longlong_to_numeric(v8, 18, DBNUMERIC_val(v)) == 0) return false; r = Check(bcp_bind(GetCmd(), (BYTE*) v, 0, val.IsNULL() ? 0 : -1, 0, 0, SYBNUMERIC, i + 1)); pb = (void*) (v + 1); } break; case eDB_Char: { CDB_Char& val = dynamic_cast<CDB_Char&> (param); if (val.IsNULL()) { r = Check(bcp_bind(GetCmd(), (BYTE*) "", 0, 0, NULL, 0, SYBCHAR, i + 1)); } else { // r = Check(bcp_bind(GetCmd(), (BYTE*) val.Data(), 0, // val.Size(), NULL, 0, SYBCHAR, i + 1)); r = Check(bcp_bind(GetCmd(), (BYTE*) val.AsCString(), 0, -1, (BYTE*) "", 1, SYBCHAR, i + 1)); } } break; case eDB_VarChar: { CDB_VarChar& val = dynamic_cast<CDB_VarChar&> (param); if (val.IsNULL()) { r = Check(bcp_bind(GetCmd(), (BYTE*) "", 0, 0, NULL, 0, SYBVARCHAR, i + 1)); } else { r = Check(bcp_bind(GetCmd(), (BYTE*) val.AsCString(), 0, -1, (BYTE*) "", 1, SYBVARCHAR, i + 1)); } } break; case eDB_LongChar: { CDB_LongChar& val = dynamic_cast<CDB_LongChar&> (param); if (val.IsNULL()) { r = Check(bcp_bind(GetCmd(), (BYTE*) "", 0, 0, NULL, 0, SYBCHAR, i + 1)); } else { r = Check(bcp_bind(GetCmd(), (BYTE*) val.AsCString(), 0, -1, (BYTE*) "", 1, SYBCHAR, i + 1)); } } break; case eDB_Binary: { CDB_Binary& val = dynamic_cast<CDB_Binary&> (param); r = Check(bcp_bind(GetCmd(), (BYTE*) val.Value(), 0, val.IsNULL() ? 0 : (DBINT) val.Size(), 0, 0, SYBBINARY, i + 1)); } break; case eDB_VarBinary: { CDB_VarBinary& val = dynamic_cast<CDB_VarBinary&> (param); r = Check(bcp_bind(GetCmd(), (BYTE*) val.Value(), 0, val.IsNULL() ? 0 : (DBINT) val.Size(), 0, 0, SYBBINARY, i + 1)); } break; case eDB_LongBinary: { CDB_LongBinary& val = dynamic_cast<CDB_LongBinary&> (param); r = Check(bcp_bind(GetCmd(), (BYTE*) val.Value(), 0, val.IsNULL() ? 0 : val.DataSize(), 0, 0, SYBBINARY, i + 1)); } break; case eDB_Float: { CDB_Float& val = dynamic_cast<CDB_Float&> (param); // DBREAL v = (DBREAL) val.Value(); r = Check(bcp_bind(GetCmd(), (BYTE*) val.BindVal(), 0, val.IsNULL() ? 0 : -1, 0, 0, SYBREAL, i + 1)); } break; case eDB_Double: { CDB_Double& val = dynamic_cast<CDB_Double&> (param); // DBFLT8 v = (DBFLT8) val.Value(); r = Check(bcp_bind(GetCmd(), (BYTE*) val.BindVal(), 0, val.IsNULL() ? 0 : -1, 0, 0, SYBFLT8, i + 1)); } break; case eDB_SmallDateTime: { CDB_SmallDateTime& val = dynamic_cast<CDB_SmallDateTime&> (param); DBDATETIME4* dt = (DBDATETIME4*) pb; if (param.IsNULL()) { DBDATETIME4_days(dt) = 0; DBDATETIME4_mins(dt) = 0; } else { DBDATETIME4_days(dt) = val.GetDays(); DBDATETIME4_mins(dt) = val.GetMinutes(); } r = Check(bcp_bind(GetCmd(), (BYTE*) dt, 0, val.IsNULL() ? 0 : -1, 0, 0, SYBDATETIME4, i + 1)); pb = (void*) (dt + 1); } break; case eDB_DateTime: { CDB_DateTime& val = dynamic_cast<CDB_DateTime&> (param); DBDATETIME* dt = (DBDATETIME*) pb; if (param.IsNULL()) { dt->dtdays = 0; dt->dttime = 0; } else { dt->dtdays = val.GetDays(); dt->dttime = val.Get300Secs(); } r = Check(bcp_bind(GetCmd(), (BYTE*) dt, 0, val.IsNULL() ? 0 : -1, 0, 0, SYBDATETIME, i + 1)); pb = (void*) (dt + 1); } break; case eDB_Text: { CDB_Text& val = dynamic_cast<CDB_Text&> (param); r = Check(bcp_bind(GetCmd(), 0, 0, val.IsNULL() ? 0 : (DBINT) val.Size(), 0, 0, SYBTEXT, i + 1)); m_HasTextImage = true; } break; case eDB_Image: { CDB_Image& val = dynamic_cast<CDB_Image&> (param); r = Check(bcp_bind(GetCmd(), 0, 0, val.IsNULL() ? 0 : (DBINT) val.Size(), 0, 0, SYBIMAGE, i + 1)); m_HasTextImage = true; } break; default: return false; } if (r != CS_SUCCEED) return false; } GetBindParamsImpl().LockBinding(); m_WasBound = true; } else { for (unsigned int i = 0; i < GetBindParamsImpl().NofParams(); i++) { if (GetBindParamsImpl().GetParamStatus(i) == 0) continue; CDB_Object& param = *GetBindParamsImpl().GetParam(i); switch ( param.GetType() ) { case eDB_Int: { CDB_Int& val = dynamic_cast<CDB_Int&> (param); // DBINT v = (DBINT) val.Value(); r = Check(bcp_colptr(GetCmd(), (BYTE*) val.BindVal(), i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), val.IsNULL() ? 0 : -1, i + 1)) == SUCCEED ? SUCCEED : FAIL; } break; case eDB_SmallInt: { CDB_SmallInt& val = dynamic_cast<CDB_SmallInt&> (param); // DBSMALLINT v = (DBSMALLINT) val.Value(); r = Check(bcp_colptr(GetCmd(), (BYTE*) val.BindVal(), i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), val.IsNULL() ? 0 : -1, i + 1)) == SUCCEED ? SUCCEED : FAIL; } break; case eDB_TinyInt: { CDB_TinyInt& val = dynamic_cast<CDB_TinyInt&> (param); // DBTINYINT v = (DBTINYINT) val.Value(); r = Check(bcp_colptr(GetCmd(), (BYTE*) val.BindVal(), i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), val.IsNULL() ? 0 : -1, i + 1)) == SUCCEED ? SUCCEED : FAIL; } break; case eDB_BigInt: { CDB_BigInt& val = dynamic_cast<CDB_BigInt&> (param); DBNUMERIC* v = (DBNUMERIC*) pb; v->precision= 18; v->scale= 0; Int8 v8 = val.Value(); if (longlong_to_numeric(v8, 18, DBNUMERIC_val(v)) == 0) return false; r = Check(bcp_colptr(GetCmd(), (BYTE*) v, i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), val.IsNULL() ? 0 : -1, i + 1)) == SUCCEED ? SUCCEED : FAIL; pb = (void*) (v + 1); } break; case eDB_Char: { CDB_Char& val = dynamic_cast<CDB_Char&> (param); if (val.IsNULL()) { r = Check(bcp_colptr(GetCmd(), (BYTE*) "", i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), 0, i + 1)) == SUCCEED ? SUCCEED : FAIL; } else { r = Check(bcp_colptr(GetCmd(), (BYTE*) val.AsCString(), i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), -1 /* val.Size() */, i + 1)) == SUCCEED ? SUCCEED : FAIL; } } break; case eDB_VarChar: { CDB_VarChar& val = dynamic_cast<CDB_VarChar&> (param); if (val.IsNULL()) { r = Check(bcp_colptr(GetCmd(), (BYTE*) "", i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), 0, i + 1)) == SUCCEED ? SUCCEED : FAIL; } else { r = Check(bcp_colptr(GetCmd(), (BYTE*) val.AsCString(), i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), -1, i + 1)) == SUCCEED ? SUCCEED : FAIL; } } break; case eDB_LongChar: { CDB_LongChar& val = dynamic_cast<CDB_LongChar&> (param); if (val.IsNULL()) { r = Check(bcp_colptr(GetCmd(), (BYTE*) "", i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), 0, i + 1)) == SUCCEED ? SUCCEED : FAIL; } else { r = Check(bcp_colptr(GetCmd(), (BYTE*) val.AsCString(), i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), -1, i + 1)) == SUCCEED ? SUCCEED : FAIL; } } break; case eDB_Binary: { CDB_Binary& val = dynamic_cast<CDB_Binary&> (param); r = Check(bcp_colptr(GetCmd(), (BYTE*) val.Value(), i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), val.IsNULL() ? 0 : (DBINT) val.Size(), i + 1)) == SUCCEED ? SUCCEED : FAIL; } break; case eDB_VarBinary: { CDB_VarBinary& val = dynamic_cast<CDB_VarBinary&> (param); r = Check(bcp_colptr(GetCmd(), (BYTE*) val.Value(), i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), val.IsNULL() ? 0 : (DBINT)val.Size(), i + 1)) == SUCCEED ? SUCCEED : FAIL; } break; case eDB_LongBinary: { CDB_LongBinary& val = dynamic_cast<CDB_LongBinary&> (param); r = Check(bcp_colptr(GetCmd(), (BYTE*) val.Value(), i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), val.IsNULL() ? 0 : val.DataSize(), i + 1)) == SUCCEED ? SUCCEED : FAIL; } break; case eDB_Float: { CDB_Float& val = dynamic_cast<CDB_Float&> (param); //DBREAL v = (DBREAL) val.Value(); r = Check(bcp_colptr(GetCmd(), (BYTE*) val.BindVal(), i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), val.IsNULL() ? 0 : -1, i + 1)) == SUCCEED ? SUCCEED : FAIL; } break; case eDB_Double: { CDB_Double& val = dynamic_cast<CDB_Double&> (param); //DBFLT8 v = (DBFLT8) val.Value(); r = Check(bcp_bind(GetCmd(), (BYTE*) val.BindVal(), 0, val.IsNULL() ? 0 : -1, 0, 0, SYBFLT8, i + 1)); } break; case eDB_SmallDateTime: { CDB_SmallDateTime& val = dynamic_cast<CDB_SmallDateTime&> (param); DBDATETIME4* dt = (DBDATETIME4*) pb; if (param.IsNULL()) { DBDATETIME4_days(dt) = 0; DBDATETIME4_mins(dt) = 0; } else { DBDATETIME4_days(dt) = val.GetDays(); DBDATETIME4_mins(dt) = val.GetMinutes(); } r = Check(bcp_colptr(GetCmd(), (BYTE*) dt, i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), val.IsNULL() ? 0 : -1, i + 1)) == SUCCEED ? SUCCEED : FAIL; pb = (void*) (dt + 1); } break; case eDB_DateTime: { CDB_DateTime& val = dynamic_cast<CDB_DateTime&> (param); DBDATETIME* dt = (DBDATETIME*) pb; if (param.IsNULL()) { dt->dtdays = 0; dt->dttime = 0; } else { dt->dtdays = val.GetDays(); dt->dttime = val.Get300Secs(); } r = Check(bcp_colptr(GetCmd(), (BYTE*) dt, i + 1)) == SUCCEED && Check(bcp_collen(GetCmd(), val.IsNULL() ? 0 : -1, i + 1)) == SUCCEED ? SUCCEED : FAIL; pb = (void*) (dt + 1); } break; case eDB_Text: { CDB_Text& val = dynamic_cast<CDB_Text&> (param); r = Check(bcp_collen(GetCmd(), (DBINT) val.Size(), i + 1)); } break; case eDB_Image: { CDB_Image& val = dynamic_cast<CDB_Image&> (param); r = Check(bcp_collen(GetCmd(), (DBINT) val.Size(), i + 1)); } break; default: return false; } if (r != CS_SUCCEED) return false; } } return true; }
// Aux. for CDBL_RowResult::GetItem() CDB_Object* CDBL_Result::GetItemInternal( I_Result::EGetItem policy, int item_no, SDBL_ColDescr* fmt, CDB_Object* item_buff ) { EDB_Type b_type = item_buff ? item_buff->GetType() : eDB_UnsupportedType; const BYTE* d_ptr = Check(dbdata (GetCmd(), item_no)); DBINT d_len = Check(dbdatlen(GetCmd(), item_no)); CDB_Object* val = s_GenericGetItem(fmt->data_type, item_buff, b_type, d_ptr, d_len); if (val) return val; switch (fmt->data_type) { case eDB_BigInt: { DBNUMERIC* v = (DBNUMERIC*) d_ptr; if (item_buff) { if (v) { if (b_type == eDB_Numeric) { ((CDB_Numeric*) item_buff)->Assign ((unsigned int) v->precision, (unsigned int) v->scale, (unsigned char*) DBNUMERIC_val(v)); } else if (b_type == eDB_BigInt) { *((CDB_BigInt*) item_buff) = numeric_to_longlong ((unsigned int) v->precision, DBNUMERIC_val(v)); } else { DATABASE_DRIVER_ERROR( "Wrong type of CDB_Object." + GetDbgInfo(), 230020 ); } } else item_buff->AssignNULL(); return item_buff; } return v ? new CDB_BigInt(numeric_to_longlong((unsigned int) v->precision, DBNUMERIC_val(v))) : new CDB_BigInt; } case eDB_Numeric: { DBNUMERIC* v = (DBNUMERIC*) d_ptr; if (item_buff) { if (v) { if (b_type == eDB_Numeric) { ((CDB_Numeric*) item_buff)->Assign ((unsigned int) v->precision, (unsigned int) v->scale, (unsigned char*) DBNUMERIC_val(v)); } else { DATABASE_DRIVER_ERROR( "Wrong type of CDB_Object." + GetDbgInfo(), 230020 ); } } else item_buff->AssignNULL(); return item_buff; } return v ? new CDB_Numeric((unsigned int) v->precision, (unsigned int) v->scale, (unsigned char*) DBNUMERIC_val(v)) : new CDB_Numeric; } case eDB_Text: { if (item_buff && b_type != eDB_Text && b_type != eDB_Image) { DATABASE_DRIVER_ERROR( "Wrong type of CDB_Object." + GetDbgInfo(), 130020 ); } CDB_Text* v = NULL; if (item_buff) { v = static_cast<CDB_Text*>(item_buff); if (policy == I_Result::eAssignLOB) { // Explicitly truncate previous value ... v->Truncate(); } } else { v = new CDB_Text; } _ASSERT(v); v->Append((char*) d_ptr, (int) d_len); return v; } case eDB_Image: { if (item_buff && b_type != eDB_Text && b_type != eDB_Image) { DATABASE_DRIVER_ERROR( "Wrong type of CDB_Object." + GetDbgInfo(), 130020 ); } CDB_Image* v = NULL; if (item_buff) { v = static_cast<CDB_Image*>(item_buff); if (policy == I_Result::eAssignLOB) { // Explicitly truncate previous value ... v->Truncate(); } } else { v = new CDB_Image; } _ASSERT(v); v->Append((void*) d_ptr, (int) d_len); return v; } default: DATABASE_DRIVER_ERROR( "Unexpected result type." + GetDbgInfo(), 130004 ); } }