📄 test2.cpp
字号:
void p16(int objects)
{
COCICache c(s1);
t_trans* objs = new t_trans[objects];
c.flush();
delete [] objs;
}
void q16_array_pin()
{
int ref_count = 1000;
COCICache c(s1);
//std::vector<COCIObject> objs(1000,COCIObject(s1, COCIType(s1,"O_T")));
//t_pers pers_objs[1000];
COCIObject o(s1, COCIType(s1, "O_T"));
int i = 1;
o.set("A1",i);
o.set("A2",i);
o.set("A3",i);
o.set("A4",i);
o.set("A5",i);
o.set("A6",i);
o.set("A7",i);
o.set("A8",i);
o.set("A9",i);
o.set("A10",i);
o.set("A11",i);
o.set("A12",i);
o.set("A13",i);
o.set("A14",i);
o.set("A15",i);
o.set("A16",i);
std::vector<COCIObject> objs;//(1000,o);
//t_trans trans_objs[1000];
std::vector<COCIRef> refs(ref_count,COCIRef(s1));
COCIStatement stmt(s1);
stmt = "select ref(r) from o r";
stmt.define(1,refs);
if(stmt.execute())
{
do
{
objs = COCIObject::array_pin(refs);
for(std::vector<COCIObject>::iterator itr = objs.begin(); itr != objs.end(); itr++)
{
o = *itr;
int a16 = o.get("A16");
//cout << a16 << endl;
}
}while(stmt.fetch());
}
}
void q16_select()
{
int ref_count = 1000;
COCICache c(s1);
//std::vector<COCIObject> objs(1000,COCIObject(s1, COCIType(s1,"O_T")));
//t_pers pers_objs[1000];
COCIObject o(s1, COCIType(s1, "O_T"));
int i = 1;
o.set("A1",i);
o.set("A2",i);
o.set("A3",i);
o.set("A4",i);
o.set("A5",i);
o.set("A6",i);
o.set("A7",i);
o.set("A8",i);
o.set("A9",i);
o.set("A10",i);
o.set("A11",i);
o.set("A12",i);
o.set("A13",i);
o.set("A14",i);
o.set("A15",i);
o.set("A16",i);
std::vector<COCIObject> objs;//(1000,o);
//t_trans trans_objs[1000];
std::vector<COCIRef> refs(ref_count,COCIRef(s1));
COCIStatement stmt(s1);
stmt = "select ref(r),a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15,a16 from o r";
std::vector<int> a1(1000,0);
std::vector<int> a2(1000,0);
std::vector<int> a3(1000,0);
std::vector<int> a4(1000,0);
std::vector<int> a5(1000,0);
std::vector<int> a6(1000,0);
std::vector<int> a7(1000,0);
std::vector<int> a8(1000,0);
std::vector<int> a9(1000,0);
std::vector<int> a10(1000,0);
std::vector<int> a11(1000,0);
std::vector<int> a12(1000,0);
std::vector<int> a13(1000,0);
std::vector<int> a14(1000,0);
std::vector<int> a15(1000,0);
std::vector<int> a16(1000,0);
stmt.define(1,refs);
stmt.define(2,a1);
stmt.define(3,a2);
stmt.define(4,a3);
stmt.define(5,a4);
stmt.define(6,a5);
stmt.define(7,a6);
stmt.define(8,a7);
stmt.define(9,a8);
stmt.define(10,a9);
stmt.define(11,a10);
stmt.define(12,a11);
stmt.define(13,a12);
stmt.define(14,a13);
stmt.define(15,a14);
stmt.define(16,a15);
stmt.define(17,a16);
if(stmt.execute())
{
do
{
int count = 0;
objs = COCIObject::array_pin(refs);
for(std::vector<COCIObject>::iterator itr = objs.begin(); itr != objs.end(); itr++)
{
int a16 = itr->get("A16");
cout << a16 << " : " << refs[count].to_hex().c_str() << endl;
count++;
}
/*for(int i = 0; i < stmt.rows_fetched(); i++)
{
cout << a16[i] << " : " << refs[i].to_hex().c_str() << endl;
}*/
}while(stmt.fetch());
}
}
void plsql()
{
COCIStatement stmt(s1);
stmt = "BEGIN\
DECLARE\
my_exception EXCEPTION;\
BEGIN\
RAISE my_exception;\
EXCEPTION\
WHEN my_exception THEN\
NULL;\
END;\
END;";
stmt.execute();
stmt = "BEGIN\
DECLARE\
my_exception EXCEPTION;\
BEGIN\
RAISE my_exception;\
END;\
END;";
try
{
stmt.execute();
}
catch(CBaseException& exc)
{
char* buff = exc.GetError();
cout << "Errortext: " << buff << endl;
}
}
void test_date(COCIDate d, char* what)
{
cout << endl << what << endl;
// create table null_date (d date);
COCITransaction t(s1);
COCIStatement stmt(s1);
// Clean the table
cout << "Clean table" << endl;
stmt = "delete null_date";
stmt.execute();
t.commit();
cout << "insert value" << endl;
stmt = "insert into null_date values (:d)";
stmt.bind(":d",d);
stmt.execute();
t.commit();
cout << "Retrieve number of values" << endl;
stmt = "select count(*) from null_date";
int cnt = 0;
stmt.define(1,cnt);
stmt.execute();
cout << "Number of date(s) in null_date Count = " << cnt << endl;
t.commit();
cout << "Determine value of retrieved values" << endl;
stmt = "select d from null_date";
COCIDate d2(s1);
stmt.define(1,d2);
stmt.execute();
if(d2.is_null())
{
cout << "Date is null\n";
}
else
{
cout << "Date is not null\n";
}
}
void tt()
{
// clean
/* stmt = "delete null_date";
stmt.execute();
t.commit();
COCIDate d3(s1);
d3 = COCIDate::sys_date(s1);
stmt = "insert into null_date values (:1)";
stmt.bind(1,d3);
stmt.execute();
stmt = "select count(*) from null_date";
cnt = 0;
stmt.define(1,cnt);
stmt.execute();
cout << "Count = " << cnt << " (Expected 1) " << endl;
t.commit();
stmt = "select d from null_date";
COCIDate d4(s1);
stmt.define(1,d4);
stmt.execute();
if(d4.is_null())
{
cout << "Date is null (Not expected)\n";
}
else
{
cout << "Date is not null (Expected)\n";
}
/*COCIObject d(s1, COCITable(s1, "D"), COCIType(s1, "D_T"));
COCIDate dob(s1);
//dob = COCIDate::sys_date(s1);
d.set("dob",dob);
d.flush();*/
/*COCIObject s(s1, COCITable(s1, "S"), COCIType(s1, "S_T"));
COCIString str(s1);
str = "Hello";
s.set("str",str);
s.flush();*/
/*COCIObject n(s1, COCITable(s1, "N"), COCIType(s1, "N_T"));
COCINumber num(s1);
//num = 10;
n.set("id",num);
n.flush();*/
/* COCIObject x(s1, COCITable(s1, "X"), COCIType(s1, "X_T"));
COCIObject y(s1, COCITable(s1, "Y"), COCIType(s1, "Y_T"));
//x.set("Y",y.get_ref());
y.set("X",x.get_ref());
x.flush();
y.flush(); */
}
void lb()
{
COCITransaction t(s1);
COCIObject a(s1, COCITable(s1, "A"), COCIType(s1, "A_T"));
a.set("str","x");
std::vector<COCIObject> a_objs(999,a);
COCIObject c(s1, COCITable(s1, "C"), COCIType(s1, "C_T"));
c.set("str","z");
std::vector<COCIObject> c_objs(999,c);
std::vector<COCIObject> b_objs(1000,COCIObject(s1, COCITable(s1, "B"), COCIType(s1,"B_T")));
int i = 0;
for(std::vector<COCIObject>::iterator itr = b_objs.begin(); itr != b_objs.end(); itr++)
{
itr->set("str","y");
itr->set("a",a_objs[i].get_ref());
itr->set("c",c_objs[i].get_ref());
}
t.commit();
}
void lb2()
{
COCITransaction t(s1);
COCIStatement stmt(s1);
stmt = "insert into weight values(1,'xxx','m$oft',1)";
stmt.execute();
stmt = "insert into fraudentity values('xxx',1,null,null,null,null,'xxx',null,null,'xxx',sysdate,null,'xxx',sysdate,null,null,null,null,null,null,null)";
stmt.execute();
stmt = "insert into businessname values (1,null,null,null,'xxx',1,'xxx','xxx','xxx','uk',1,'m$oft','xxx','xxx','xxx','N')";
stmt.execute();
stmt = "insert into serialnumber values (1,'xxx','m$oft','xxx',1,'xxx','xxx',1,'xxx','N')";
stmt.execute();
stmt = "insert into identification values (1,1,'m$oft','xxx','xxx','xxx',1,'xxx','uk',null,'xxx','N')";
stmt.execute();
stmt = "insert into telecomnumber values (1,'xxx',1,'uk','xxx',1,'m$oft','xxx',null,null,null,'xxx',null,'xxx','N')";
stmt.execute();
stmt = "insert into creditcard values(1,'xxx',1,'xxx','xxx','m$oft','xxx',1,'xxx','N')";
stmt.execute();
stmt = "insert into address values(1,'xxx',1,'xxx',null,null,'xxx',1,'m$oft','xxx','xxx',null,null,null,null,null,null,null,null,null,null,null,null,'uk',null,'xxx','xxx','N')";
stmt.execute();
t.commit();
}
void delobj()
{
COCITransaction t(s1);
t.start();
COCIObject m(s1, COCITable(s1, "m"), COCIType(s1, "m_t"));
m.set("id",666);
std::vector<COCIObject> objs(999, m);
t.commit();
t.start();
COCIStatement stmt(s1);
stmt = "delete m";
stmt.execute();
t.commit();
}
void _1to1()
{
COCIStatement stmt1(s1);
COCIStatement stmt2(s1);
stmt1 = "insert into a values (1,:b_b_id,10)";
stmt2 = "insert into b values (1,:b_b_id,10)";
}
void lb3(char* corp, char* codei)
{
COCINumber code(s1);
COCIString type(s1);
type.resize(6);
COCIString corporation(s1);
corporation.resize(6);
COCINumber value(s1);
COCIStatement stmt(s1);
stmt = "select code,type,corporation,value from weight where corporation = :corp and code = :code";
stmt.define(1,code);
stmt.define(2,type);
stmt.define(3,corporation);
stmt.define(4,value);
COCIString corp_input(s1);
corp_input.resize(6);
corp_input = corp;
stmt.bind(":corp",corp_input);
COCINumber code_input(s1);
code_input = atoi((const char*)codei);
stmt.bind(":code",code_input);
if(stmt.execute())
{
do
{
cout << (int)code << " : " << type << " : " << corporation << " : " << (int)value << endl;
}while(stmt.fetch());
}
}
void std_string()
{
// DDL
// create table std_string(str varchar2(20));
// insert into std_string values ('01234567890123456789');
COCIString str(s1);
str.resize(20);
COCIStatement stmt(s1);
stmt = "select str from std_string";
//signed short is_null = 0;
stmt.define(1,str/*,&is_null*/);
stmt.execute();
cout << str.get_text() << endl;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -