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"
15 namespace litesql {
16 using namespace std;
17 class Database;
21 template <class T>
22 class Cursor {
23 private:
25  const Database& db;
27  Backend::Cursor * cursor;
29  bool done;
31  bool dataReady;
33  Record currentRow;
34 public:
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 
50 template <class T>
51 Cursor<T>::Cursor(const Database& db_, Backend::Cursor * c)
52  : db(db_), cursor(c), done(false), dataReady(false) {
53  operator++();
54 }
55 template <class T>
57  delete cursor;
58 }
59 template <class T>
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 
74 template <class T>
75 std::vector<T> Cursor<T>::dump() {
76  std::vector<T> res;
77  for (;!done;operator++())
78  res.push_back(operator*());
79  return res;
80 }
81 template <class T>
83  Record rec;
84 
85  if (!dataReady)
86  throw NotFound();
87 
88  return T(db,currentRow);
89 }
90 
91 }
92 
93 #endif
Definition: backend.hpp:14
An abstract base class for cursors that iterate result sets returned by relational database...
Definition: backend.hpp:23
Cursor< T > & operator++(int)
steps to next record
Definition: cursor.hpp:41
A base class of databases.
Definition: database.hpp:37
std::string operator*(int amount, const std::string &s)
returns a string which is duplicated &#39;amount&#39; times
Definition: string.cpp:101
contains class Record and typedef Records
Cursor< T > & operator++()
steps to next record
Definition: cursor.hpp:60
exception thrown when a record is not found
Definition: except.hpp:32
~Cursor()
deletes Backend::Cursor
Definition: cursor.hpp:56
SQL data row wrapper.
Definition: types.hpp:19
bool rowsLeft()
returns true if there are records left in the result set
Definition: cursor.hpp:47
Classes Backend, Backend::Cursor and Backend::Result.
used to iterate results of SQL statement, creates objects of type T from retrieved records...
Definition: cursor.hpp:22
std::vector< T > dump()
returns the rest of the result set in vector
Definition: cursor.hpp:75
T operator*()
returns current record
Definition: cursor.hpp:82

SourceForge.net Logo