OpenASIP  2.0
RelationalDBQueryResult.cc
Go to the documentation of this file.
1 /*
2  Copyright (c) 2002-2009 Tampere University.
3 
4  This file is part of TTA-Based Codesign Environment (TCE).
5 
6  Permission is hereby granted, free of charge, to any person obtaining a
7  copy of this software and associated documentation files (the "Software"),
8  to deal in the Software without restriction, including without limitation
9  the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  and/or sell copies of the Software, and to permit persons to whom the
11  Software is furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in
14  all copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22  DEALINGS IN THE SOFTWARE.
23  */
24 /**
25  * @file RelationalDBQueryResult.cc
26  *
27  * Empty implementation of the interface, just to be able to add Doxygen
28  * comments for methods.
29  *
30  * @author Pekka Jääskeläinen 2004 (pekka.jaaskelainen-no.spam-tut.fi)
31  *
32  * @note rating: red
33  * @todo Change returning UNKNOWN_INDEX to throwing an exception.
34  */
35 
37 
38 #include "DataObject.hh"
39 
40 /**
41  * Destructor.
42  */
44 }
45 
46 /**
47  * Returns the number of columns in the result set.
48  *
49  * @return Number of columns, UNKNOWN_INDEX if unknown (if not supported by
50  * the driver).
51  */
52 int
54  return UNKNOWN_INDEX;
55 }
56 
57 /**
58  * Returns the index of column with the given name.
59  *
60  * @param name Name of the column.
61  * @return Index of the column with given name. UNKNOWN_INDEX if not found.
62  */
63 int
64 RelationalDBQueryResult::column(const std::string& name) const {
65  for (int i = 0; i < columns(); ++i) {
66  if (columnName(i) == name) {
67  return i;
68  }
69  }
70  return UNKNOWN_INDEX;
71 }
72 
73 /**
74  * Returns the name (title) of a column in the result set.
75  *
76  * @param columnIndex Index of the column of which title interested.
77  * @return Title. Empty string if unknown (if not supported by the driver or
78  * index out of bounds).
79  */
80 std::string
82  return "";
83 }
84 
85 /**
86  * Returns the data of a column in the current row in the result set.
87  *
88  * Returns a DataObject with isNull() set in case the value from DB
89  * is NULL.
90  *
91  * @param columnIndex Index of the column of which data to return.
92  * @return The data. Returns NullDataObject if the index is out of bounds.
93  *
94  */
95 const DataObject&
96 RelationalDBQueryResult::data(std::size_t) const {
97  return NullDataObject::instance();
98 }
99 
100 /**
101  * Returns the data of a column in the current row in the result set.
102  *
103  * @param name Name of the column of which data to return.
104  * @return The data. Returns NullDataObject if the column cannot be found.
105  * Also returns NullDataObject in case the feature is not supported
106  * by the database implementation.
107  *
108  */
109 const DataObject&
110 RelationalDBQueryResult::data(const std::string& name) const {
111 
112  int columnIndex = column(name);
113  if (columnIndex != UNKNOWN_INDEX) {
114  return data(columnIndex);
115  }
116 
117  return NullDataObject::instance();
118 }
119 
120 /**
121  * Queries if the result set contains more rows.
122  *
123  * @return True if there are more rows that can be accessed with next().
124  */
125 bool
127  return false;
128 }
129 
130 /**
131  * Advances the row cursor to next row in the result set.
132  *
133  * In case the current row is the last row this method does nothing.
134  *
135  * @return True if there are still more rows to fetch. *
136  */
137 bool
139  return false;
140 }
141 
142 /**
143  * Binds int type variable to a prepared sql statement.
144  */
145 void
146 RelationalDBQueryResult::bindInt(unsigned int /*position*/, int /*value*/) {
147  return;
148 }
149 
150 /**
151  * Binds string type variable to a prepared sql statement.
152  */
153 void
155  unsigned int /*position*/, const std::string& /*value*/) {
156  return;
157 }
158 
159 /**
160  * Resets s prepared sql statement.
161  */
162 void
164  return;
165 }
166 
RelationalDBQueryResult.hh
DataObject
Definition: DataObject.hh:50
RelationalDBQueryResult::data
virtual const DataObject & data(std::size_t column) const =0
Definition: RelationalDBQueryResult.cc:96
RelationalDBQueryResult::reset
virtual void reset()
Definition: RelationalDBQueryResult.cc:163
RelationalDBQueryResult::UNKNOWN_INDEX
static const int UNKNOWN_INDEX
Definition: RelationalDBQueryResult.hh:50
RelationalDBQueryResult::hasNext
virtual bool hasNext()=0
Definition: RelationalDBQueryResult.cc:126
RelationalDBQueryResult::next
virtual bool next()=0
Definition: RelationalDBQueryResult.cc:138
RelationalDBQueryResult::bindString
virtual void bindString(unsigned int position, const std::string &value)
Definition: RelationalDBQueryResult.cc:154
RelationalDBQueryResult::~RelationalDBQueryResult
virtual ~RelationalDBQueryResult()
Definition: RelationalDBQueryResult.cc:43
DataObject.hh
RelationalDBQueryResult::columnName
virtual std::string columnName(std::size_t columnIndex) const
Definition: RelationalDBQueryResult.cc:81
RelationalDBQueryResult::column
virtual int column(const std::string &name) const
Definition: RelationalDBQueryResult.cc:64
RelationalDBQueryResult::bindInt
virtual void bindInt(unsigned int position, int value)
Definition: RelationalDBQueryResult.cc:146
RelationalDBQueryResult::columns
virtual int columns() const
Definition: RelationalDBQueryResult.cc:53
NullDataObject::instance
static NullDataObject & instance()
Definition: DataObject.cc:542