~ubuntu-branches/ubuntu/quantal/poco/quantal

« back to all changes in this revision

Viewing changes to Data/SQLite/testsuite/src/SQLiteTest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Krzysztof Burghardt
  • Date: 2008-11-15 11:39:15 UTC
  • mfrom: (3.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20081115113915-7kauhm2c3m2i7oid
Tags: 1.3.3p1-2
* Fixed FTBFS with GCC 4.4 due to missing #include (Closes: #505619)
* Renamed 20_gcc43-missing-include.dpatch to 20_gcc44-missing-include.dpatch
* Downgraded dependencies on -dbg packages (Closes: #504342)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
//
2
2
// SQLiteTest.cpp
3
3
//
4
 
// $Id: //poco/1.3/Data/SQLite/testsuite/src/SQLiteTest.cpp#3 $
 
4
// $Id: //poco/1.3/Data/SQLite/testsuite/src/SQLiteTest.cpp#5 $
5
5
//
6
6
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
7
7
// and Contributors.
44
44
#include <iostream>
45
45
#include "Poco/File.h"
46
46
#include "Poco/Stopwatch.h"
 
47
#include "Poco/Data/SQLite/SQLiteException.h"
47
48
 
48
49
 
49
50
using namespace Poco::Data;
53
54
using Poco::InvalidAccessException;
54
55
using Poco::RangeException;
55
56
using Poco::BadCastException;
 
57
using Poco::Data::SQLite::ParameterCountMismatchException;
56
58
 
57
59
 
58
60
struct Person
129
131
                std::string lastName;
130
132
                std::string firstName;
131
133
                std::string address;
132
 
                int age = 0;
133
134
                if (!pExt->extract(pos++, obj.lastName))
134
135
                        obj.lastName = defVal.lastName;
135
136
                if (!pExt->extract(pos++, obj.firstName))
191
192
}
192
193
 
193
194
 
194
 
void SQLiteTest::testInsertCharPointer()
195
 
{
196
 
        Session tmp (SessionFactory::instance().create(SQLite::Connector::KEY, "dummy.db"));
197
 
        std::string tableName("Person");
198
 
        std::string lastName("lastname");
199
 
        std::string firstName("firstname");
200
 
        std::string address("Address");
201
 
        int age = 133132;
202
 
        int count = 0;
203
 
        std::string result;
204
 
        tmp << "DROP TABLE IF EXISTS Person", now;
205
 
        tmp << "CREATE TABLE IF NOT EXISTS Person (LastName VARCHAR(30), FirstName VARCHAR, Address VARCHAR, Age INTEGER(3))", now;
206
 
 
207
 
        tmp << "INSERT INTO PERSON VALUES(:ln, :fn, :ad, :age)", use("lastname"), use("firstname"), use("Address"), use(133132), now;
208
 
        tmp << "SELECT COUNT(*) FROM PERSON", into(count), now;
209
 
        assert (count == 1);
210
 
        tmp << "SELECT LastName FROM PERSON", into(result), now;
211
 
        assert (lastName == result);
212
 
        tmp << "SELECT Age FROM PERSON", into(count), now;
213
 
        assert (count == age);
214
 
}
215
 
 
216
 
 
217
 
 
218
 
void SQLiteTest::testInsertCharPointer2()
219
 
{
220
 
        Session tmp (SessionFactory::instance().create(SQLite::Connector::KEY, "dummy.db"));
221
 
        std::string tableName("Person");
222
 
        std::string lastName("lastname");
223
 
        std::string firstName("firstname");
224
 
        std::string address("Address");
225
 
        int age = 133132;
226
 
        int count = 0;
227
 
        std::string result;
228
 
        tmp << "DROP TABLE IF EXISTS Person", now;
229
 
        tmp << "CREATE TABLE IF NOT EXISTS Person (LastName VARCHAR(30), FirstName VARCHAR, Address VARCHAR, Age INTEGER(3))", now;
230
 
 
231
 
        tmp << "INSERT INTO PERSON VALUES(:ln, :fn, :ad, :age)", use("lastname"), use("firstname"), use("Address"), use(133132), now;
232
 
        tmp << "SELECT COUNT(*) FROM PERSON", into(count), now;
233
 
        assert (count == 1);
234
 
        Statement stmt1 = (tmp << "SELECT LastName FROM PERSON", into(result));
235
 
        stmt1.execute();
236
 
        assert (lastName == result);
237
 
        count = 0;
238
 
        Statement stmt2 = (tmp << "SELECT Age FROM PERSON", into(count));
239
 
        stmt2.execute();
240
 
        assert (count == age);
241
 
}
242
 
 
243
 
 
244
195
void SQLiteTest::testComplexType()
245
196
{
246
197
        Session tmp (SessionFactory::instance().create(SQLite::Connector::KEY, "dummy.db"));
348
299
        Session tmp (SessionFactory::instance().create(SQLite::Connector::KEY, "dummy.db"));
349
300
        std::vector<std::string> str;
350
301
 
351
 
        int count = 100;
352
302
        tmp << "DROP TABLE IF EXISTS Strings", now;
353
303
        tmp << "CREATE TABLE IF NOT EXISTS Strings (str VARCHAR(30))", now;
354
304
        try
420
370
        }
421
371
 
422
372
        tmp << "INSERT INTO Strings VALUES(:str)", use(data), now;
423
 
        int count = 0;
 
373
 
424
374
        std::vector<int> retData;
425
375
        tmp << "SELECT * FROM Strings", into(retData), limit(50), now;
426
376
        assert (retData.size() == 50);
443
393
        }
444
394
 
445
395
        tmp << "INSERT INTO Strings VALUES(:str)", use(data), now;
446
 
        int count = 0;
 
396
 
447
397
        std::vector<int> retData;
448
398
        tmp << "SELECT * FROM Strings", into(retData), limit(0), now; // stupid test, but at least we shouldn't crash
449
399
        assert (retData.size() == 0);
462
412
        }
463
413
 
464
414
        tmp << "INSERT INTO Strings VALUES(:str)", use(data), now;
465
 
        int count = 0;
 
415
 
466
416
        std::vector<int> retData;
467
417
        Statement stmt = (tmp << "SELECT * FROM Strings", into(retData), limit(50), now);
468
418
        assert (!stmt.done());
493
443
        }
494
444
 
495
445
        tmp << "INSERT INTO Strings VALUES(:str)", use(data), now;
496
 
        int count = 0;
 
446
 
497
447
        std::vector<int> retData;
498
448
        Statement stmt = (tmp << "SELECT * FROM Strings", into(retData), limit(50));
499
449
        assert (retData.size() == 0);
1577
1527
}
1578
1528
 
1579
1529
 
 
1530
void SQLiteTest::testBindingCount()
 
1531
{
 
1532
        Session tmp (SQLite::Connector::KEY, "dummy.db");
 
1533
 
 
1534
        tmp << "DROP TABLE IF EXISTS Ints", now;
 
1535
        tmp << "CREATE TABLE Ints (int0 INTEGER)", now;
 
1536
 
 
1537
        int i = 42;
 
1538
        try     { tmp << "INSERT INTO Ints VALUES (?)", now; } 
 
1539
        catch (ParameterCountMismatchException&) { }
 
1540
 
 
1541
        try     { tmp << "INSERT INTO Ints VALUES (?)", use(i), use(i), now; }
 
1542
        catch (ParameterCountMismatchException&) { }
 
1543
        tmp << "INSERT INTO Ints VALUES (?)", use(i), now;
 
1544
        
 
1545
        int j = 0;
 
1546
        try     { tmp << "SELECT int0 from Ints where int0 = ?", into(i), now; }
 
1547
        catch (ParameterCountMismatchException&) { }
 
1548
        tmp << "SELECT int0 from Ints where int0 = ?", use(i), into(j), now;
 
1549
        assert (42 == j);
 
1550
}
 
1551
 
 
1552
 
1580
1553
void SQLiteTest::setUp()
1581
1554
{
1582
1555
}
1592
1565
        CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("SQLiteTest");
1593
1566
 
1594
1567
        CppUnit_addTest(pSuite, SQLiteTest, testSimpleAccess);
1595
 
        CppUnit_addTest(pSuite, SQLiteTest, testInsertCharPointer);
1596
 
        CppUnit_addTest(pSuite, SQLiteTest, testInsertCharPointer2);
1597
1568
        CppUnit_addTest(pSuite, SQLiteTest, testComplexType);
1598
1569
        CppUnit_addTest(pSuite, SQLiteTest, testSimpleAccessVector);
1599
1570
        CppUnit_addTest(pSuite, SQLiteTest, testComplexTypeVector);
1648
1619
        CppUnit_addTest(pSuite, SQLiteTest, testTuple1);
1649
1620
        CppUnit_addTest(pSuite, SQLiteTest, testTupleVector1);
1650
1621
        CppUnit_addTest(pSuite, SQLiteTest, testInternalExtraction);
 
1622
        CppUnit_addTest(pSuite, SQLiteTest, testBindingCount);
1651
1623
 
1652
1624
        return pSuite;
1653
1625
}