WORM 0.2
A C++ DAL/ORM code generation framework
|
00001 /* 00002 * WORM - a DAL/ORM code generation framework 00003 * Copyright (C) 2011 Erik Winn <erikwinnmail@yahoo.com> 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 3 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, see <http://www.gnu.org/licenses/>. 00017 */ 00018 00019 #include <vector> 00020 #include <string> 00021 00022 #include "wsqlrecord.h" 00023 #include "wsqlfield.h" 00024 00025 namespace WSql { 00026 00063 WSqlRecord::WSqlRecord() 00064 { 00065 _isValid=false; 00066 } 00067 00068 WSqlRecord::WSqlRecord( const WSql::WSqlRecord& other ) 00069 { 00070 _isValid=other._isValid; 00071 _fields=other._fields; 00072 } 00073 WSqlRecord::~WSqlRecord() 00074 { 00076 } 00077 00078 WSqlRecord& WSqlRecord::operator=( const WSql::WSqlRecord& other ) 00079 { 00080 _isValid=other._isValid; 00081 _fields=other._fields; 00082 return *this; 00083 } 00084 bool WSqlRecord::operator==( const WSql::WSqlRecord& other ) const 00085 { 00086 return false; 00088 } 00089 void WSqlRecord::setNull( const std::string& name ) 00090 { 00091 setNull(indexOf(name)); 00092 } 00093 void WSqlRecord::setNull( int pos ) 00094 { 00095 _fields.at(pos).setData(std::string()); 00096 } 00097 00113 std::string WSqlRecord::data(int pos) const 00114 { 00115 return field(pos).data<std::string>(); 00116 } 00117 00126 std::string WSqlRecord::data(const std::string& colname) const 00127 { 00128 return field(colname).data<std::string>(); 00129 } 00130 00131 bool WSqlRecord::isNull(const std::string& colname) const 00132 { 00133 return data(colname).empty(); 00134 } 00135 bool WSqlRecord::isNull(int index) const 00136 { 00137 return data(index).empty(); 00138 } 00139 00140 WSqlField WSqlRecord::field( int pos ) const 00141 { 00142 return at(pos); 00143 } 00144 00145 WSqlField WSqlRecord::at( int pos ) const 00146 { 00147 int sz = _fields.size(); 00148 if ( !sz || pos < 0 || pos > sz - 1 ) 00149 return WSqlField(); 00150 return _fields.at(pos); 00151 } 00152 00153 WSqlField WSqlRecord::field( const std::string& colname ) const 00154 { 00155 return at(indexOf(colname)); 00156 } 00157 00158 int WSqlRecord::indexOf( const std::string& name ) const 00159 { 00160 int intToReturn = -1; 00161 if ( _fields.empty() ) 00162 return intToReturn; 00163 int i = 0; 00164 std::vector<WSqlField>::const_iterator it; 00165 for ( it = _fields.begin(); it != _fields.end() ; ++it ) 00166 { 00167 if ( it->name().compare( name ) == 0 ) 00168 { 00169 intToReturn = i; 00170 break; 00171 } 00172 ++i; 00173 } 00174 return intToReturn; 00175 } 00176 00177 void WSqlRecord::clear() 00178 { 00179 _fields.clear(); 00180 } 00181 00182 } //namespace WSql