inline void CheckType(const CDB_Object& value, EDB_Type type1, EDB_Type type2) { EDB_Type cur_type = value.GetType(); if (!(cur_type == type1 || cur_type == type2)) { DATABASE_DRIVER_ERROR("Invalid type conversion.", 101100); } }
inline void CheckType(const CDB_Object& value, EDB_Type type1) { EDB_Type cur_type = value.GetType(); if (cur_type != type1) { ReportTypeConvError(cur_type, type1); } }
inline void CheckType(const CDB_Object& value, EDB_Type type1, EDB_Type type2) { EDB_Type cur_type = value.GetType(); if (!(cur_type == type1 || cur_type == type2)) { DATABASE_DRIVER_ERROR(string("Invalid type conversion: have ") + CDB_Object::GetTypeName(cur_type, false) + " but need either " + CDB_Object::GetTypeName(type1, false) + " or " + CDB_Object::GetTypeName(type2, false), 101100); } }
inline TO Convert_CDB_Object_DT(const CDB_Object& value) { CheckNULL(value); const EDB_Type cur_type = value.GetType(); switch (cur_type) { case eDB_DateTime: return NCBI_CONVERT_TO(Convert(static_cast<const CDB_DateTime&>(value).Value()), TO); case eDB_SmallDateTime: return NCBI_CONVERT_TO(Convert(static_cast<const CDB_SmallDateTime&>(value).Value()), TO); default: ReportTypeConvError(cur_type, "bool"); } return TO(); }
inline TO Convert_CDB_ObjectSql(const CDB_Object& value) { if (value.IsNULL()) { return TO(); } const EDB_Type cur_type = value.GetType(); switch (cur_type) { case eDB_BigInt: return NCBI_CONVERT_TO(Convert(static_cast<const CDB_BigInt&>(value).Value()), TO); case eDB_Int: return NCBI_CONVERT_TO(Convert(static_cast<const CDB_Int&>(value).Value()), TO); case eDB_SmallInt: return NCBI_CONVERT_TO(Convert(static_cast<const CDB_SmallInt&>(value).Value()), TO); case eDB_TinyInt: return NCBI_CONVERT_TO(Convert(static_cast<const CDB_TinyInt&>(value).Value()), TO); case eDB_Bit: return NCBI_CONVERT_TO(Convert(static_cast<const CDB_Bit&>(value).Value()), TO); case eDB_Float: return NCBI_CONVERT_TO(Convert(static_cast<const CDB_Float&>(value).Value()), TO); case eDB_Double: return NCBI_CONVERT_TO(Convert(static_cast<const CDB_Double&>(value).Value()), TO); case eDB_Numeric: return NCBI_CONVERT_TO(Convert(static_cast<const CDB_Numeric&>(value).Value()), TO); case eDB_Char: case eDB_VarChar: case eDB_LongChar: { const CDB_String& cdb_str = static_cast<const CDB_String&>(value); const string& str = cdb_str.Value(); return Convert(str); } case eDB_Binary: return Convert(string( static_cast<const char*>(static_cast<const CDB_Binary&>(value).Value()), static_cast<const CDB_Binary&>(value).Size() )); case eDB_VarBinary: return Convert(string( static_cast<const char*>(static_cast<const CDB_VarBinary&>(value).Value()), static_cast<const CDB_VarBinary&>(value).Size() )); case eDB_LongBinary: return Convert(string( static_cast<const char*>(static_cast<const CDB_LongBinary&>(value).Value()), static_cast<const CDB_LongBinary&>(value).DataSize() )); case eDB_Text: case eDB_Image: { string result; CDB_Stream& strm = const_cast<CDB_Stream&>(static_cast<const CDB_Stream&>(value)); result.resize(strm.Size()); strm.Read(const_cast<void*>(static_cast<const void*>(result.c_str())), strm.Size() ); return Convert(result); } default: ReportTypeConvError(cur_type, "bool"); } return TO(); }