lang_cmd.cpp
来自「ncbi源码」· C++ 代码 · 共 560 行 · 第 1/2 页
CPP
560 行
else { while(dbres->Fetch()); } delete dbres; } }}bool CODBC_LangCmd::HasFailed() const{ return m_HasFailed;}int CODBC_LangCmd::RowCount() const{ return m_RowCount;}void CODBC_LangCmd::Release(){ m_BR = 0; if (m_WasSent) { Cancel(); m_WasSent = false; } m_Connect->DropCmd(*this); delete this;}CODBC_LangCmd::~CODBC_LangCmd(){ if (m_BR) *m_BR = 0; if (m_WasSent) Cancel(); SQLFreeHandle(SQL_HANDLE_STMT, m_Cmd);}bool CODBC_LangCmd::x_AssignParams(string& cmd, CMemPot& bind_guard, SQLINTEGER* indicator){ 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); const char* type; char tbuf[64]; SQLRETURN rc_from_bind; switch (param.GetType()) { case eDB_Int: { CDB_Int& val = dynamic_cast<CDB_Int&> (param); type = "int"; indicator[n]= 4; rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 4, 0, val.BindVal(), 4, indicator+n); break; } case eDB_SmallInt: { CDB_SmallInt& val = dynamic_cast<CDB_SmallInt&> (param); type = "smallint"; indicator[n]= 2; rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_SSHORT, SQL_SMALLINT, 2, 0, val.BindVal(), 2, indicator+n); break; } case eDB_TinyInt: { CDB_TinyInt& val = dynamic_cast<CDB_TinyInt&> (param); type = "tinyint"; indicator[n]= 1; rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_UTINYINT, SQL_TINYINT, 1, 0, val.BindVal(), 1, indicator+n); break; } case eDB_BigInt: { CDB_BigInt& val = dynamic_cast<CDB_BigInt&> (param); type = "numeric"; indicator[n]= 8; rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_SBIGINT, SQL_NUMERIC, 18, 0, val.BindVal(), 18, indicator+n); break; } case eDB_Char: { CDB_Char& val = dynamic_cast<CDB_Char&> (param); type= "varchar(255)"; indicator[n]= SQL_NTS; rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 255, 0, (void*)val.Value(), 256, indicator+n); break; } case eDB_VarChar: { CDB_VarChar& val = dynamic_cast<CDB_VarChar&> (param); type = "varchar(255)"; indicator[n]= SQL_NTS; rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, 255, 0, (void*)val.Value(), 256, indicator+n); break; } case eDB_LongChar: { CDB_LongChar& val = dynamic_cast<CDB_LongChar&> (param); sprintf(tbuf,"varchar(%d)", val.Size()); type= tbuf; indicator[n]= SQL_NTS; rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_VARCHAR, val.Size(), 0, (void*)val.Value(), val.Size(), indicator+n); break; } case eDB_Binary: { CDB_Binary& val = dynamic_cast<CDB_Binary&> (param); type = "varbinary(255)"; indicator[n]= val.Size(); rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, 255, 0, (void*)val.Value(), 255, indicator+n); break; } case eDB_VarBinary: { CDB_VarBinary& val = dynamic_cast<CDB_VarBinary&> (param); type = "varbinary(255)"; indicator[n]= val.Size(); rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, 255, 0, (void*)val.Value(), 255, indicator+n); break; } case eDB_LongBinary: { CDB_LongBinary& val = dynamic_cast<CDB_LongBinary&> (param); sprintf(tbuf,"varbinary(%d)", val.Size()); type= tbuf; type = "varbinary(255)"; indicator[n]= val.DataSize(); rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_BINARY, SQL_VARBINARY, val.Size(), 0, (void*)val.Value(), val.Size(), indicator+n); break; } case eDB_Float: { CDB_Float& val = dynamic_cast<CDB_Float&> (param); type = "real"; indicator[n]= 4; rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_FLOAT, SQL_REAL, 4, 0, val.BindVal(), 4, indicator+n); break; } case eDB_Double: { CDB_Double& val = dynamic_cast<CDB_Double&> (param); type = "float"; indicator[n]= 8; rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_DOUBLE, SQL_FLOAT, 8, 0, val.BindVal(), 8, indicator+n); break; } case eDB_SmallDateTime: { CDB_SmallDateTime& val = dynamic_cast<CDB_SmallDateTime&> (param); type = "smalldatetime"; SQL_TIMESTAMP_STRUCT* ts= 0; if(!val.IsNULL()) { ts= (SQL_TIMESTAMP_STRUCT*)bind_guard.Alloc(sizeof(SQL_TIMESTAMP_STRUCT)); const CTime& t= val.Value(); ts->year= t.Year(); ts->month= t.Month(); ts->day= t.Day(); ts->hour= t.Hour(); ts->minute= t.Minute(); ts->second= 0; ts->fraction= 0; indicator[n]= sizeof(SQL_TIMESTAMP_STRUCT); } rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_TYPE_TIMESTAMP, SQL_TYPE_TIMESTAMP, 16, 0, (void*)ts, sizeof(SQL_TIMESTAMP_STRUCT), indicator+n); break; } case eDB_DateTime: { CDB_DateTime& val = dynamic_cast<CDB_DateTime&> (param); type = "datetime"; SQL_TIMESTAMP_STRUCT* ts= 0; if(!val.IsNULL()) { ts= (SQL_TIMESTAMP_STRUCT*)bind_guard.Alloc(sizeof(SQL_TIMESTAMP_STRUCT)); const CTime& t= val.Value(); ts->year= t.Year(); ts->month= t.Month(); ts->day= t.Day(); ts->hour= t.Hour(); ts->minute= t.Minute(); ts->second= t.Second(); ts->fraction= t.NanoSecond()/1000000; ts->fraction*= 1000000; /* MSSQL has a bug - it can not handle fraction of msecs */ indicator[n]= sizeof(SQL_TIMESTAMP_STRUCT); } rc_from_bind= SQLBindParameter(m_Cmd, n+1, SQL_PARAM_INPUT, SQL_C_TYPE_TIMESTAMP, SQL_TYPE_TIMESTAMP, 23, 3, ts, sizeof(SQL_TIMESTAMP_STRUCT), indicator+n); break; } default: return false; } switch(rc_from_bind) { case SQL_SUCCESS_WITH_INFO: m_Reporter.ReportErrors(); case SQL_SUCCESS: break; case SQL_ERROR: m_Reporter.ReportErrors(); throw CDB_ClientEx(eDB_Error, 420066, "CODBC_LangCmd::x_AssignParams", "SQLBindParameter failed"); default: throw CDB_ClientEx(eDB_Error, 420067, "CODBC_LangCmd::x_AssignParams", "SQLBindParameter failed (memory corruption suspected)"); } cmd += "declare " + name + ' ' + type + ";select " + name + " = ?;"; if(param.IsNULL()) { indicator[n]= SQL_NULL_DATA; } } return true;}bool CODBC_LangCmd::xCheck4MoreResults(){ switch(SQLMoreResults(m_Cmd)) { case SQL_SUCCESS_WITH_INFO: m_Reporter.ReportErrors(); case SQL_SUCCESS: return true; case SQL_NO_DATA: return false; case SQL_ERROR: m_Reporter.ReportErrors(); throw CDB_ClientEx(eDB_Error, 420014, "CODBC_LangCmd::xCheck4MoreResults", "SQLMoreResults failed"); default: throw CDB_ClientEx(eDB_Error, 420015, "CODBC_LangCmd::xCheck4MoreResults", "SQLMoreResults failed (memory corruption suspected)"); }}END_NCBI_SCOPE/* * =========================================================================== * $Log: lang_cmd.cpp,v $ * Revision 1000.2 2004/06/01 19:21:51 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.8 * * Revision 1.8 2004/05/17 21:16:06 gorelenk * Added include of PCH ncbi_pch.hpp * * Revision 1.7 2003/11/07 17:14:20 soussov * work around the odbc bug. It can not handle properly the fractions of msecs * * Revision 1.6 2003/11/06 20:33:32 soussov * fixed bug in DateTime bindings * * Revision 1.5 2003/06/05 16:02:04 soussov * adds code for DumpResults and for the dumped results processing * * Revision 1.4 2003/05/16 20:26:44 soussov * adds code to skip parameter if it was not set * * Revision 1.3 2003/05/08 20:40:08 soussov * adds stdio.h for sprintf * * Revision 1.2 2003/05/08 20:30:24 soussov * CDB_LongChar CDB_LongBinary added * * Revision 1.1 2002/06/18 22:06:24 soussov * initial commit * * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?