m_UseSampleDatabase(sd),
84m_UseSvcMapper(
false)
91 #ifdef NCBI_DLL_SUPPORT 101 #ifdef HAVE_LIBSYBASE 159arg_desc->SetUsageContext(
GetArguments().GetProgramBasename(),
160 "DBAPI Sample Application");
163 #define FTDS_DRIVERS "ftds", "ftds100", "ftds14"
165 #if defined(NCBI_OS_MSWIN) 166 #define DEF_SERVER "MSDEV1" 167 #define DEF_DRIVER "ftds" 168 #define ALL_DRIVERS "ctlib", FTDS_DRIVERS, "gateway", "odbc"
169 #elif defined(HAVE_LIBSYBASE) 170 #define DEF_SERVER "DBAPI_DEV16_2K" 171 #define DEF_DRIVER "ctlib" 172 #define ALL_DRIVERS "ctlib", FTDS_DRIVERS, "gateway", "odbc"
174 #define DEF_SERVER "MSDEV1" 175 #define DEF_DRIVER "ftds" 176 #define ALL_DRIVERS FTDS_DRIVERS, "gateway", "odbc"
179arg_desc->AddDefaultKey(
"S",
"server",
180 "Name of the SQL server to connect to",
183arg_desc->AddDefaultKey(
"d",
"driver",
184 "Name of the DBAPI driver to use",
189arg_desc->AddDefaultKey(
"U",
"username",
193arg_desc->AddDefaultKey(
"P",
"password",
197arg_desc->AddOptionalKey(
"v",
"version",
198 "TDS protocol version",
201arg_desc->AddDefaultKey(
"lb",
"use_load_balancer",
202 "Use load balancer for service mapping",
205 "on",
"off",
"random"));
232 stringservice_mapping = args[
"lb"].AsString();
233 if(service_mapping ==
"on") {
235}
else if(service_mapping ==
"random") {
237 static CRandomrdm_gen(rdm_seed);
243 LOG_POST_X(1,
"Using load-balancer service to server mapper ...");
289<< err_msg <<
"] ");
300 const string& pool_name)
302unique_ptr<CDB_Connection>
conn;
322 if( !
conn.get() ) {
328 string sql(
"select @@servername");
330unique_ptr<CDB_LangCmd>
stmt(
conn->LangCmd(
sql));
333 while(
stmt->HasMoreResults() ) {
334unique_ptr<CDB_Result>
result(
stmt->Result());
349 conn->SetDatabaseName(
"DBAPI_Sample");
352 return conn.release();
374 string sql=
"select name from sysobjects WHERE type = 'U'";
375 typedeflist<string> table_name_list_t;
376table_name_list_t table_name_list;
377table_name_list_t::const_iterator citer;
382 while( lcmd->HasMoreResults() ) {
384unique_ptr<CDB_Result>
r(lcmd->Result());
385 if( !
r.get() )
continue;
388 while(
r->Fetch() ) {
393 r->GetItem(&str_val);
395 if( str_val.
IsNULL() )
continue;
396 stringtable_creation_date;
398string::size_type pos =
table_name.find_last_of(
'_');
400 if( pos == string::npos )
continue;
401table_creation_date =
table_name.substr(pos + 1);
404 CTimecreation_date(table_creation_date,
"MDy");
418 for(citer = table_name_list.begin(); citer != table_name_list.end(); ++citer)
430 while( lcmd->HasMoreResults() ) {
431unique_ptr<CDB_Result>
r(lcmd->Result());
436 while(
r->Fetch() ) {
438 for(
unsigned intj = 0; j <
r->NofItems(); j++ ) {
440 const stringiname =
r->ItemName(j);
441cout << '<' << iname << '>
'; 442 if ( rt == eDB_Char || rt == eDB_VarChar ) { 448 cout << v.AsString(); 450 } else if ( rt == eDB_Int || 451 rt == eDB_SmallInt || 452 rt == eDB_TinyInt ) { 460 } else if ( rt == eDB_Float ) { 468 } else if ( rt == eDB_Double ) { 476 } else if ( rt == eDB_DateTime || 477 rt == eDB_SmallDateTime ) { 483 cout << v.Value().AsString(); 485 } else if ( rt == eDB_Numeric ) { 493 } else if ( CDB_Object::IsBlobType(rt) ) { 494 unique_ptr<CDB_Stream> v 495 (static_cast<CDB_Stream*>(CDB_Object::Create(rt))); 497 cout << '{
' << CDB_Object::GetTypeName(rt) << " (" 498 << v->Size() << " bytes)}"; 499 } else if ( rt == eDB_Image ) { 502 cout << "{image (" << v.Size() << " bytes)}"; 505 cout << "{unprintable}"; 507 cout << "</" << iname << '>
'; 509 cout << "</ROW>" << endl << endl; 517 CDbapiSampleApp::CreateTable (const string& table_name) 521 // Drop a table with same name. 522 sql = string(" IF EXISTS (select * from sysobjects WHERE name = '"); 523 sql += table_name + "' AND type = 'U') begin "; 524 sql += " DROP TABLE " + table_name + " end "; 526 unique_ptr<CDB_LangCmd> lcmd(GetConnection().LangCmd (sql)); 530 // Create a new table. 531 sql = " create table " + table_name + "( \n"; 532 sql += " int_val int not null, \n"; 533 sql += " fl_val real not null, \n"; 534 sql += " date_val datetime not null, \n"; 535 sql += " str_val varchar(255) null, \n"; 536 sql += " txt_val text null \n"; 537 // sql += " primary key clustered(int_val) \n"; 540 lcmd.reset(GetConnection().LangCmd ( sql )); 547 CDbapiSampleApp::GetConnection(void) 549 if ( !m_Connection.get() ) { 550 m_Connection.reset(CreateConnection()); 553 return *m_Connection; 558CDbapiSampleErrHandler::CDbapiSampleErrHandler(void)
562CDbapiSampleErrHandler::~CDbapiSampleErrHandler(void)
566// Return TRUE if "ex" is processed, FALSE if not (or if "ex" is NULL)
568CDbapiSampleErrHandler::HandleIt(CDB_Exception* ex)
573// Ignore errors with ErrorCode set to 0
574// (this is related mostly to the FreeTDS driver)
575if (ex->GetDBErrCode() == 0)
578// On other errors, throw an exception (was not allowed before!)
EUseSampleDatabase m_UseSampleDatabase
virtual void ExitSample(void)
virtual void Exit()
Cleanup on application exit.
void DeleteTable(const string &table_name)
virtual void Init()
Initialize the application.
I_DriverContext & GetDriverContext(void)
Get the driver context (for the driver specified in the command line)
const string & GetServerName(void) const
Return current server name.
virtual int RunSample(void)=0
virtual int Run()
Run the application.
CDB_Connection * CreateConnection(IConnValidator *validator=NULL, I_DriverContext::TConnectionMode mode=I_DriverContext::fBcpIn, bool reusable=false, const string &pool_name=kEmptyStr)
Create new connection using server, username and password specified in the application command line.
virtual ~CDbapiSampleApp(void)
virtual void InitSample(CArgDescriptions &arg_desc)
Override these 3 to suit your test's needs.
void SetDatabaseParameter(const string &name, const string &value)
Set database connection parameter.
bool UseSvcMapper(void) const
const string & GetDriverName(void) const
Return current driver name.
void DeleteLostTables(void)
Delete tables which are lost after previous tests.
unique_ptr< I_DriverContext > m_DriverContext
const string & GetPassword(void) const
Return current password.
CDbapiSampleApp(EUseSampleDatabase sd=eUseSampleDatabase)
const TDatabaseParameters & GetDatabaseParameters(void) const
Return database conection parameters.
const string & GetUserName(void) const
Return current user name.
CDB_Connection & GetConnection(void)
Get connection created using server, username and password specified in the application command line.
EServerType GetServerType(void) const
Return current server type.
void ShowResults(const string &query)
Delete table if it exists ShowResults is printing resuts on screen.
Lightweight representation of just a host and a port.
static SSystemFastMutex & GetMutex(void)
#define DBLB_INSTALL_DEFAULT()
Easy-to-use macro to install the default DBAPI service mapper.
static CS_CONNECTION * conn
static const char table_name[]
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
@ eString
An arbitrary string.
@ eInteger
Convertible into an integer number (int or Int8)
void DBAPI_RegisterDriver_FTDS(void)
void DBAPI_RegisterDriver_FTDS14(void)
void DBAPI_RegisterDriver_CTLIB(void)
void DBAPI_RegisterDriver_FTDS100(void)
void DBAPI_RegisterDriver_ODBC(void)
I_DriverContext * GetDriverContext(const string &driver_name, string *err_msg=0, const map< string, string > *attr=0)
static CDB_UserHandler & GetDefault(void)
virtual bool HandleIt(CDB_Exception *ex)=0
Handle the exceptions resulting from a native API call, one-by-one.
CDB_Connection * Connect(const string &srv_name, const string &user_name, const string &passwd, TConnectionMode mode, bool reusable=false, const string &pool_name=kEmptyStr)
Create new connection to specified server (or service) within this context.
CDB_Connection * ConnectValidated(const string &srv_name, const string &user_name, const string &passwd, IConnValidator &validator, TConnectionMode mode=0, bool reusable=false, const string &pool_name=kEmptyStr)
Create new connection to specified server (within this context).
const string & AsString(void) const
#define LOG_POST_X(err_subcode, message)
#define ERR_POST_X(err_subcode, message)
Error posting with default error code and given error subcode.
void Fatal(CExceptionArgs_Base &args)
static void EnableGlobally(bool enable=true)
Enable (or disable, if called with enable = false) loading plugins from DLLs in general.
uint32_t Uint4
4-byte (32-bit) unsigned integer
static TPid GetPid(void)
Get process identifier (pid) for the current process.
TValue GetRand(void)
Get the next random number in the interval [0..GetMax()] (inclusive)
static string GetLocalHost(void)
Get local (current) host name (uname call).
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
static string TruncateSpaces(const string &str, ETrunc where=eTrunc_Both)
Truncate whitespace in a string.
string AsString(const CTimeFormat &format=kEmptyStr, TSeconds out_tz=eCurrentTimeZone) const
Transform time to string.
@ eCurrent
Use current time. See also CCurrentTime.
Definition of all error codes used in dbapi libraries (dbapi_driver.lib and others).
Parameters initialization model.
Defines process management classes.
Defines command line argument related classes.
Defines unified interface to application:
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
Resolve host name to ip address and back using preset ini-file.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4