36 #ifdef HAVE_LIBNCBICRYPT
37 # include <ncbi_key_lookup.h>
48 #include "../rw_impl.hpp"
51 #define NCBI_USE_ERRCODE_X Dbapi_Sdbapi
57 #define SDBAPI_CATCH_LOWLEVEL() \
58 catch (CDB_DeadlockEx& ex) { \
59 NCBI_RETHROW(ex, CSDB_DeadlockException, eLowLevel, ""); \
60 } catch (CDB_Exception& ex) { \
61 NCBI_RETHROW(ex, CSDB_Exception, eLowLevel, ""); \
64 #define SDBAPI_THROW(code, msg) \
65 NCBI_THROW(CSDB_Exception, code, \
66 CDB_Exception::SMessageInContext(msg, x_GetContext()))
248 "Conversion between " +
string(one_type) +
" and "
250 +
" is not supported");
253 #ifdef NCBI_COMPILER_WORKSHOP
254 #define CONVERTVALUE_STATIC
256 #define CONVERTVALUE_STATIC static
276 string str_val = from_val.
AsString();
278 to_var.
Append(str_val.data(), str_val.size());
291 to_var =
Int8(from_val);
303 to_var.
Append(str_val.data(), str_val.size());
316 to_var =
Int8(from_val);
319 to_var =
Int4(from_val);
331 to_var.
Append(str_val.data(), str_val.size());
344 to_var =
Int8(from_val);
347 to_var =
Int4(from_val);
350 to_var =
Int2(from_val);
362 to_var.
Append(str_val.data(), str_val.size());
375 to_var =
Int8(from_val);
378 to_var =
Int4(from_val);
381 to_var =
Int2(from_val);
384 to_var =
Uint1(from_val);
396 to_var.
Append(str_val.data(), str_val.size());
409 to_var =
Int8(from_val);
412 to_var =
Int4(from_val);
415 to_var =
Int2(from_val);
418 to_var =
Uint1(from_val);
421 to_var =
bool(from_val);
433 to_var.
Append(str_val.data(), str_val.size());
446 to_var = float(from_val);
449 to_var = double(from_val);
461 to_var.
Append(str_val.data(), str_val.size());
474 to_var = double(from_val);
486 to_var.
Append(str_val.data(), str_val.size());
516 to_var.
Append(from_val.data(), from_val.size());
525 to_var = NStr::StringToNumeric<Int2>(from_val);
528 to_var = NStr::StringToNumeric<Uint1>(from_val);
539 to_var =
CTime(from_val);
564 s_ConvertValue(
string(
reinterpret_cast<const char*
>(from_val.data()),
576 to_var.
Append(
reinterpret_cast<const char*
>(from_val.data()),
593 #undef CONVERTVALUE_STATIC
681 "Value for Int4 is out of bounds: "
684 to_val =
Int4(temp_val);
718 "Value for short is out of bounds: "
721 to_val = short(temp_val);
738 to_val =
static_cast<unsigned char>(from_var.
GetBit());
755 "Value for unsigned char is out of bounds: "
758 to_val =
static_cast<unsigned char>(temp_val);
773 to_val = from_var.
GetBit();
786 if (temp_val != 0 && temp_val != 1)
789 "Value for bool is out of bounds: "
792 to_val = temp_val == 1;
879 "fNBS_ZLib and fNBS_BZLib are mutually incompatible; "
880 "please specify at most one compression algorithm.");
932 || driver_name ==
"ftds100"
933 || driver_name ==
"ftds14") {
936 ERR_POST_X(15,
"Unsupported driver name " << driver_name
980 "Password decryption failed.");
994 #ifdef HAVE_LIBNCBICRYPT
996 key = NCBICRYPT_FindBuiltinKey(
string(key_id).c_str());;
1001 "Unknown password decryption key ID " +
string(key_id));
1039 "Connection parameters miss at least one essential part"
1040 " (host, user, password, or database [as \"path\"]): "
1065 if ( !it->value.empty() ) {
1085 static const char*
kDefault =
"default";
1093 #define COPY_PARAM_EX(en, gn, fn) \
1094 if (conf_params.Is##gn##Set()) \
1095 m_ParamMap[e##en] = conf_params.fn
1096 #define COPY_PARAM(en, fn) COPY_PARAM_EX(en, en, fn)
1097 #define COPY_BOOL_PARAM(en, gn, fn) \
1098 if (conf_params.Is##gn##Set()) \
1099 m_ParamMap[e##en] = conf_params.fn.empty() ? "default" \
1100 : NStr::StringToBool(conf_params.fn) ? "true" : "false"
1101 #define COPY_NUM_PARAM(en, gn, fn) \
1102 if (conf_params.Is##gn##Set()) \
1103 m_ParamMap[e##en] = conf_params.fn.empty() ? kDefault : conf_params.fn
1123 pool_allow_temp_overflow);
1125 continue_after_raiserror);
1126 COPY_NUM_PARAM (ConnPoolMaxConnUse, PoolMaxConnUse, pool_max_conn_use);
1127 COPY_BOOL_PARAM(LogMinorMessages, LogMinorMessages, log_minor_messages);
1129 #undef COPY_PARAM_EX
1131 #undef COPY_BOOL_PARAM
1132 #undef COPY_NUM_PARAM
1134 if ( !conf_params.
args.empty() ) {
1149 " password_file parameters are mutually exclusive.");
1168 password = it->second;
1171 if (pwfile.empty()) {
1178 "Unable to open password file " + pwfile +
": " +
1187 if ( !key_id.empty() ) {
1190 password = decryptor->Decrypt(password, key_id);
1191 ITERATE (
string, pit, password) {
1192 if ( !
isprint((
unsigned char)*pit) ) {
1195 "Invalid character in supposedly decrypted"
1214 if ( !port.empty() ) {
1222 if (params->
GetParam(
"is_pooled") ==
"true") {
1226 if ( !explicit_pool_name.empty() ) {
1227 params->
SetParam(
"pool_name", explicit_pool_name);
1233 params->
SetParam(
"pool_max_conn_use",
1249 typedef vector<CUrlArgs*> TAllArgs;
1253 unique_ptr<CUrlArgs> conf_args;
1257 conf_args.reset(
new CUrlArgs(it->second));
1258 all_args.push_back(conf_args.get());
1262 ITERATE (TAllArgs, ait, all_args) {
1265 const string& param_name = uit->name;
1266 const string& param_value = uit->value;
1268 params->
SetParam(param_name, param_value);
1273 params->
SetParam(
"do_not_read_conf",
"true");
1278 const string& name,
EParam id)
const
1292 if (code_value == reg_value) {
1301 conf_map[it->name] = it->value;
1305 TConfMap::const_iterator cmit = conf_map.find(uait->name);
1306 if (cmit != conf_map.end()) {
1311 ERR_POST_X(18,
Info <<
"Using privately configured service alias "
1312 << code_value <<
" -> " << reg_value);
1315 code_value =
"(redacted)";
1316 reg_value =
"(redacted)";
1319 <<
" parameter value " << code_value <<
" for "
1334 list<string> sections;
1336 ITERATE(list<string>, it, sections) {
1337 const string& name = *it;
1338 if (name.size() <= 10
1347 if (lower_params.
GetParam(
"is_pooled") ==
"true") {
1348 result &=
ctx->SatisfyPoolMinimum(lower_params);
1370 "CSDBAPI::UseDriver called with SDBAPI already in use.");
1481 list<string>* servers ,
1482 string* error_message )
1484 if (dbservice.empty()) {
1486 "Mirrored database service name cannot be empty");
1489 bool first_execution =
false;
1490 SMirrorInfo& mir_info = (*s_MirrorsData)[dbservice];
1493 first_execution =
true;
1502 first_execution =
true;
1505 if (conn_params.
GetParam(
"single_server") !=
"true") {
1507 "UpdateMirror cannot be used when configuration file "
1508 "doesn't have exclusive_server=true (for " + dbservice
1515 "UpdateMirror cannot work with non-standard "
1516 "connection factory");
1522 error_message->clear();
1527 bool need_reread_servers =
false;
1528 bool servers_reread =
false;
1529 bool has_master =
false;
1530 int cnt_switches = 0;
1533 if (serv_list.empty()) {
1534 list<string> servers;
1536 ITERATE(list<string>, it, servers) {
1538 serv_list.back()->server_name = *it;
1541 servers_reread =
true;
1543 else if (need_reread_servers) {
1544 list<string> new_serv_info;
1548 ITERATE(list<string>, it, new_serv_info) {
1549 if (*it == (*old_it)->server_name) {
1555 serv_list.erase(old_it);
1558 ITERATE(list<string>, new_it, new_serv_info) {
1561 if ((*old_it)->server_name == *new_it) {
1568 serv_list.back()->server_name = *new_it;
1572 servers_reread =
true;
1574 if (serv_list.empty()) {
1576 ERR_POST_X(3,
"No servers for service '" << service_name
1577 <<
"' are available");
1578 if (error_message) {
1579 *error_message =
"No servers for service '" + service_name
1580 +
"' are available";
1585 for (TMirrorServList::iterator it = serv_list.end(); it != serv_list.begin(); )
1589 const string& server_name = (*it)->server_name;
1594 if (!
conn->IsAlive()) {
1596 ERR_POST_X(7,
"Connection to server '" << server_name
1597 <<
"' for service '" << service_name
1603 serv_params.
SetParam(
"is_pooled",
"false");
1604 serv_params.
SetParam(
"do_not_dispatch",
"true");
1607 conn->Connect(serv_params);
1609 ERR_POST_X(8,
"Connection to server '" << server_name
1610 <<
"' for service '" << service_name
1611 <<
"' is restored.");
1619 ERR_POST_X(9,
"Cannot establish connection to server '"
1620 << server_name <<
"' for service '"
1621 << service_name <<
"'.");
1625 need_reread_servers =
true;
1628 bool success =
false;
1629 if (
conn->IsAlive()) {
1632 stmt->ExecuteUpdate(
"use " + db_name);
1641 if (!success && server_name == mir_info.
master) {
1643 string pool_name = conn_params.
GetParam(
"pool_name");
1645 ERR_POST_X(4,
"The master for database '" << db_name <<
1646 "' (service '" << service_name <<
1647 "') has become inaccessible. Because of this " <<
1648 invalidated_count <<
1649 " active connections got invalidated in the pool '" <<
1652 need_reread_servers =
true;
1654 else if (success && server_name != mir_info.
master) {
1656 string pool_name = conn_params.
GetParam(
"pool_name");
1657 size_t invalidated_count =
1660 conn->GetCDB_Connection()->Host(),
1661 conn->GetCDB_Connection()->Port());
1662 string msg_start =
"The master for database '" + db_name +
1663 "' (for service '" + service_name +
1664 "') switched to '" + server_name +
"' from ";
1665 string msg_end =
". Because of this " +
1667 " active connections got invalidated in the pool '" +
1670 if (mir_info.
master.empty()) {
1672 ERR_POST_X(5, Message << msg_start <<
"NONE" << msg_end);
1676 mir_info.
master <<
"'" << msg_end);
1681 mir_info.
master = server_name;
1682 serv_list.push_front(*it);
1683 TMirrorServList::iterator it_del = it++;
1684 serv_list.erase(it_del);
1685 need_reread_servers =
true;
1687 if (++cnt_switches == 10) {
1690 "Mirror database switches too frequently or "
1691 "it isn't mirrored: " + service_name);
1694 else if (success && server_name == mir_info.
master) {
1699 while (need_reread_servers && !servers_reread);
1701 if (first_execution && !has_master) {
1703 string pool_name = conn_params.
GetParam(
"pool_name");
1705 ERR_POST_X(10,
"The master for database '" << db_name <<
1706 "' (service '" << service_name <<
1707 "') is not accessible. Because of this " <<
1708 invalidated_count <<
1709 " active connections got invalidated in the pool '" <<
1715 servers->push_back((*it)->server_name);
1720 *error_message =
"All database instances are inaccessible";
1728 TNewBlobStoreFlags
flags,
1734 " variant of NewBlobStore that inspects column types"
1748 if (ex ==
nullptr) {
1760 const string& message)
1762 if (severity < 10 || (severity == 10 && msgnum == 0)) {
1763 if (severity == 0 || (severity == 10 && msgnum == 0)) {
1771 && (severity == 16 || (severity == 10 && msgnum > 0))) {
1784 (severity, msgnum, message);
1792 m_DefaultTimeout(0),
1793 m_HasCustomTimeout(
false),
1794 m_ContinueAfterRaiserror
1846 unsigned int sec, nanosec;
1847 timeout.
GetNano(&sec, &nanosec);
1891 conn->Connect(lower_params);
1905 : m_Conn(other.m_Conn),
1906 m_IsOpen(other.m_IsOpen),
1907 m_EverConnected(other.m_EverConnected)
2050 }
else if (check_method ==
eNoCheck) {
2056 if ( !
conn->IsAlive() ) {
2067 query.RequireRowCount(1);
2070 &&
row[1].AsInt4() == 1);
2073 }
catch (exception&) {
2089 #define CONNECT_AS_NEEDED() x_ConnectAsNeeded(NCBI_CURRENT_FUNCTION)
2107 const string& search_conditions,
2114 switch (column_type) {
2126 unique_ptr<I_BlobDescriptor> desc
2128 desc_type, has_legacy_type));
2136 TNewBlobStoreFlags
flags,
2142 " variant of NewBlobStore that inspects column types"
2153 const string& key_col_name,
2154 const string& num_col_name,
2155 const vector<string> blob_col_names,
2156 TNewBlobStoreFlags
flags,
2163 &blob_col_names[0], blob_col_names.size(),
2177 +
" when not connected.");
2186 "Cannot obtain driver version before connecting");
2203 : m_DBImpl(db_impl),
2205 m_Autoflush(autoflush),
2208 m_WriteStarted(
false),
2237 "Cannot write into completed CBulkInsert");
2244 "Cannot write into CBulkInsert when CDatabase was closed");
2246 if (col != 0 && col >
int(
m_Cols.size())) {
2248 "Too many values were written to CBulkInsert: "
2281 "Cannot bind columns when already started to insert");
2283 if (col - 1 !=
int(
m_Cols.size())) {
2285 "Cannot bind columns in CBulkInsert randomly");
2300 "Not enough values were written to CBulkInsert: "
2324 unique_ptr<IBulkInsert> bi(
m_BI);
2338 for (
unsigned int i = 0;
i <
m_Cols.size(); ++
i) {
2477 #if !NCBI_INT8_IS_LONG
2481 #if SIZEOF_LONG == 8
2553 : m_Basis(new
CParamQFB(v, q->x_GetContext(), param_type))
2563 : m_Basis(qf.m_Basis.release())
2622 : m_Fields(
r.m_Fields), m_MetaData(
r.m_MetaData)
2632 if (col == 0 || col > m_Fields.size()) {
2635 "No such column in the result set: "
2642 x_CheckColumnNumber(col);
2643 return m_Fields[col - 1];
2649 = m_MetaData->col_nums.find(col);
2650 if (it == m_MetaData->col_nums.end()) {
2653 "No such column in the result set: " + col +
". "
2656 return m_Fields[it->second - 1];
2662 return m_Fields.size();
2667 x_CheckColumnNumber(col);
2668 return m_MetaData->col_names[col - 1];
2673 x_CheckColumnNumber(col);
2674 return m_MetaData->col_types[col - 1];
2681 m_MetaData->exception_context.Reset(&q.
x_GetContext());
2686 m_Fields.reserve(cols_cnt);
2687 for (
unsigned int i = 1;
i <= cols_cnt; ++
i) {
2689 m_MetaData->col_nums[meta->
GetName(
i)] =
i;
2690 m_MetaData->col_names.emplace_back(meta->
GetName(
i));
2698 : m_DBImpl(db_impl),
2702 m_IgnoreBounds(
true),
2703 m_HasExplicitMode(
false),
2704 m_RSBeginned(
false),
2707 m_ReportedWrongRowCount(
false),
2709 m_RowUnderConstruction(
false),
2740 oss << (
m_IsSP ?
"RPC: " :
"SQL: ");
2744 oss <<
"; input parameter(s): ";
2748 oss << it->first <<
" = ";
2752 oss <<
value->GetData()->GetLogString();
2766 "CQuery is not operational because CDatabase was closed");
2772 "CQuery is closed or never executed");
2792 it->second.x_Detach();
2793 static_cast<CParamQFB&
>(*it->second.m_Impl->m_Basis)
2794 .SetParamType(param_type);
2802 const_cast<CVariant&
>(*it->second.m_Impl->GetValue()));
2819 it->second.x_Detach();
2820 static_cast<CParamQFB&
>(*it->second.m_Impl->m_Basis)
2821 .SetParamType(param_type);
2841 it->second.x_Detach();
2866 "Parameter '" +
string(name) +
"' doesn't exist. "
2868 }
else if (
static_cast<const CParamQFB&
>(*it->second.m_Impl->m_Basis)
2873 "CQuery::GetParameter called with some results still"
2888 it->second.x_Detach();
2898 p.second.x_Detach();
2939 "Problem while closing DB query "
2940 "(result was at row number " << orig_row_no <<
2941 " and is now at row number " <<
m_CurRowNo <<
").");
2985 "No statement to execute.");
3025 =
static_cast<const CParamQFB&
>(*it->second.m_Impl->m_Basis);
3084 "CQuery::GetRowCount called with some results still"
3097 "CQuery::GetStatus called with some results still"
3124 "Too many rows returned (limited to "
3130 "Not enough rows returned ("
3182 while (
stmt->HasMoreResults()) {
3196 for (
unsigned int i = 1;
i <= col_cnt; ++
i) {
3207 <<
"Multiple SDBAPI result sets found, but"
3208 " neither SingleSet nor MultiSet explicitly"
3209 " requested. Now defaulting to SingleSet. "
3261 if ( !has_more_rs ) {
3267 "All result sets in CQuery were already iterated through. "
3289 bool has_more =
true;
3297 while (has_more && rs !=
m_CurRS) {
3357 "RequireRowCount must follow Execute or ExecuteSP,"
3358 " which reset any requirements.");
3360 if (min_rows > max_rows) {
3362 "Inconsistent row-count constraints: "
3367 _TRACE(
"RequireRowCount(" << min_rows <<
", " << max_rows <<
')');
3380 bool missed_results =
false;
3410 if (missed_results) {
3439 nc_self.
m_Row = saved_row;
3482 : m_DBImpl(db_impl),
3564 : m_Query(ri.m_Query),
3582 return m_Query->x_GetContext();
3588 return m_Query->GetResultSetNo();
3594 return m_Query->GetRowNo();
3600 return m_Query->GetTotalColumns();
3606 return m_Query->GetColumnName(col);
3612 return m_Query->GetColumnType(col);
3620 else if (m_IsEnd ^ ri.
m_IsEnd) {
3621 return m_Query->IsFinished();
3630 if (m_IsEnd || m_Query->IsFinished()) {
3632 "Cannot increase end() iterator");
3641 return m_Query->GetRow()[col];
3647 return m_Query->GetRow()[col];
3652 return m_Query->GetRow();
3658 unique_ptr<IQueryFieldBasis> new_basis
3661 m_Basis.reset(new_basis.release());
3667 unique_ptr<IQueryFieldBasis> new_basis
3670 m_Basis.reset(new_basis.release());
3684 return m_Basis->x_GetContext();
3690 return m_Basis->GetValue();
3704 unsigned char value = 0;
3765 const vector<unsigned char>&
3769 string(
"Method is unsupported for this type of data: ")
3773 const vector<unsigned char>&
3776 const CVariant& var_val = *GetValue();
3781 const unsigned char*
data
3782 =
reinterpret_cast<const unsigned char*
>(
value.data());
3784 m_Vector.insert(m_Vector.begin(),
data,
data +
value.size());
3788 const vector<unsigned char>&
3791 return m_Impl->AsVector();
3798 string(
"Method is unsupported for this type of data: ")
3805 const CVariant& var_val = *GetValue();
3815 return m_Impl->AsIStream();
3821 return m_Impl->GetValue()->IsNull();
3827 "Method requires a live field");
3833 const CVariant& var_val = *GetValue();
3839 blob_size,
flags,
false),
3850 string(
"Method is unsupported for this type of data: ")
3857 m_OStream.reset(m_Basis->GetOStream(blob_size,
flags));
3870 return GetOStream(blob_size,
3877 "Method requires a live field");
3882 const CVariant& var_val = *GetValue();
3892 string(
"Method is unsupported for this type of data: ")
3898 return m_Basis->GetBookmark();
3904 return m_Impl->GetBookmark();
3932 const string&
value,
3982 unsigned char value,
4106 "Exactly one row requested while RequireRowCount() set "
4111 "Exactly one row requested while RequireRowCount() set "
4118 "Expected exactly one row, but none are available");
4125 "Expected exactly one row, but more than one are available");
Helper class to allow safe initialization from higher-layer objects.
unique_ptr< I_BlobDescriptor > m_Descr
CRef< CDatabaseImpl > m_DBImpl
unique_ptr< CWStream > m_OStream
CNcbiOstream & GetOStream(size_t blob_size, TBlobOStreamFlags flags)
CBlobBookmarkImpl(CDatabaseImpl *db_impl, I_BlobDescriptor *descr)
Object used to store bookmarks to blobs to be changed later.
CBlobBookmark & operator=(const CBlobBookmark &bm)
CNcbiOstream & GetOStream(size_t blob_size, TBlobOStreamFlags flags=0) const
Get Blob output stream.
CRef< CBlobBookmarkImpl > m_Impl
Bookmark implementation object.
CBlobBookmark(void)
Empty constructor of bookmark object.
EBlobType
Blob type (if known).
void x_CheckCanWrite(int col)
CRef< CDB_Exception::SContext > m_Context
void Bind(int col, ESDB_Type type)
void AddOrderHint(CTempString columns)
void x_CheckWriteStarted(void)
CBulkInsertImpl(CDatabaseImpl *db_impl, const string &tableName, int autoflush)
const CDB_Exception::SContext & x_GetContext(void) const
void WriteVal(const T &val)
void SetHints(CTempString hints)
CRef< CDatabaseImpl > m_DBImpl
void AddHint(IBulkInsert::EHints hint, unsigned int value)
vector< CVariant > m_Cols
Object used to perform bulk-inserting operations to database.
CBulkInsert & operator<<(const string &val)
Put values of different type into bulk-insert row.
EHints
Type of hint that can be set for bulk insert.
void AddHint(EHints hint)
Add hint to the bulk insert.
void Complete()
Complete bulk insert.
void Bind(int col, ESDB_Type type)
Bind column for bulk insert.
void AddOrderHint(CTempString columns)
Add "ORDER" hint.
EHintsWithValue
Type of hint that requires some value to be provided with it.
void SetHints(CTempString hints)
Set hints by one call. Resets everything that was set by Add*Hint().
CRef< CBulkInsertImpl > m_Impl
Bulk-insert implementation object.
CBulkInsert(void)
Empty constructor of bulk-insert object.
CBulkInsert & operator=(const CBulkInsert &bi)
void SetTimeout(const CTimeout &timeout)
CRef< CDB_Exception::SContext > m_Context
virtual ~CConnHolder(void)
bool m_ContinueAfterRaiserror
list< string > m_PrintOutput
CRef< CSDB_UserHandler > m_Handler
IConnection * GetConn(void) const
CConnHolder(IConnection *conn, const CSDB_ConnectionParam ¶ms)
const CDB_Exception::SContext & GetContext(void) const
const list< string > & GetPrintOutput(void) const
Helper hook-up class that installs default logging/registry/locking (but only if they have not yet be...
void SetEncoding(EEncoding encoding)
void SetPassword(const string &passwd)
void SetDriverName(const string &name)
void SetParam(const string &key, const string &value)
void SetServerName(const string &name)
void SetDatabaseName(const string &name)
void SetUserName(const string &name)
void GetServersList(const string &validator_name, const string &service_name, list< string > *serv_list)
void WorkWithSingleServer(const string &validator_name, const string &service_name, const string &server)
CDataSourceInitializer(void)
void Connect(const CSDB_ConnectionParam ¶ms)
CRef< CConnHolder > m_Conn
const list< string > & GetPrintOutput(void) const
IConnection * GetConnection(void)
const CDB_Exception::SContext & GetContext(void) const
bool EverConnected() const
void SetTimeout(const CTimeout &timeout)
Database connection object.
void Close(void)
Close database object.
CDatabase & operator=(const CDatabase &db)
void Connect(void)
Explicitly (re)connect to the database server.
CSDBAPI::EDriver GetDriverVersion(void) const
Get the driver version.
CQuery NewQuery(void)
Get new CQuery object for this database.
CDatabase Clone(void)
Clone database object.
CBlobBookmark NewBookmark(const string &table_name, const string &column_name, const string &search_conditions, CBlobBookmark::EBlobType column_type=CBlobBookmark::eUnknown, ETriState has_legacy_type=eTriState_Unknown)
Get new CBlobBookmark object.
CBulkInsert NewBulkInsert(const string &table_name, int autoflush)
Get new CBulkInsert object.
EConnectionCheckMethod
How thoroughly IsConnected should actually check the connection.
CRef< CDatabaseImpl > m_Impl
Database implementation object.
CBlobStoreStatic * NewBlobStore(const string &table_name, TNewBlobStoreFlags flags=TNewBlobStoreFlags(0), size_t image_limit=1<< 24)
Get new CBlobStoreStatic object (to be owned by caller).
bool IsConnected(EConnectionCheckMethod check_method=eNoCheck)
Check if database object was already connected to database server.
CSDB_ConnectionParam m_Params
Database parameters.
void x_ConnectAsNeeded(const char *operation)
CDatabase(void)
Empty constructor of database object.
CRef< IDBConnectionFactory > GetConnectionFactory(void) const
Retrieve a connection factory.
static CDbapiConnMgr & Instance(void)
Get access to the class instance.
Incapsulate compile time information such as __FILE__, __LINE__, NCBI_MODULE, current function.
const CVariant * GetValue(void) const override
static CNcbiApplication * Instance(void)
Singleton method.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
ESP_ParamType GetParamType(void) const
CRef< CQueryFieldImpl > Detach(void) override
const vector< unsigned char > & AsVector(void) const override
CNcbiOstream & GetOStream(size_t blob_size, TBlobOStreamFlags flags) const override
CBlobBookmark GetBookmark(void) const override
CQueryBlobImpl(CQueryImpl *q, unsigned int col_num)
CNcbiIstream & AsIStream(void) const override
const CDB_Exception::SContext & x_GetContext(void) const
virtual CNcbiOstream & GetOStream(size_t blob_size, TBlobOStreamFlags flags) const
virtual CNcbiIstream & AsIStream(void) const
const CVariant * GetValue(void) const
virtual CRef< CQueryFieldImpl > Detach(void)
virtual const vector< unsigned char > & AsVector(void) const
CQueryFieldImpl(CQueryImpl *q, unsigned int col_num)
virtual CBlobBookmark GetBookmark(void) const
unsigned int GetRowNo(CQuery::EHowMuch how_much=CQuery::eAllResultSets) const
const list< string > & GetPrintOutput(void) const
void SetSql(CTempString sql)
ICallableStatement * m_CallStmt
unsigned int GetResultSetNo(void) const
void x_InitRSFields(void)
void ClearParameter(CTempString name)
unsigned int m_MaxRowCount
unsigned int GetMaxRowCount(void) const
void x_CheckCanWork(bool need_rs=false) const
void SetNullParameter(CTempString name, ESDB_Type type, ESP_ParamType param_type)
void x_SetOutParameter(const string &name, const CVariant &value)
void SetParameter(CTempString name, const T &value, ESDB_Type type, ESP_ParamType param_type)
CRef< CDatabaseImpl > m_DBImpl
int GetStatus(void) const
void x_InitBeforeExec(void)
void Execute(const CTimeout &timeout)
void ExecuteSP(CTempString sp, const CTimeout &timeout)
unsigned int GetMinRowCount(void) const
CDatabaseImpl * GetDatabase(void) const
void SetIgnoreBounds(bool is_ignore)
bool m_ReportedWrongRowCount
CQueryImpl(CDatabaseImpl *db_impl)
unsigned int m_MinRowCount
void x_ClearAllParams(void)
unsigned int GetTotalColumns(void) const
CRef< CDB_Exception::SContext > m_Context
string GetColumnName(unsigned int col) const
const CQuery::CField & GetParameter(CTempString name)
void ClearParameters(void)
IConnection * GetConnection(void)
const CQuery::CRow & GetRow(void) const
bool HasMoreResultSets(void)
bool m_RowUnderConstruction
void x_DetachAllFields(void)
ESDB_Type GetColumnType(unsigned int col) const
unsigned int m_CurRelRowNo
void RequireRowCount(unsigned int min_rows, unsigned int max_rows)
const CQuery::CField & GetColumn(const CDBParamVariant &col) const
void x_CheckRowCount(void)
bool IsFinished(CQuery::EHowMuch how_much=CQuery::eThisResultSet) const
void VerifyDone(CQuery::EHowMuch how_much=CQuery::eThisResultSet)
const CDB_Exception::SContext & x_GetContext(void) const
int GetRowCount(void) const
const CVariant & GetFieldValue(unsigned int col_num)
Class representing value in result set or output parameter of stored procedure.
CNcbiOstream & GetOStream(size_t blob_size, TBlobOStreamFlags flags=0) const
Get a blob output stream, on top of a cloned connection.
bool IsNull(void) const
Check if value is NULL.
bool AsBool(void) const
Get value as bool.
Int8 AsInt8(void) const
Get value as 8-byte integer.
const vector< unsigned char > & AsVector(void) const
Get value as vector of bytes.
Int4 AsInt4(void) const
Get value as 4-byte integer.
CNcbiIstream & AsIStream(void) const
Get value as input stream.
unsigned char AsByte(void) const
Get value as single byte.
CTime AsDateTime(void) const
Get value as CTime.
string AsString(void) const
Get value as UTF-8 string.
short AsShort(void) const
Get value as short integer.
double AsDouble(void) const
Get value as double.
CBlobBookmark GetBookmark(void) const
Get bookmark for the blob.
float AsFloat(void) const
Get value as float.
Iterator class doing main navigation through result sets.
ESDB_Type GetColumnType(unsigned int col) const
Get type of the column with given number in the current result set.
bool operator==(const CRowIterator &ri) const
Comparison of iterators.
unsigned int GetResultSetNo(void) const
Get number of currently active result set.
unsigned int GetTotalColumns(void) const
Get number of columns in the current result set.
const CDB_Exception::SContext & x_GetContext(void) const
CRowIterator(void)
Empty constructor of iterator.
const CRow & operator*(void) const
Get the full row. (The caller is welcome to keep a copy.)
CRowIterator & operator=(const CRowIterator &ri)
bool m_IsEnd
Flag showing whether this is constant pointer to the end or pointer to some particular row.
CRowIterator & operator++(void)
Advance iterator to the next row in the result set.
unsigned int GetRowNo(void) const
Get row number currently active.
string GetColumnName(unsigned int col) const
Get name of the column with given number in the current result set.
const CField & operator[](unsigned int col) const
Get column value by its number.
CRef< CQueryImpl > m_Query
Query iterator was created for.
A full row of result data.
void x_CheckColumnNumber(unsigned int col) const
CRef< SQueryRSMetaData > m_MetaData
ESDB_Type GetColumnType(unsigned int col) const
Get type of the column with given number in the row.
vector< CField > m_Fields
unsigned int GetTotalColumns(void) const
Get number of columns in the row.
const string & GetColumnName(unsigned int col) const
Get name of the column with given number in the row.
const CField & operator[](unsigned int col) const
Get column value by its number.
void x_Reset(CQueryImpl &q, IResultSet &rs)
const CDB_Exception::SContext & x_GetContext(void) const
Object used to execute queries and stored procedures on the database server and retrieve result sets.
bool HasMoreResultSets(void)
Check if any more result sets are available for reading.
CQuery & SetSql(CTempString sql)
Set current sql statement.
int GetStatus(void) const
Get return status of stored procedure.
CQuery & MultiSet(void)
Convert this query to not merge different result sets, i.e.
CRow GetTheOnlyRow(void)
Provides the only row for the executed query.
CQuery & ClearParameters(void)
Remove all parameters from parameter list.
unsigned int GetTotalColumns(void) const
Get total number of columns in the current result set.
EAllowLog
Allow transaction log (general, to avoid using bools).
@ eDisableLog
Disables log.
CRowIterator end(void) const
Get iterator pointing to the end of the current result set or to the end of all result sets (dependin...
ESDB_Type GetColumnType(unsigned int col) const
Get type of the column with given number in the current result set All columns are numbered starting ...
EHowMuch
Whether to consider just the current result set or all result sets, in MultiSet mode.
void VerifyDone(EHowMuch how_much=eThisResultSet)
Ensure that no unread rows or parameter results remain, and that the total number of rows satisfies a...
CRef< CQueryImpl > m_Impl
Query implementation object.
void Cancel(void)
Cancel the current statement or procedure call.
CQuery & SetNullParameter(CTempString name, ESDB_Type type, ESP_ParamType param_type=eSP_In)
Assign null value to the parameter.
CRowIterator begin(void) const
Start iterating through next result set.
const CField & GetParameter(CTempString name)
Get value of the parameter.
CQuery & ClearParameter(CTempString name)
Remove parameter with given name from parameter list.
CQuery & Execute(const CTimeout &timeout=CTimeout(CTimeout::eDefault))
Explicitly execute sql statement.
const list< string > & GetPrintOutput(void) const
Get any PRINT output from the latest procedure call (or statement).
void RequireRowCount(unsigned int n)
Indicate precisely how many rows the active query should return.
CQuery(void)
Empty constructor of query object.
CQuery & SetParameter(CTempString name, const string &value, ESDB_Type type=eSDB_String, ESP_ParamType param_type=eSP_In)
Assign string value to the parameter.
unsigned int GetRowNo(EHowMuch how_much=eAllResultSets) const
Get row number currently active.
CQuery & ExecuteSP(CTempString sp, const CTimeout &timeout=CTimeout(CTimeout::eDefault))
Execute stored procedure with given name.
int GetRowCount(void) const
Get number of rows read after statement execution.
unsigned int GetResultSetNo(void) const
Get number of currently active result set.
void PurgeResults(void)
Purge all remaining result sets; fill in all remaining parameter results.
CQuery & SingleSet(void)
Convert this query to work like only one result set was returned effectively merging all result sets ...
string GetColumnName(unsigned int col) const
Get name of the column with given number in the current result set.
CQuery & operator=(const CQuery &q)
@ fLogExceptions
Exceptions logged only.
@ fOwnWriter
Own the underlying writer.
CBlobBookmark GetBookmark(void) const override
const CDB_Exception::SContext & x_GetContext(void) const override
const CVariant * GetValue(void) const override
CNcbiOstream * GetOStream(size_t blob_size, TBlobOStreamFlags flags) const override
@ eMirror_Unavailable
All databases in the mirror are unavailable.
@ eMirror_Steady
Mirror is working on the same server as before.
@ eMirror_NewMaster
Switched to a new master.
static void UseDriver(EDriver driver)
Use the specified driver for all connections.
static EMirrorStatus UpdateMirror(const string &dbservice, list< string > *servers=NULL, string *error_message=NULL)
Check for master/mirror switch.
static CBlobStoreDynamic * NewBlobStore(const CSDB_ConnectionParam ¶m, const string &table_name, TNewBlobStoreFlags flags=TNewBlobStoreFlags(0), size_t image_limit=1<< 24)
Get new CBlobStoreDynamic object (to be owned by caller).
static bool Init(void)
Initialize SDBAPI.
static void SetApplicationName(const CTempString &name)
Report the specified application name to servers.
static string GetApplicationName(void)
Check SDBAPI's application name setting.
Convenience class to initialize database connection parameters from URL-like strings and/or applicati...
CSDB_ConnectionParam & Set(EParam param, const string &value, TSetFlags flags=0)
Set one of the "essential" database connection parameters, unless overridden in a configuration file.
static CRef< CSDB_Decryptor > GetGlobalDecryptor(void)
Get the current password decryptor, if any.
@ eService
Named service, interfaces-file alias, or raw server name, per http://ncbi.github.io/cxx-toolkit/pages...
@ eConnPoolAllowTempOverflow
@ ePort
DB server's port (when not using an alias or named service)
@ eContinueAfterRaiserror
void x_FillParamMap(void)
Populate m_ParamMap according to the current server or service name.
void x_FillLowerParams(CDBConnParamsBase *params) const
Fill parameters for low-level DBAPI from what is set here and in the configuration file.
static void SetGlobalDecryptor(CRef< CSDB_Decryptor > decryptor)
Use the specified password decryptor.
CUrl m_Url
URL storing all parameters set in code.
void x_FillBoolParam(CDBConnParamsBase *params, const string &name, EParam id) const
string ComposeUrl(TComposeUrlFlags flags=0) const
Compose database connection URL string out of this class.
static bool x_IsKnownArg(const string &name)
@ fThrowIfIncomplete
Throw an exception if missing any "essential" parameters.
string x_GetPassword() const
Determine what password to use, accounting for possible encryption or indirection.
void x_ReportOverride(const CTempString &name, CTempString code_value, CTempString reg_value) const
static const char * x_GetName(EParam param)
string Get(EParam param, EWithOverrides with_overrides=eWithoutOverrides) const
Get one of the "essential" database connection parameters.
void x_InitErrCode(CException::EErrCode err_code) override
Helper method for initializing error code.
void x_Init(const CDiagCompileInfo &info, const string &message, const CException *prev_exception, EDiagSev severity) override
Helper method for initializing exception data.
Database password decryptor.
virtual string x_GetKey(const CTempString &key_id)
virtual string x_Decrypt(const string &ciphertext, const string &key)
Exception class used throughout the API.
virtual const char * GetErrCodeString(void) const override
Translate from the error code value to its string representation.
void x_Assign(const CException &src) override
Helper method for copying exception data.
void x_Init(const CDiagCompileInfo &info, const string &message, const CException *prev_exception, EDiagSev severity) override
Helper method for initializing exception data.
CConstRef< CDB_Exception::SContext > m_Context
virtual ERetriable GetRetriable(void) const override
Retrieve info about ability to retry an action caused the exception.
@ eOutOfBounds
Conversion of string to integer type exceeded limits of requested type.
@ eWrongParams
Wrong parameters provided to the method.
@ eLowLevel
Exception from low level DBAPI was re-thrown with this exception class.
@ eInconsistent
Operation logically incorrect is attempted to be made (increase past end() iterator,...
@ eStarted
CBulkInsert has already started to send data, no changes in meta-information can be made.
@ eNotExist
Field/parameter with given name/position does not exist.
@ eClosed
CDatabase/CQuery/CBulkInsert is tried to be used when no connection is opened.
@ eURLFormat
Incorrectly formated URL is used to create CSDB_ConnectionParam.
@ eUnsupported
Unsupported data type conversion is requested.
@ eNotInOrder
Columns cannot be bound to CBulkInsert randomly.
void ReportExtra(ostream &os) const override
Report "non-standard" attributes.
bool HandleIt(CDB_Exception *ex)
Handle the exceptions resulting from a native API call, one-by-one.
bool HandleMessage(int severity, int msgnum, const string &message)
Handle message resulting from a native API call.
static const TFlags kDefaults
@ fIsText
(N)TEXT or (N)VARCHAR(MAX)
@ fLogBlobs
Enable server-side logging.
@ fPreallocated
Don't create rows or clean up excess rows.
CTempString implements a light-weight string on top of a storage buffer whose lifetime management is ...
CTimeout – Timeout interval.
CUpdMirrorServerParams(const CDBConnParams &other)
virtual string GetServerName(void) const
virtual string GetPassword(void) const
virtual EEncoding GetEncoding(void) const
virtual string GetUserName(void) const
virtual Uint4 GetHost(void) const
const CDBConnParams & m_Other
~CUpdMirrorServerParams(void)
virtual string GetParam(const string &key) const
Parameters, which are not listed above explicitly, should be retrieved via SetParam() method.
virtual CRef< IConnValidator > GetConnValidator(void) const
virtual EServerType GetServerType(void) const
virtual Uint4 GetProtocolVersion(void) const
virtual string GetDatabaseName(void) const
virtual Uint2 GetPort(void) const
Writer-based output stream.