117 #include <TStopwatch.h>
137 class MySQLRow: public TSQLRow
145 ULong_t *fFieldLength;
149 fResult = (MYSQL_RES *) res;
150 fFields = (MYSQL_ROW)fResult->current_row;
154 MySQLRow*
Set(
void *res)
156 fResult = (MYSQL_RES *) res;
157 fFields = (MYSQL_ROW)fResult->current_row;
167 void Close(Option_t *opt=
"")
171 if (!fFields)
return;
187 if (field < 0 || field >= (Int_t)mysql_num_fields(fResult)) {
194 ULong_t GetFieldLength(Int_t field)
201 fFieldLength = mysql_fetch_lengths(fResult);
208 return fFieldLength[
field];
211 const char* GetField(Int_t field)
217 return fFields[
field];
285 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
290 return imp->
fMYSQL_RES->current_row[columnIndex-1];
313 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
318 const char*
str = imp->
fMYSQL_RES->current_row[columnIndex-1];
320 return ( str && strlen(str) ) ?
321 (str[0] ==
't') || (str[0] ==
'T') ||
322 (str[0] ==
'y') || (str[0] ==
'Y') ||
323 (str[0] ==
'1') || (str[0] ==
'1') : kFALSE;
339 Char_t return_value = 0;
348 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
353 const char*
str = imp->
fMYSQL_RES->current_row[columnIndex-1];
355 switch( imp->MYSQL_RES->fields[column-1].type ) {
356 case FIELD_TYPE_DECIMAL:
357 case FIELD_TYPE_TINY:
358 case FIELD_TYPE_SHORT:
359 case FIELD_TYPE_LONG:
360 case FIELD_TYPE_FLOAT:
361 case FIELD_TYPE_DOUBLE:
362 case FIELD_TYPE_LONGLONG:
363 case FIELD_TYPE_INT24:
364 return (Char_t)atoi(str);
391 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
396 return (Short_t)atoi(imp->
fMYSQL_RES->current_row[columnIndex-1]);
419 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
424 return (Int_t)atoi(imp->
fMYSQL_RES->current_row[columnIndex-1]);
447 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
453 Int_t
length = strlen(value);
457 if( length >= 10 && value[4] ==
'-' && value[7] ==
'-' && (!value[10] || value[10] ==
' ') ) {
458 return ((Long_t) atol(value)*10000
L+(Long_t) atol(value+5)*100
L+(Long_t) atol(value+8));
460 return (Long_t)atol(value);
484 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
489 return (Float_t)atof(imp->
fMYSQL_RES->current_row[columnIndex-1]);
512 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
517 return (Double_t)atof(imp->
fMYSQL_RES->current_row[columnIndex-1]);
543 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
574 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
605 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
636 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
678 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
718 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
747 if( (UInt_t)(columnIndex-1) >= imp->
fMYSQL_RES->field_count ) {
753 obj = b->ReadObject(TObject::Class());
1082 !strcmp(columnName.Data(),imp->
fMYSQL_RES->fields[
i].name) ?
return i :;;
1101 return (!imp->
fMYSQL_RES->row_count) ? kFALSE : (fCurrentRow == -1);
1134 return (!imp->
fMYSQL_RES->row_count) ? kFALSE : (fCurrentRow == 0);
1198 imp->fRurrentRow = imp->
fMYSQL_RES->row_count;
1267 if (rows < 0 /* || rows > getMaxRows()*/) {
1268 throw new SQLException(
"Value must be between 0 and getMaxRows()",
"S1009");
1284 Int_t return_value = 0;
1286 return return_value;
1302 return return_value;
1318 Int_t return_value = 0;
1320 return return_value;
1338 Bool_t return_value = kFALSE;
1340 return return_value;
1358 Bool_t return_value = kFALSE;
1360 return return_value;
1379 Bool_t return_value = kFALSE;
1381 return return_value;
1666 TBuffer *
b =
new TBuffer(TBuffer::kWrite);
2131 return return_value ?
fRow->Set(
this) : 0;
2147 MySQLStatementPrivate* stmt = (MySQLStatementPrivate*)
fStatement->
fImp;
2157 if( !imp->
fMYSQL_RES->row_count ||
con->fMYSQL->status==MYSQL_STATUS_USE_RESULT )
return 0;
2197 throw new SQLException(
"Cannot absolute position to row 0",
"S1009");
2200 if (_on_insert_row) {
2201 _on_insert_row =
false;
2204 if (_doing_updates) {
2205 _doing_updates =
false;
2211 else if (row == -1) {
2215 if (row > Rows.size()) {
2223 int new_row_position = Rows.size() + row + 1;
2225 if (new_row_position <= 0) {
2231 return absolute(new_row_position);
2237 This_Row = (
byte[][])Rows.elementAt(currentRow);
2265 int new_row_position = currentRow + rows + 1;
2284 Bool_t return_value = kFALSE;
2286 return return_value ?
fRow->Set(
this) : 0;
2302 Bool_t return_value = kFALSE;
2303 return return_value ?
fRow->Set(
this) : 0;
2322 if( (column > imp->
fMYSQL_RES->field_count) || (column < 1) ) {
2323 return (set_stmt_error(stmt,
"S1002",
"Invalid column number",0));
2327 return imp->MYSQL_RES->fields[column-1].name;
2362 TString stropt = option;
2363 stropt.ReplaceAll(
" ",
"");
2366 t1 = stropt.Index(pattern.Data());
2367 t1 = t2 = stropt.Index(
"=",t1) + 1;
2368 TString
str = stropt(t1,1024);
2371 for(
int i=0;isdigit(tmp[
i])!=0;i++) t2=i+1;
2372 str = stropt(t1,t2);
2373 return atoi(str.Data());
2388 Warning(
"Print()",
"TSQLResultSet is destroyed\n");
2401 Int_t save_row =
GetRow();
2405 Int_t srow = save_row;
2409 TString stropt = option;
2412 if(stropt.Contains(
"begin")) {
2416 if (stropt.Contains(
"end")) {
2420 if (stropt.Contains(
"nrows")) {
2426 nn =
new Int_t[ncols+1];
2427 pd1 =
new Int_t[ncols+1];
2429 for(
int i=1;
i<ncols+1;
i++) {
2432 dl = colname.Length() + 2;
2433 nn[
i] = TMath::Max(dl,ds);
2438 for(
int i=1;
i<ncols+1;
i++) {
2439 cout <<
"+"; cout.fill(
'-'); cout.width(nn[
i]+1); cout <<
"+";
2442 for(
int i=1;
i<ncols+1;
i++) {
2444 cout <<
"| " << colname <<
" ";
2445 cout.fill(
' '); cout.width(pd1[
i]+1); cout <<
"|";
2449 for(
int i=1;
i<ncols+1;
i++) {
2450 cout <<
"+"; cout.fill(
'-'); cout.width(nn[
i]+1); cout <<
"+";
2460 while (
Next() && cur_row+2 < srow) cur_row =
GetRow();
2465 static TStopwatch timer;
2473 if(nrows > 0 && nr >= nrows)
break;
2474 if(erow > 0 && cur_row >= erow )
break;
2478 for(
int i=1;
i<ncols+1;
i++) {
2480 cout <<
"| " <<
str;
2481 pd2 = nn[
i] - str.Length();
2482 cout.fill(
' '); cout.width(pd2); cout <<
"|";
2486 for(
int i=1;
i<ncols+1;
i++) {
2487 cout <<
"+"; cout.fill(
'-'); cout.width(nn[
i]+1); cout <<
"+";
2491 Double_t rtime = timer.RealTime();
2493 cout << nr <<
" rows in set. ( Real time: " << rtime <<
" seconds )" << endl;
2499 Warning(
"Print",
"To set cursor to initial position -> re-execute Query.");
2532 Int_t yy,
mm, dd, hh, mi, ss;
2535 Int_t save_row =
GetRow();
2538 Int_t srow = begin > 0 ? begin : save_row;
2539 Int_t erow = end > 0 ? end : -1;
2552 for(
int i=1;
i <= ncollumns; ++
i ) {
2561 siz +=
sizeof(Int_t);
2566 siz +=
sizeof(UInt_t);
2571 siz +=
sizeof(Short_t);
2574 siz +=
sizeof(Float_t);
2586 siz +=
sizeof(Double_t);
2593 for(
int i=1;
i <= ncollumns; ++
i ) {
2601 sprintf(tmpstr,
"[%d]",prec);
2602 leafList += clmname + tmpstr +
"/C:";
2605 leafList += clmname +
"/I:";
2610 leafList += clmname +
"/i:";
2615 leafList += clmname +
"/S:";
2618 leafList += clmname +
"/F:";
2630 leafList += clmname +
"/D:";
2634 if(!leafList.IsNull()) leafList.Resize(leafList.Length()-1);
2638 buf =
new char[siz];
2642 if(tblname.IsNull()) {
2644 sprintf(tmpstr,
"%d",gRandom->Integer(1000));
2650 TTree*
tree =
new TTree(tblname.Data(),
"Created by TSQLResultSet:Tree() method");
2652 tree->Branch(tblname.Data(),(
void*)buf,leafList.Data());
2662 while (
Next() && cur_row+2 < srow) cur_row =
GetRow();
2671 if(erow>0 && cur_row >= erow)
break;
2674 for(
int i=1;
i <= ncollumns; ++
i ) {
2682 memcpy(&buf[offset],str.Data(),siz);
2685 siz =
sizeof(Int_t);
2687 memcpy(&buf[offset],&intg,siz);
2692 siz =
sizeof(Short_t);
2694 memcpy(&buf[offset],&shrt,siz);
2697 siz =
sizeof(Float_t);
2699 memcpy(&buf[offset],&flt,siz);
2704 siz =
sizeof(UInt_t);
2706 sscanf(str.Data(),
"%d-%d-%d %d:%d:%d",
2707 &yy, &
mm, &dd, &hh, &mi, &ss);
2708 tp.tm_year = yy-1900;
2715 t = (UInt_t)mktime(&tp);
2716 memcpy(&buf[offset],&t,siz);
2728 siz =
sizeof(Double_t);
2730 memcpy(&buf[offset],&dbl,siz);
2743 Warning(
"Print",
"To set cursor to initial position -> re-execute Query.");