5 |
6 | using namespace UnitTest;
7 | using std::ostringstream;
8 |
9 | namespace
10 | {
11 |
12 | #ifdef UNITTEST_USE_CUSTOM_STREAMS
13 |
14 | // Overload to let MemoryOutStream accept std::string
15 | MemoryOutStream& operator<<(MemoryOutStream& s, const std::string& value)
16 | {
17 | s << value.c_str();
18 | return s;
19 | }
20 |
21 | #endif
22 |
23 | struct XmlTestReporterFixture
24 | {
25 | XmlTestReporterFixture()
26 | : reporter(output)
27 | {
28 | }
29 |
30 | ostringstream output;
31 | XmlTestReporter reporter;
32 | };
33 |
34 | TEST_FIXTURE(XmlTestReporterFixture, MultipleCharactersAreEscaped)
35 | {
36 | TestDetails const details("TestName", "suite", "filename.h", 4321);
37 |
38 | reporter.ReportTestStart(details);
39 | reporter.ReportFailure(details, "\"\"\'\'&&<<>>");
40 | reporter.ReportTestFinish(details, 0.1f);
41 | reporter.ReportSummary(1, 2, 3, 0.1f);
42 |
43 | char const* expected =
44 | ""
45 | ""
46 | ""
47 | ""
49 | ""
50 | "";
51 |
52 | CHECK_EQUAL(expected, output.str());
53 | }
54 |
55 | TEST_FIXTURE(XmlTestReporterFixture, OutputIsCachedUntilReportSummaryIsCalled)
56 | {
57 | TestDetails const details("", "", "", 0);
58 |
59 | reporter.ReportTestStart(details);
60 | reporter.ReportFailure(details, "message");
61 | reporter.ReportTestFinish(details, 1.0F);
62 | CHECK(output.str().empty());
63 |
64 | reporter.ReportSummary(1, 1, 1, 1.0f);
65 | CHECK(!output.str().empty());
66 | }
67 |
68 | TEST_FIXTURE(XmlTestReporterFixture, EmptyReportSummaryFormat)
69 | {
70 | reporter.ReportSummary(0, 0, 0, 0.1f);
71 |
72 | const char *expected =
73 | ""
74 | ""
75 | "";
76 |
77 | CHECK_EQUAL(expected, output.str());
78 | }
79 |
80 | TEST_FIXTURE(XmlTestReporterFixture, SingleSuccessfulTestReportSummaryFormat)
81 | {
82 | TestDetails const details("TestName", "DefaultSuite", "", 0);
83 |
84 | reporter.ReportTestStart(details);
85 | reporter.ReportSummary(1, 0, 0, 0.1f);
86 |
87 | const char *expected =
88 | ""
89 | ""
90 | ""
91 | "";
92 |
93 | CHECK_EQUAL(expected, output.str());
94 | }
95 |
96 | TEST_FIXTURE(XmlTestReporterFixture, SingleFailedTestReportSummaryFormat)
97 | {
98 | TestDetails const details("A Test", "suite", "A File", 4321);
99 |
100 | reporter.ReportTestStart(details);
101 | reporter.ReportFailure(details, "A Failure");
102 | reporter.ReportSummary(1, 1, 1, 0.1f);
103 |
104 | const char *expected =
105 | ""
106 | ""
107 | ""
108 | ""
109 | ""
110 | "";
111 |
112 | CHECK_EQUAL(expected, output.str());
113 | }
114 |
115 | TEST_FIXTURE(XmlTestReporterFixture, FailureMessageIsXMLEscaped)
116 | {
117 | TestDetails const details("TestName", "suite", "filename.h", 4321);
118 |
119 | reporter.ReportTestStart(details);
120 | reporter.ReportFailure(details, "\"\'&<>");
121 | reporter.ReportTestFinish(details, 0.1f);
122 | reporter.ReportSummary(1, 1, 1, 0.1f);
123 |
124 | char const* expected =
125 | ""
126 | ""
127 | ""
128 | ""
129 | ""
130 | "";
131 |
132 | CHECK_EQUAL(expected, output.str());
133 | }
134 |
135 | TEST_FIXTURE(XmlTestReporterFixture, OneFailureAndOneSuccess)
136 | {
137 | TestDetails const failedDetails("FailedTest", "suite", "fail.h", 1);
138 | reporter.ReportTestStart(failedDetails);
139 | reporter.ReportFailure(failedDetails, "expected 1 but was 2");
140 | reporter.ReportTestFinish(failedDetails, 0.1f);
141 |
142 | TestDetails const succeededDetails("SucceededTest", "suite", "", 0);
143 | reporter.ReportTestStart(succeededDetails);
144 | reporter.ReportTestFinish(succeededDetails, 1.0f);
145 | reporter.ReportSummary(2, 1, 1, 1.1f);
146 |
147 | char const* expected =
148 | ""
149 | ""
150 | ""
151 | ""
152 | ""
153 | ""
154 | "";
155 |
156 | CHECK_EQUAL(expected, output.str());
157 | }
158 |
159 | TEST_FIXTURE(XmlTestReporterFixture, MultipleFailures)
160 | {
161 | TestDetails const failedDetails1("FailedTest", "suite", "fail.h", 1);
162 | TestDetails const failedDetails2("FailedTest", "suite", "fail.h", 31);
163 |
164 | reporter.ReportTestStart(failedDetails1);
165 | reporter.ReportFailure(failedDetails1, "expected 1 but was 2");
166 | reporter.ReportFailure(failedDetails2, "expected one but was two");
167 | reporter.ReportTestFinish(failedDetails1, 0.1f);
168 |
169 | reporter.ReportSummary(1, 1, 2, 1.1f);
170 |
171 | char const* expected =
172 | ""
173 | ""
174 | ""
175 | ""
176 | ""
177 | ""
178 | "";
179 |
180 | CHECK_EQUAL(expected, output.str());
181 | }
182 |
183 | }
184 |
--------------------------------------------------------------------------------
/easySQLite/SqlTable.cpp:
--------------------------------------------------------------------------------
1 | #include "SqlTable.h"
2 |
3 |
4 | namespace sql
5 | {
6 |
7 | Table::Table(sqlite3* db, string tableName, Field* definition)
8 | : _db(db), _tableName(tableName), _recordset(db, definition)
9 | {
10 | }
11 |
12 | Table::Table(sqlite3* db, string tableName, FieldSet* fields)
13 | : _db(db), _tableName(tableName), _recordset(db, fields)
14 | {
15 | }
16 |
17 | string Table::name()
18 | {
19 | return _tableName;
20 | }
21 |
22 | string Table::getDefinition()
23 | {
24 | return "CREATE TABLE " + _tableName + " (" + fields()->getDefinition() + ")";
25 | }
26 |
27 | FieldSet* Table::fields()
28 | {
29 | return _recordset.fields();
30 | }
31 |
32 | string Table::toString()
33 | {
34 | string s;
35 |
36 | for (int index = 0; index < fields()->count(); index++)
37 | {
38 | if (Field* f = fields()->getByIndex(index))
39 | {
40 | s += intToStr(index + 1) + ". " + f->getDefinition();
41 |
42 | if (index < (fields()->count() - 1))
43 | s +="\r\n";
44 | }
45 | }
46 |
47 | return s;
48 | }
49 |
50 | string Table::errMsg()
51 | {
52 | return _recordset.errMsg();
53 | }
54 |
55 | sqlite3* Table::getHandle()
56 | {
57 | return _db;
58 | }
59 |
60 | bool Table::create()
61 | {
62 | if (exists())
63 | return true;
64 |
65 | const string sqlDefinition = getDefinition();
66 |
67 | if (_recordset.query(sqlDefinition))
68 | {
69 | return true;
70 | }
71 |
72 | return false;
73 | }
74 |
75 | bool Table::query(string queryStr)
76 | {
77 | if (_recordset.query(queryStr))
78 | {
79 | return true;
80 | }
81 | return false;
82 | }
83 |
84 | bool Table::open()
85 | {
86 | const string queryStr = "select * from " + _tableName;
87 |
88 | if (_recordset.query(queryStr))
89 | {
90 | return true;
91 | }
92 |
93 | return false;
94 | }
95 |
96 | //example of whereCondition:
97 | //"_ID > 40"
98 | bool Table::open(string whereCondition)
99 | {
100 | const string queryStr = "select * from " + _tableName + (whereCondition.empty() ? "" : " where " + whereCondition);
101 |
102 | if (_recordset.query(queryStr))
103 | {
104 | return true;
105 | }
106 |
107 | return false;
108 | }
109 |
110 | //example of sortBy:
111 | //"_ID desc"
112 | bool Table::open(string whereCondition, string sortBy)
113 | {
114 | const string queryStr = "select * from " + _tableName
115 | + (whereCondition.empty() ? "" : " where " + whereCondition)
116 | + (sortBy.empty() ? "" : " order by " + sortBy);
117 |
118 | if (_recordset.query(queryStr))
119 | {
120 | return true;
121 | }
122 |
123 | return false;
124 | }
125 |
126 | bool Table::truncate()
127 | {
128 | const string queryStr = "delete from " + _tableName;
129 |
130 | if (_recordset.query(queryStr))
131 | {
132 | return true;
133 | }
134 |
135 | return false;
136 | }
137 |
138 | bool Table::remove()
139 | {
140 | const string queryStr = "drop table " + _tableName;
141 |
142 | if (_recordset.query(queryStr))
143 | {
144 | return true;
145 | }
146 |
147 | return false;
148 | }
149 |
150 | bool Table::deleteRecords(string whereCondition)
151 | {
152 | const string sql = "delete from " + _tableName + (whereCondition.empty() ? "" : " where " + whereCondition);
153 |
154 | RecordSet rs(_db, _recordset.fields());
155 |
156 | if (rs.query(sql))
157 | {
158 | return true;
159 | }
160 |
161 | return false;
162 | }
163 |
164 | int Table::recordCount()
165 | {
166 | return _recordset.count();
167 | }
168 |
169 | int Table::totalRecordCount()
170 | {
171 | const string queryStr = "select count(*) from " + _tableName;
172 |
173 | RecordSet rs(_db, _recordset.fields());
174 |
175 | if (rs.query(queryStr))
176 | {
177 | if (Value* value = rs.getTopRecordFirstValue())
178 | {
179 | return (int)value->asInteger();
180 | }
181 | }
182 |
183 | return -1;
184 | }
185 |
186 | bool Table::exists()
187 | {
188 | const string queryStr = "select count(*) from sqlite_master where type = 'table' and name = '" + _tableName + "'";
189 |
190 | RecordSet rs(_db, _recordset.fields());
191 |
192 | if (rs.query(queryStr))
193 | {
194 | if (Value* value = rs.getTopRecordFirstValue())
195 | {
196 | return (value->asInteger() > 0);
197 | }
198 | }
199 |
200 | return false;
201 | }
202 |
203 | Record* Table::getRecord(int record_index)
204 | {
205 | return _recordset.getRecord(record_index);
206 | }
207 |
208 | Record* Table::getTopRecord()
209 | {
210 | return getRecord(0);
211 | }
212 |
213 | Record* Table::getRecordByKeyId(integer keyId)
214 | {
215 | const string queryStr = "select * from " + _tableName + " where _ID = " + intToStr(keyId);
216 |
217 | if (_recordset.query(queryStr))
218 | {
219 | if (_recordset.count() > 0)
220 | {
221 | return _recordset.getRecord(0);
222 | }
223 | }
224 |
225 | return NULL;
226 | }
227 |
228 | bool Table::addRecord(Record* record)
229 | {
230 | if (record)
231 | {
232 | const string sql = record->toSqlInsert(name());
233 |
234 | RecordSet rs(_db, _recordset.fields());
235 |
236 | if (rs.query(sql))
237 | {
238 | return true;
239 | }
240 | }
241 | return false;
242 | }
243 |
244 | bool Table::updateRecord(Record* record)
245 | {
246 | if (record)
247 | {
248 | const string sql = record->toSqlUpdate(name());
249 |
250 | RecordSet rs(_db, _recordset.fields());
251 |
252 | if (rs.query(sql))
253 | {
254 | return true;
255 | }
256 | }
257 | return false;
258 | }
259 |
260 | bool Table::copyRecords(Table& source)
261 | {
262 | for (int index = 0; index < source.recordCount(); index++)
263 | {
264 | if (Record* record = source.getRecord(index))
265 | {
266 | if (!addRecord(record))
267 | return false;
268 | }
269 | }
270 | return true;
271 | }
272 |
273 | Table* Table::createFromDefinition(sqlite3* db, string tableName, string fieldsDefinition)
274 | {
275 | if (FieldSet* fields = FieldSet::createFromDefinition(fieldsDefinition))
276 | {
277 | Table* table = new Table(db, tableName, fields);
278 |
279 | delete fields;
280 |
281 | return table;
282 | }
283 |
284 | return NULL;
285 | }
286 |
287 | bool Table::backup(Table& source)
288 | {
289 | bool bResult = false;
290 |
291 | if (exists())
292 | remove();
293 |
294 | if (create())
295 | {
296 | if (source.open())
297 | {
298 | if (copyRecords(source))
299 | {
300 | if (source.totalRecordCount() == totalRecordCount())
301 | bResult = true;
302 | }
303 | }
304 | }
305 |
306 | return bResult;
307 | }
308 |
309 |
310 | //sql eof
311 | };
312 |
--------------------------------------------------------------------------------
/_ReadMe.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | easySQLite short help
10 |
68 |
69 |
70 |
71 | easySQLite
a C++ SQLite wrapper
72 |
73 | This is C++ API wrapper for SQLite C API database engine. It was written to simplify and speedup coding
74 | of local database access.
75 |
76 | easySQLite is released under BSD License.
77 |
78 | easySQLite was written and tested with Visual C++ 2010 Express, but is not
79 | using any nonstandard extensions, so should compile with any other C++ compiler.
80 |
81 | How To Start ?
82 |
83 | First, include "SqlCommon.h" and other headers if required to your project.
84 |
85 | easySQLite uses sql namespace.
86 |
87 | At begin, you should create database table structure as Field's objects array:
88 |
89 |
90 |
91 | Field definition_tbPerson[] =
92 | {
93 | Field(FIELD_KEY),
94 | Field("fname", type_text, flag_not_null),
95 | Field("lname", type_text, flag_not_null),
96 | Field("birthdate", type_time),
97 | Field(DEFINITION_END),
98 | };
99 |
100 |
101 |
102 | Default Field object constructor parameters:
103 |
104 | - name
(sql::string)
105 | - type
(sql::field_type)
106 | - flags
(sql::field_flags). Can be OR'ed
107 |
108 |
109 | Table structure definition should begin with Field(FIELD_KEY) and end with Field(DEFINITION_END).
110 |
111 | Field(FIELD_KEY) is like Field("_ID", type_int, flag_primary_key).
112 |
113 | Now, you are ready to open/create database file. Define database object and then open database file.
114 |
115 |
116 |
117 | sql::Database db;
118 |
119 | try
120 | {
121 | db.open("test.db");
122 | //...
123 |
124 | } catch (Exception e) {
125 | //...
126 | }
127 |
128 |
129 |
130 | TIP: you can check for errors by using return bool value of any method and ::errMsg() of used object.
131 | Default behaviour for most objects is to use exceptions.
132 |
133 | Disable USE_EXCEPTIONS directive in SqlCommon.h to "manually" check for result values, for example:
134 |
135 |
136 |
137 | if (!db.open("test.db"))
138 | {
139 | log(db.errMsg());
140 | }
141 |
142 |
143 |
144 | When database file is up and ready, you can define new Table object for it:
145 |
146 |
147 |
148 | sql::Table tbPerson(db.getHandle(), "person", definition_tbPerson);
149 |
150 |
151 |
152 | Default Table object constructor parameters:
153 |
154 | - db handle
(sqlite3*)
155 | - tableName
(sql::string)
156 | - fields definition
(sql::Field*). Field* array or FieldSet* of another table.
157 |
158 |
159 | Now, the simplest way to interact with data is to use Table object methods, for example:
160 |
161 |
162 |
163 | //remove table from database if exists
164 | if (tbPerson.exists())
165 | tbPerson.remove();
166 |
167 | //create new table
168 | tbPerson.create();
169 |
170 | //removes all records
171 | tbPerson.truncate();
172 |
173 | //loads all records to internal recordset
174 | tbPerson.open();
175 |
176 | //loads one record
177 | tbPerson.open("_ID == 5");
178 |
179 | //returns loaded records count
180 | tbPerson.recordCount();
181 |
182 |
183 |
184 | Modify Or Query Data
185 |
186 | To make modifications of your data or query them, you must use Record object.
187 |
188 | To add (insert) new record to table, define Record with table FieldSet definition.
189 | Then you can set some data to fields and just insert new record to table:
190 |
191 |
192 |
193 | Record record(tbPerson.fields());
194 |
195 | record.setString("fname", "Jan");
196 | record.setString("lname", "Kowalski");
197 | record.setTime("birthdate", time::now());
198 |
199 | tbPerson.addRecord(&record);
200 |
201 |
202 |
203 | Query records and update at once:
204 |
205 |
206 |
207 | tbPerson.open("_ID >= 10 and _ID <= 15");
208 |
209 | for (int index = 0; index < tbPerson.recordCount(); index++)
210 | {
211 | if (Record* record = tbPerson.getRecord(index))
212 | {
213 | record->setString("fname", "");
214 | record->setString("lname", "Nowak");
215 | record->setNull("birthdate");
216 |
217 | tbPerson.updateRecord(record);
218 | }
219 | }
220 |
221 |
222 |
223 | List all records:
224 |
225 |
226 |
227 | tbPerson.open();
228 |
229 | for (int index = 0; index < tbPerson.recordCount(); index++)
230 | if (Record* record = tbPerson.getRecord(index))
231 | log(record->toString());
232 |
233 |
234 |
235 | Get one record by key field (_ID):
236 |
237 |
238 |
239 | if (Record* record = tbPerson.getRecordByKeyId(7))
240 | {
241 | //...
242 | }
243 |
244 |
245 |
246 | You can find more usage examples in easySQLite.cpp project file.
247 |
248 | Author
249 |
250 | Copyright (c) 2010, Piotr Zagawa
251 |
252 | All rights reserved.
253 |
254 | contact
255 | website
256 |
257 |
258 |
259 |
260 |
--------------------------------------------------------------------------------
/easySQLite/SqlRecord.cpp:
--------------------------------------------------------------------------------
1 | #include "SqlRecord.h"
2 | #include "SqlFieldSet.h"
3 |
4 | namespace sql
5 | {
6 |
7 | Record::Record(FieldSet* fields)
8 | : _fields(fields)
9 | {
10 | initColumnCount(_fields->count());
11 | }
12 |
13 | Record::Record(Record* record)
14 | : _fields(record->_fields)
15 | {
16 | initColumnCount(_fields->count());
17 | _values = record->_values;
18 | }
19 |
20 | Record::Record(const Record& record)
21 | : _fields(record._fields)
22 | {
23 | initColumnCount(_fields->count());
24 | _values = record._values;
25 | }
26 |
27 | FieldSet* Record::fields()
28 | {
29 | return _fields;
30 | }
31 |
32 | void Record::initColumnCount(int columns)
33 | {
34 | _values.resize(columns);
35 | }
36 |
37 | void Record::initColumnValue(int column_index, char* value, field_type type)
38 | {
39 | _values[column_index].setValue(value, type);
40 | }
41 |
42 | int Record::columnCount()
43 | {
44 | return _values.size();
45 | }
46 |
47 | Value* Record::getValue(int column_index)
48 | {
49 | if ((column_index >= 0) && (column_index < (int)_values.size()))
50 | return &_values.at(column_index);
51 |
52 | return NULL;
53 | }
54 |
55 | Value* Record::getValue(string fieldName)
56 | {
57 | if (Field* field = _fields->getByName(fieldName))
58 | return getValue(field->getIndex());
59 |
60 | return NULL;
61 | }
62 |
63 | Value* Record::getKeyIdValue()
64 | {
65 | for (int index = 0; index < _fields->count(); index++)
66 | {
67 | if (Field* field = _fields->getByIndex(index))
68 | {
69 | if (field->isKeyIdField())
70 | return getValue(field->getIndex());
71 | }
72 | }
73 |
74 | return NULL;
75 | }
76 |
77 | string Record::toString()
78 | {
79 | string s;
80 |
81 | for (int column = 0; column < columnCount(); column++)
82 | if (Value* value = getValue(column))
83 | {
84 | s += value->toString();
85 | if (column < (columnCount() - 1))
86 | s += "|";
87 | }
88 |
89 | return s;
90 | }
91 |
92 | string Record::toSql()
93 | {
94 | string s;
95 |
96 | for (int index = 0; index < _fields->count(); index++)
97 | {
98 | if (Field* field = _fields->getByIndex(index))
99 | {
100 | if (Value* value = getValue(field->getName()))
101 | {
102 | s += value->toSql(field->getType());
103 |
104 | if (index < (_fields->count() - 1))
105 | s += ", ";
106 | }
107 | }
108 | }
109 |
110 | return s;
111 | }
112 |
113 | void Record::setNull(int index)
114 | {
115 | if (Value* v = getValue(index))
116 | v->setNull();
117 | }
118 |
119 | void Record::setString(int index, string value)
120 | {
121 | if (Value* v = getValue(index))
122 | v->setString(value);
123 | }
124 |
125 | void Record::setInteger(int index, integer value)
126 | {
127 | if (Value* v = getValue(index))
128 | v->setInteger(value);
129 | }
130 |
131 | void Record::setDouble(int index, double value)
132 | {
133 | if (Value* v = getValue(index))
134 | v->setDouble(value);
135 | }
136 |
137 | void Record::setBool(int index, bool value)
138 | {
139 | if (Value* v = getValue(index))
140 | v->setBool(value);
141 | }
142 |
143 | void Record::setTime(int index, time value)
144 | {
145 | if (Value* v = getValue(index))
146 | v->setTime(value);
147 | }
148 |
149 | Field* Record::fieldByName(string fieldName)
150 | {
151 | if (Field* field = _fields->getByName(fieldName))
152 | {
153 | return field;
154 | } else {
155 | THROW_EXCEPTION("Record::fieldByName: field '" + fieldName + "' not found")
156 | return NULL;
157 | }
158 | }
159 |
160 | void Record::setNull(string fieldName)
161 | {
162 | if (Field* field = fieldByName(fieldName))
163 | setNull(field->getIndex());
164 | }
165 |
166 | void Record::setString(string fieldName, string value)
167 | {
168 | if (Field* field = fieldByName(fieldName))
169 | setString(field->getIndex(), value);
170 | }
171 |
172 | void Record::setInteger(string fieldName, integer value)
173 | {
174 | if (Field* field = fieldByName(fieldName))
175 | setInteger(field->getIndex(), value);
176 | }
177 |
178 | void Record::setDouble(string fieldName, double value)
179 | {
180 | if (Field* field = fieldByName(fieldName))
181 | setDouble(field->getIndex(), value);
182 | }
183 |
184 | void Record::setBool(string fieldName, bool value)
185 | {
186 | if (Field* field = fieldByName(fieldName))
187 | setBool(field->getIndex(), value);
188 | }
189 |
190 | void Record::setTime(string fieldName, time value)
191 | {
192 | if (Field* field = fieldByName(fieldName))
193 | setTime(field->getIndex(), value);
194 | }
195 |
196 | string Record::toSqlInsert(string tableName)
197 | {
198 | string s = "insert into " + tableName + " ";
199 |
200 | s += "(" + _fields->toString() + ")";
201 |
202 | s += " values ";
203 |
204 | s += "(" + toSql() + ")";
205 |
206 | return s;
207 | }
208 |
209 | string Record::toSqlUpdate(string tableName)
210 | {
211 | string s = "update " + tableName + " set ";
212 |
213 | for (int index = 0; index < _fields->count(); index++)
214 | {
215 | if (Field* field = _fields->getByIndex(index))
216 | {
217 | if (field->isKeyIdField())
218 | continue;
219 |
220 | if (Value* value = getValue(field->getName()))
221 | {
222 | s += field->getName() + "=" + value->toSql(field->getType());
223 |
224 | if (index < (_fields->count() - 1))
225 | s += ", ";
226 | }
227 | }
228 | }
229 |
230 | if (Value* value = getKeyIdValue())
231 | s += " where _ID = " + value->toSql(type_int);
232 |
233 | return s;
234 | }
235 |
236 | bool Record::equalsColumnValue(Record* record, string fieldName)
237 | {
238 | if (record)
239 | {
240 | if (Value* value1 = getValue(fieldName))
241 | if (Value* value2 = record->getValue(fieldName))
242 | return value1->equals(*value2);
243 | }
244 | return false;
245 | }
246 |
247 | bool Record::equalsValues(Record* record)
248 | {
249 | if (record)
250 | {
251 | for (int index = 0; index < _fields->count(); index++)
252 | {
253 | if (Field* field = _fields->getByIndex(index))
254 | {
255 | if (field->isKeyIdField())
256 | continue;
257 |
258 | if (Value* value1 = getValue(field->getName()))
259 | if (Value* value2 = record->getValue(field->getName()))
260 | if (!value1->equals(*value2))
261 | return false;
262 | }
263 | }
264 | return true;
265 | }
266 | return false;
267 | }
268 |
269 |
270 | //sql eof
271 |
272 | void Record::setNull(Field& field)
273 | {
274 | setNull(field.getName());
275 | }
276 |
277 | void Record::setString(Field& field, string value)
278 | {
279 | setString(field.getName(),value);
280 | }
281 |
282 | void Record::setInteger(Field& field, integer value)
283 | {
284 | setInteger(field.getName(),value);
285 | }
286 |
287 | void Record::setDouble(Field& field, double value)
288 | {
289 | setDouble(field.getName(),value);
290 | }
291 |
292 | Value* Record::getValue(const Field& field)
293 | {
294 | return getValue(field.getName());
295 | }
296 |
297 | void Record::setBool(Field& field, bool value)
298 | {
299 | setBool(field.getName(),value);
300 | }
301 |
302 | void Record::setTime(Field& field, time value)
303 | {
304 | setTime(field.getName(),value);
305 | }
306 |
307 | }
308 | ;
309 |
--------------------------------------------------------------------------------
/UnitTest++/UnitTest++.vsnet2005.vcproj:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
14 |
15 |
16 |
17 |
18 |
25 |
28 |
31 |
34 |
37 |
40 |
53 |
56 |
59 |
62 |
65 |
68 |
71 |
74 |
77 |
80 |
81 |
89 |
92 |
95 |
98 |
101 |
104 |
115 |
118 |
121 |
124 |
127 |
130 |
133 |
136 |
139 |
142 |
143 |
144 |
145 |
146 |
147 |
150 |
153 |
154 |
157 |
158 |
159 |
162 |
163 |
166 |
167 |
170 |
171 |
174 |
175 |
178 |
179 |
182 |
183 |
186 |
187 |
190 |
191 |
194 |
195 |
198 |
199 |
202 |
203 |
206 |
207 |
210 |
211 |
214 |
215 |
218 |
219 |
222 |
223 |
226 |
227 |
230 |
231 |
234 |
235 |
238 |
239 |
242 |
243 |
246 |
247 |
250 |
251 |
254 |
255 |
258 |
259 |
262 |
263 |
266 |
267 |
270 |
271 |
274 |
275 |
278 |
279 |
282 |
283 |
286 |
287 |
290 |
291 |
294 |
295 |
298 |
299 |
302 |
303 |
306 |
307 |
310 |
311 |
314 |
315 |
316 |
317 |
318 |
319 |
--------------------------------------------------------------------------------