|
MysqlResult.cxxGo to the documentation of this file.00001 // 00002 // Copyright (C) 2006 Christian Holm Christensen <cholm@nbi.dk> 00003 // 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public License 00006 // as published by the Free Software Foundation; either version 2.1 00007 // of the License, or (at your option) any later version. 00008 // 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free 00016 // Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00017 // 02111-1307 USA 00018 // 00019 // Note, some of this code is based on the ROOT MySQL interface 00020 // 00026 #include "MysqlResult.h" 00027 #include "MysqlRow.h" 00028 00029 //____________________________________________________________________ 00030 RcuDb::Mysql::Result::Result(MYSQL_RES* res) 00031 { 00032 fResult = res; 00033 fNRows = res ? mysql_num_rows(fResult) : 0; 00034 fInfo = 0; 00035 } 00036 00037 //____________________________________________________________________ 00038 void 00039 RcuDb::Mysql::Result::Close() 00040 { 00041 if (!fResult) return; 00042 mysql_free_result(fResult); 00043 fResult = 0; 00044 fInfo = 0; 00045 fNRows = 0; 00046 } 00047 00048 //____________________________________________________________________ 00049 const char* 00050 RcuDb::Mysql::Result::FieldName(int i) 00051 { 00052 if (!Validate(i)) return 0; 00053 if (!fInfo) fInfo = mysql_fetch_fields(fResult); 00054 if (!fInfo) return 0; // Bad 00055 return fInfo[i].name; 00056 } 00057 00058 //____________________________________________________________________ 00059 int 00060 RcuDb::Mysql::Result::NFields() 00061 { 00062 if (!fResult) return 0; 00063 return int(mysql_num_fields(fResult)); 00064 } 00065 00066 //____________________________________________________________________ 00067 RcuDb::Row* 00068 RcuDb::Mysql::Result::Next() 00069 { 00070 if (!fResult) return 0; 00071 MYSQL_ROW row = mysql_fetch_row(fResult); 00072 if (!row) return 0; 00073 return new Row(fResult, row); 00074 } 00075 00076 00077 //____________________________________________________________________ 00078 bool 00079 RcuDb::Mysql::Result::Validate(int i) 00080 { 00081 if (!fResult) return false; // Closed 00082 if (i < 0 || i >= NFields()) return false; 00083 return true; 00084 } 00085 // 00086 // EOF 00087 //
|