LiteSQL 0.3.10
cursor.hpp
Go to the documentation of this file.
1/* LiteSQL
2 *
3 * The list of contributors at http://litesql.sf.net/
4 *
5 * See LICENSE for copyright information. */
6
7#ifndef _litesql_cursor_hpp
8#define _litesql_cursor_hpp
9
10#include <stdio.h>
11#include "litesql/types.hpp"
12#include "litesql/backend.hpp"
15namespace litesql {
16using namespace std;
17class Database;
21template <class T>
22class Cursor {
23private:
25 const Database& db;
27 Backend::Cursor * cursor;
29 bool done;
31 bool dataReady;
33 Record currentRow;
34public:
35 Cursor(const Database& db, Backend::Cursor * c);
37 ~Cursor();
39 Cursor<T> & operator++();
41 Cursor<T> & operator++(int) { return operator++();}
43 std::vector<T> dump();
45 T operator*();
47 inline bool rowsLeft() { return !done; }
48};
49
50template <class T>
51Cursor<T>::Cursor(const Database& db_, Backend::Cursor * c)
52 : db(db_), cursor(c), done(false), dataReady(false) {
53 operator++();
54}
55template <class T>
57 delete cursor;
58}
59template <class T>
60Cursor<T> & Cursor<T>::operator++() {
61 if (done)
62 return *this;
63 currentRow = cursor->fetchOne();
64 if (currentRow.size() == 0) {
65 done = true;
66 dataReady = false;
67 }
68 else
69 dataReady = true;
70
71 return *this;
72}
73
74template <class T>
75std::vector<T> Cursor<T>::dump() {
76 std::vector<T> res;
77 for (;!done;operator++())
78 res.push_back(operator*());
79 return res;
80}
81template <class T>
83 Record rec;
84
85 if (!dataReady)
86 throw NotFound();
87
88 return T(db,currentRow);
89}
90
91}
92
93#endif
Classes Backend, Backend::Cursor and Backend::Result.
An abstract base class for cursors that iterate result sets returned by relational database.
Definition backend.hpp:23
bool rowsLeft()
returns true if there are records left in the result set
Definition cursor.hpp:47
~Cursor()
deletes Backend::Cursor
Definition cursor.hpp:56
Cursor< T > & operator++()
steps to next record
Definition cursor.hpp:60
std::vector< T > dump()
returns the rest of the result set in vector
Definition cursor.hpp:75
Cursor< T > & operator++(int)
steps to next record
Definition cursor.hpp:41
T operator*()
returns current record
Definition cursor.hpp:82
A base class of databases.
Definition database.hpp:37
exception thrown when a record is not found
Definition except.hpp:32
SQL data row wrapper.
Definition types.hpp:20
contains class Record and typedef Records

SourceForge.net Logo