(
void);
71 virtual int Run(
void);
104 "SDBAPI simple operations demo");
107argdesc->
AddDefaultKey(
"user_string1",
"UserString1",
"A user-supplied " 108 "string to be used in one of the demonstrations " 109 "(could contain a SQL injection attempt)",
112argdesc->
AddDefaultKey(
"user_string2",
"UserString2",
"Another " 113 "user-supplied string to be used in one of the " 114 "demonstrations (could contain a SQL injection " 118argdesc->
AddDefaultKey(
"user_string3",
"UserString3",
"Yet another " 119 "user-supplied string to be used in one of the " 120 "demonstrations (could contain a SQL injection " 133argdesc->
AddPositional(
"pw_file",
"File containing database user password",
173 m_Service= args[
"service"].AsString();
174 m_DbName= args[
"db_name"].AsString();
175 m_User= args[
"user"].AsString();
176 m_PwFile= args[
"pw_file"].AsString();
232 stringproc_name(
"sdbapi_simple_sproc");
237 query.SetParameter(
"@max_id", 5);
238 query.SetParameter(
"@max_fl", 5.1f);
242cout <<
"\nExecuting stored proc \""<< proc_name <<
"\":"<< endl;
243 query.ExecuteSP(proc_name);
250cout <<
"int_val fl_val"<< endl;
251 for(
const auto&
row:
query.SingleSet()) {
252cout <<
row[1].AsInt4() <<
" " 253<<
row[2].AsFloat() << endl;
260cout <<
"Number of rows: "<<
query.GetParameter(
"@num_rows").AsInt4() << endl;
278 string sql(
"SELECT [title] FROM [Journal]");
281cout <<
"\nExecuting static SQL \""<<
sql<<
"\":"<< endl;
290cout <<
"title"<< endl;
291 for(
const auto&
row:
query.SingleSet()) {
292cout <<
row[1].AsString() << endl;
314 stringuser_last = args[
"user_string1"].AsString();
315 stringuser_salary = args[
"user_string2"].AsString();
316 stringuser_hire = args[
"user_string3"].AsString();
319 string sql(
" SELECT [id], [last], [first], [salary], [hiredate]" 320 " FROM [Employee] WHERE [last] LIKE @last" 321 " AND [salary] > @salary" 322 " AND [hiredate] > @hire");
326 query.SetParameter(
"@last", user_last);
327 query.SetParameter(
"@salary", user_salary);
328 query.SetParameter(
"@hire", user_hire);
331cout <<
"\nExecuting parameterized SQL \""<<
sql<<
"\":"<< endl;
340cout <<
"id last first salary hiredate"<< endl;
341 for(
const auto&
row:
query.SingleSet()) {
342cout <<
row[1].AsInt4() <<
" " 343<<
row[2].AsString() <<
" " 344<<
row[3].AsString() <<
" " 345<<
row[4].AsInt4() <<
" " 346<<
row[5].AsString() << endl;
374 stringuser_last = args[
"user_string1"].AsString();
375 stringuser_salary = args[
"user_string2"].AsString();
376 stringuser_hire = args[
"user_string3"].AsString();
387 string sql(
" SELECT [id], [last], [first], [salary], [hiredate]" 388 " FROM [Employee] WHERE [last] LIKE "+ user_last +
389 " AND [salary] > "+ user_salary +
390 " AND [hiredate] > "+ user_hire);
393cout <<
"\nExecuting dynamic SQL \""<<
sql<<
"\":"<< endl;
403cout <<
"id last first salary hiredate"<< endl;
404 for(
const auto&
row:
query.SingleSet()) {
405cout <<
row[1].AsInt4() <<
" " 406<<
row[2].AsString() <<
" " 407<<
row[3].AsString() <<
" " 408<<
row[4].AsInt4() <<
" " 409<<
row[5].AsString() << endl;
427 stringuser_input = args[
"user_string1"].AsString();
431 string sql(
" SELECT [id], [last], [first], [salary], [hiredate]" 432 " FROM [Employee] WHERE [last] LIKE '"+ user_input +
"'");
Database connection object.
void Connect(void)
Explicitly (re)connect to the database server.
CQuery NewQuery(void)
Get new CQuery object for this database.
Object used to execute queries and stored procedures on the database server and retrieve result sets.
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.
@ eService
Named service, interfaces-file alias, or raw server name, per http://ncbi.github.io/cxx-toolkit/pages...
void DemoSqlInjection(void)
void DemoStoredProc(void)
void DemoParamerizedSql(void)
virtual void Init(void)
Initialize the application.
virtual int Run(void)
Run the application.
void DemoDynamicSql(void)
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
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.
void SetUsageContext(const string &usage_name, const string &usage_description, bool usage_sort_args=false, SIZE_TYPE usage_width=78)
Set extra info to be used by PrintUsage().
void AddPositional(const string &name, const string &comment, EType type, TFlags flags=0)
Add description for mandatory positional argument.
void AddDefaultKey(const string &name, const string &synopsis, const string &comment, EType type, const string &default_value, TFlags flags=0, const string &env_var=kEmptyStr, const char *display_value=nullptr)
Add description for optional key with default value.
@ eString
An arbitrary string.
static CStringUTF8 SQLEncode(const CStringUTF8 &str, ESqlEncode flag)
SQL-encode string.
static CStringUTF8 AsUTF8(const CTempString &src, EEncoding encoding, EValidate validate=eNoValidate)
Convert into UTF8 from a C/C++ string.
static string UIntToString(unsigned int value, TNumToStringFlags flags=0, int base=10)
Convert UInt to string.
static unsigned int StringToUInt(const CTempString str, TStringToNumFlags flags=0, int base=10)
Convert string to unsigned int.
@ eEncoding_ISO8859_1
Note: From the point of view of the C++.
@ eSqlEnc_TagNonASCII
Produce N'...' when input's not pure ASCII.
string AsString(const CTimeFormat &format=kEmptyStr, TSeconds out_tz=eCurrentTimeZone) const
Transform time to string.
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines command line argument related classes.
@ eSDB_Int4
Like Transact-SQL INT (signed 32-bit integer)
@ eSP_InOut
Parameter can be returned from stored procedure.
int NcbiSys_main(int argc, ncbi::TXChar *argv[])
#define row(bind, expected)
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