20 const char*
testchars=
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
30 Bool_t
feq(
const double&
a,
const double&
b)
33 return (fabs(a-b)<=a*0.0000001);
50 signed char i1()
const {
return (
signed char)(
fCnt%256 - 128); }
51 short i2()
const {
return (
short)(
fCnt%65536 - 32768); }
52 int i3()
const {
return (
int)(
fCnt%16777215-8388608); }
54 Long_t
i5()
const {
return ((Long_t)
fCnt)*1000000
L; }
55 float f1()
const {
return ((
float)
fCnt); }
56 float f2()
const {
return ((
float)
fCnt/10); }
57 double f3()
const {
return ((
double)
fCnt/20);}
58 Long_t
d1()
const {
return (((Long_t)
fCnt)-
fMax/2)*4567;}
60 TString
s3()
const {
return this->
s1(); }
61 TString
s2()
const {
char buf[41];
62 snprintf(buf,41,
"This is row number %d",
fCnt);
63 return TString_C(buf); }
64 TString
s4()
const {
return this->
s2(); }
67 return Date((time_t)
fCnt*10000);
71 return Time((time_t)
fCnt);
75 return Timestamp((time_t)
fCnt*10000);
109 #if !defined(ODBCXX_QT)
110 isstream*
s=
new isstream(
currentC,longtestSize);
112 QBuffer* s=
new QBuffer();
113 s->open(IO_WriteOnly);
114 s->writeBlock(
currentC,longtestSize);
116 s->open(IO_ReadOnly);
125 #if !defined(ODBCXX_QT)
126 isstream*
s=
new isstream(
currentB,longtestSize);
128 QBuffer* s=
new QBuffer();
129 s->open(IO_WriteOnly);
130 s->writeBlock(
currentB,longtestSize);
132 s->open(IO_ReadOnly);
144 #if !defined(ODBCXX_QT)
146 while(s1->get(c1) && s2->get(c2)) {
155 while((r1=s1->readBlock(buf1,1024))!=-1 &&
156 (r2=s2->readBlock(buf2,1024))!=-1) {
157 if(r1!=r2)
return false;
159 for(
int i=0;
i<
r1;
i++) {
161 if(buf1[
i]!=buf2[
i])
return false;
171 cout <<
"Creating tables:" <<
flush;
173 (
"create table odbctest ("
174 "i1 tinyint not null, "
175 "i2 smallint not null, "
176 "i3 mediumint not null, "
178 "i5 bigint not null, "
179 "f1 float(4) not null, "
180 "f2 float(8) not null, "
181 "f3 double(10,3) not null, "
182 "d1 decimal(20,5) not null, "
183 "s1 char(1) not null, "
184 "s2 char(40) not null, "
185 "s3 varchar(1) not null, "
186 "s4 varchar(40) not null, "
189 "ts datetime not null"
191 pstmt->executeUpdate();
192 cout <<
" odbctest" <<
flush;
196 (
"create table odbctest2 ("
200 pstmt->executeUpdate();
201 cout <<
" odbctest2" <<
flush;
212 cout <<
"Populating:" <<
flush;
215 (
"insert into odbctest(i1,i2,i3,i4,i5,f1,f2,f3,d1,s1,s2,s3,s4,dt,t,ts) "
216 "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
220 pstmt->setByte(1,vg.
i1());
221 pstmt->setShort(2,vg.
i2());
222 pstmt->setInt(3,vg.
i3());
223 pstmt->setInt(4,vg.
i4());
224 pstmt->setLong(5,vg.
i5());
225 pstmt->setFloat(6,vg.
f1());
226 pstmt->setFloat(7,vg.
f2());
227 pstmt->setDouble(8,vg.
f3());
228 pstmt->setLong(9,vg.
d1());
229 pstmt->setString(10,vg.
s1());
230 pstmt->setString(11,vg.
s2());
231 pstmt->setString(12,vg.
s3());
232 pstmt->setString(13,vg.
s4());
233 pstmt->setDate(14,vg.
dt());
234 pstmt->setTime(15,vg.
t());
235 pstmt->setTimestamp(16,vg.
ts());
236 pstmt->executeUpdate();
243 (
"insert into odbctest2(id,c,b) values(?,?,?)");
247 pstmt->setInt(1,vg2.
id());
253 pstmt->executeUpdate();
260 pstmt->setInt(1,vg2.
id()+1);
261 pstmt->setNull(2,Types::LONGVARCHAR);
262 pstmt->setNull(3,Types::LONGVARBINARY);
263 pstmt->executeUpdate();
275 cout <<
"Checking:" <<
flush;
277 Statement* stmt=con->createStatement();
278 stmt->setFetchSize(37);
279 ResultSet* rs=stmt->executeQuery
280 (
"select i1,i2,i3,i4,i5,f1,f2,f3,d1,s1,s2,s3,s4,dt,t,ts from odbctest");
282 cout <<
" odbctest" <<
flush;
286 while(rs->Next() && vg.
Next()) {
292 vg.
i1()==rs->GetByte(
"i1"));
294 vg.
i2()==rs->GetShort(
"i2"));
296 vg.
i3()==rs->GetInt(
"i3"));
298 vg.
i4()==rs->GetInt(
"i4"));
300 vg.
i5()==rs->GetLong(
"i5"));
303 feq(vg.
f1(),rs->GetFloat(
"f1")));
305 feq(vg.
f2(),rs->GetFloat(
"f2")));
307 feq(vg.
f3(),rs->GetDouble(
"f3")));
310 vg.
d1()==rs->GetLong(
"d1"));
313 && vg.
s1()==rs->GetString(
"s1"));
314 Assert(vg.
s2()==rs->GetString(11) &&
315 vg.
s2()==rs->GetString(
"s2"));
316 Assert(vg.
s3()==rs->GetString(12) &&
317 vg.
s3()==rs->GetString(
"s3"));
318 Assert(vg.
s4()==rs->GetString(13) &&
319 vg.
s4()==rs->GetString(
"s4"));
321 Assert(vg.
dt().toString()==rs->GetString(14));
322 Assert(vg.
t().toString()==rs->GetString(15));
323 Assert(vg.
ts().toString()==rs->GetString(16));
330 cout <<
"(" << cnt <<
")" <<
flush;
332 stmt=con->createStatement();
333 stmt->setFetchSize(10);
334 rs=stmt->executeQuery(
"select id,c,b from odbctest2");
337 Assert(rs->GetFetchSize()==1);
341 cout <<
" odbctest2" <<
flush;
342 while(rs->Next() && vg2.Next()) {
344 Assert(vg2.id()==rs->GetInt(
"id"));
355 TBuffer*
tmp=rs->GetAsciiStream(
"c");
357 tmp=rs->GetBinaryStream(
"b");
361 cout <<
"(" << cnt <<
")" <<
flush;
374 (
"drop table "+tableName);
376 pstmt->executeUpdate();
377 }
catch(SQLException&
e) { r=
false; }
386 cout <<
"Dropping tables:" <<
flush;
388 cout <<
" odbctest" <<
flush;
392 cout <<
" odbctest2" <<
flush;
398 #include "../src/dtconv.h"
401 int main(
int argc,
char** argv)
403 if(argc!=2 && argc!=4) {
404 cerr <<
"Usage: " << argv[0] <<
" connect-string" << endl
405 <<
"or " << argv[0] <<
" dsn username password" << endl;
413 cout <<
"Connecting to " << argv[1] <<
"..." <<
flush;
416 cout <<
"Connecting to dsn=" << argv[1]
417 <<
", uid=" << argv[2]
418 <<
", pwd=" << argv[3] <<
"..." <<
flush;
421 cout <<
" done." << endl;
434 DriverManager::shutdown();
440 cout <<
"Apparently, this worked!" << endl;
444 }
catch(SQLException&
e) {
445 cerr << endl << e.getMessage() << endl;