00001 /* 00002 MyMySQL++ - Another MySQL++ API providing basic and easy access to MySQL functionality. 00003 Copyright (C) 2003 Stefan Schadt 00004 00005 This program is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 This program is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with this program; if not, write to the Free Software 00017 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00028 #include "pch.h" 00029 #include "MyMySQLPPRow.h" 00030 00032 CMyMySQLPPRow::CMyMySQLPPRow(void) 00033 { 00034 Free(); 00035 } 00036 00041 CMyMySQLPPRow::CMyMySQLPPRow(MYSQL_ROW row, MYSQL_RES *res) 00042 { 00043 Attach(row, res); 00044 } 00045 00047 CMyMySQLPPRow::~CMyMySQLPPRow(void) 00048 { 00049 Free(); 00050 } 00051 00053 void CMyMySQLPPRow::Free(void) 00054 { 00055 m_row = NULL; 00056 m_res = NULL; 00057 } 00058 00063 void CMyMySQLPPRow::Attach(MYSQL_ROW row, MYSQL_RES *res) 00064 { 00065 Free(); 00066 m_row = row; 00067 m_res = res; 00068 } 00069 00073 unsigned int CMyMySQLPPRow::GetNumFields(void) 00074 { 00075 return mysql_num_fields(m_res); 00076 } 00077 00082 CMyMySQLPPTypeConv CMyMySQLPPRow::operator[](int idx) 00083 { 00084 if(m_row == NULL) 00085 return CMyMySQLPPTypeConv(); 00086 return CMyMySQLPPTypeConv(m_row[idx]); 00087 } 00088 00093 CMyMySQLPPTypeConv CMyMySQLPPRow::Get(int idx) 00094 { 00095 if(m_row == NULL) 00096 return CMyMySQLPPTypeConv(); 00097 return CMyMySQLPPTypeConv(m_row[idx]); 00098 } 00099 00104 CMyMySQLPPTypeConv CMyMySQLPPRow::operator[](char* name) 00105 { 00106 if((m_row == NULL) || (m_row == NULL)) 00107 return CMyMySQLPPTypeConv(); 00108 for(unsigned int i = 0; i < mysql_num_fields(m_res); i++) 00109 { 00110 MYSQL_FIELD *f = mysql_fetch_field_direct(m_res, i); 00111 if(f == NULL) 00112 continue; 00113 if(strcmp(f->name, name)==0) 00114 return CMyMySQLPPTypeConv(m_row[i]); 00115 } 00116 return CMyMySQLPPTypeConv(); 00117 } 00118 00123 CMyMySQLPPTypeConv CMyMySQLPPRow::Get(char* name) 00124 { 00125 if((m_row == NULL) || (m_row == NULL)) 00126 return CMyMySQLPPTypeConv(); 00127 for(unsigned int i = 0; i < mysql_num_fields(m_res); i++) 00128 { 00129 MYSQL_FIELD *f = mysql_fetch_field_direct(m_res, i); 00130 if(f == NULL) 00131 continue; 00132 if(strcmp(f->name, name)==0) 00133 return CMyMySQLPPTypeConv(m_row[i]); 00134 } 00135 return CMyMySQLPPTypeConv(); 00136 }