📄 lang_cmd.cpp
字号:
{ return m_HasFailed;}int CDBL_LangCmd::RowCount() const{ return (m_RowCount < 0)? DBCOUNT(m_Cmd) : m_RowCount;}void CDBL_LangCmd::Release(){ m_BR = 0; if (m_WasSent) { Cancel(); m_WasSent = false; } m_Connect->DropCmd(*this); delete this;}CDBL_LangCmd::~CDBL_LangCmd(){ if (m_BR) *m_BR = 0; if (m_WasSent) Cancel();}bool CDBL_LangCmd::x_AssignParams(){ static const char s_hexnum[] = "0123456789ABCDEF"; for (unsigned int n = 0; n < m_Params.NofParams(); n++) { if(m_Params.GetParamStatus(n) == 0) continue; const string& name = m_Params.GetParamName(n); CDB_Object& param = *m_Params.GetParam(n); char val_buffer[1024]; const char* type; string cmd; if (name.length() > kDBLibMaxNameLen) return false; switch (param.GetType()) { case eDB_Int: type = "int"; break; case eDB_SmallInt: type = "smallint"; break; case eDB_TinyInt: type = "tinyint"; break; case eDB_BigInt: type = "numeric"; break; case eDB_Char: case eDB_VarChar: type = "varchar(255)"; break; case eDB_Binary: case eDB_VarBinary: type = "varbinary(255)"; break; case eDB_Float: type = "real"; break; case eDB_Double: type = "float"; break; case eDB_SmallDateTime: type = "smalldatetime"; break; case eDB_DateTime: type = "datetime"; break; default: return false; } cmd += "declare " + name + ' ' + type + "\nselect " + name + " = "; if (!param.IsNULL()) { switch (param.GetType()) { case eDB_Int: { CDB_Int& val = dynamic_cast<CDB_Int&> (param); sprintf(val_buffer, "%d\n", val.Value()); break; } case eDB_SmallInt: { CDB_SmallInt& val = dynamic_cast<CDB_SmallInt&> (param); sprintf(val_buffer, "%d\n", (int) val.Value()); break; } case eDB_TinyInt: { CDB_TinyInt& val = dynamic_cast<CDB_TinyInt&> (param); sprintf(val_buffer, "%d\n", (int) val.Value()); break; } case eDB_BigInt: { CDB_BigInt& val = dynamic_cast<CDB_BigInt&> (param); sprintf(val_buffer, "%lld\n", val.Value()); break; } case eDB_Char: { CDB_Char& val = dynamic_cast<CDB_Char&> (param); const char* c = val.Value(); // No more than 255 chars size_t i = 0; val_buffer[i++] = '"'; while (*c) { if (*c == '"') val_buffer[i++] = '"'; val_buffer[i++] = *c++; } val_buffer[i++] = '"'; val_buffer[i++] = '\n'; val_buffer[i] = '\0'; break; } case eDB_VarChar: { CDB_VarChar& val = dynamic_cast<CDB_VarChar&> (param); const char* c = val.Value(); size_t i = 0; val_buffer[i++] = '"'; while (*c) { if (*c == '"') val_buffer[i++] = '"'; val_buffer[i++] = *c++; } val_buffer[i++] = '"'; val_buffer[i++] = '\n'; val_buffer[i] = '\0'; break; } case eDB_Binary: { CDB_Binary& val = dynamic_cast<CDB_Binary&> (param); const unsigned char* c = (const unsigned char*) val.Value(); size_t i = 0, size = val.Size(); val_buffer[i++] = '0'; val_buffer[i++] = 'x'; for (size_t j = 0; j < size; j++) { val_buffer[i++] = s_hexnum[c[j] >> 4]; val_buffer[i++] = s_hexnum[c[j] & 0x0F]; } val_buffer[i++] = '\n'; val_buffer[i++] = '\0'; break; } case eDB_VarBinary: { CDB_VarBinary& val = dynamic_cast<CDB_VarBinary&> (param); const unsigned char* c = (const unsigned char*) val.Value(); size_t i = 0, size = val.Size(); val_buffer[i++] = '0'; val_buffer[i++] = 'x'; for (size_t j = 0; j < size; j++) { val_buffer[i++] = s_hexnum[c[j] >> 4]; val_buffer[i++] = s_hexnum[c[j] & 0x0F]; } val_buffer[i++] = '\n'; val_buffer[i++] = '\0'; break; } case eDB_Float: { CDB_Float& val = dynamic_cast<CDB_Float&> (param); sprintf(val_buffer, "%E\n", (double) val.Value()); break; } case eDB_Double: { CDB_Double& val = dynamic_cast<CDB_Double&> (param); sprintf(val_buffer, "%E\n", val.Value()); break; } case eDB_SmallDateTime: { CDB_SmallDateTime& val = dynamic_cast<CDB_SmallDateTime&> (param); sprintf(val_buffer, "'%s'\n", val.Value().AsString("M/D/Y h:m").c_str()); break; } case eDB_DateTime: { CDB_DateTime& val = dynamic_cast<CDB_DateTime&> (param); sprintf(val_buffer, "'%s:%.3d'\n", val.Value().AsString("M/D/Y h:m:s").c_str(), (int)(val.Value().NanoSecond()/1000000)); break; } default: return false; // dummy for compiler } cmd += val_buffer; } else cmd += "NULL\n"; if (dbcmd(m_Cmd, (char*) cmd.c_str()) != SUCCEED) return false; } return true;}END_NCBI_SCOPE/* * =========================================================================== * $Log: lang_cmd.cpp,v $ * Revision 1000.1 2004/06/01 19:20:19 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.14 * * Revision 1.14 2004/05/18 18:30:36 gorelenk * PCH <ncbi_pch.hpp> moved to correct place . * * Revision 1.13 2003/06/05 16:01:13 soussov * adds code for DumpResults and for the dumped results processing * * Revision 1.12 2003/05/16 20:25:20 soussov * adds code to skip parameter if it was not set * * Revision 1.11 2002/07/22 20:02:59 soussov * fixes the RowCount calculations * * Revision 1.10 2002/07/02 16:05:49 soussov * splitting Sybase dblib and MS dblib * * Revision 1.9 2002/01/11 20:11:43 vakatov * Fixed CVS logs from prev. revision that messed up the compilation * * Revision 1.8 2002/01/10 22:05:52 sapojnik * MS-specific workarounds needed to use blobs via I_ITDescriptor * (see Text,Image) * * Revision 1.7 2002/01/08 18:10:18 sapojnik * Syabse to MSSQL name translations moved to interface_p.hpp * * Revision 1.6 2001/12/18 19:29:22 soussov * adds conversion from nanosecs to milisecs for datetime args * * Revision 1.5 2001/12/18 17:56:53 soussov * copy-paste bug in datetime processing fixed * * Revision 1.4 2001/12/18 16:47:11 soussov * fixes bug in datetime argument processing * * Revision 1.3 2001/12/13 23:48:44 soussov * inserts space after declare * * Revision 1.2 2001/10/24 16:41:13 lavr * File description changed to be of the same style as in other files * * Revision 1.1 2001/10/22 15:19:55 lavr * This is a major revamp (by Anton Lavrentiev, with help from Vladimir * Soussov and Denis Vakatov) of the DBAPI "driver" libs originally * written by Vladimir Soussov. The revamp follows the one of CTLib * driver, and it involved massive code shuffling and grooming, numerous * local API redesigns, adding comments and incorporating DBAPI to * the C++ Toolkit. * * =========================================================================== */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -