LiteSQL 0.3.10
backend.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
10#ifndef litesql_backend_hpp
11#define litesql_backend_hpp
12#include <memory>
13#include "litesql/types.hpp"
14namespace litesql {
15 using namespace std;
16
17
19 class Backend {
20 public:
23 class Cursor {
24 public:
26 virtual ~Cursor() {}
31 virtual void setCacheSize(int s) {}
34 virtual Record fetchOne()=0;
35 };
36 class Result {
37 public:
39 virtual ~Result() {}
41 virtual size_t fieldNum() const=0;
43 virtual Record fields() const=0;
45 virtual size_t recordNum() const=0;
47 virtual Records records() const=0;
48
49 };
50
51 virtual ~Backend() {}
54 virtual bool supportsSequences() const {
55 return false;
56 }
57
59 virtual string getRowIDType() const {
60 return "INTEGER PRIMARY KEY";
61 }
62
64 virtual string getInsertID() const { return ""; }
66 virtual void begin() const {}
68 virtual void commit() const {}
70 virtual void rollback() const {}
74 virtual Result* execute(const string& query) const = 0;
79 virtual Cursor* cursor(const string& query) const = 0;
87 virtual string groupInsert(Record tables, Records fields, Records values,
88 const string& sequence) const;
94 static Backend* getBackend(const string& type,const string& connInfo);
95
96 };
97}
98
99#endif
An abstract base class for cursors that iterate result sets returned by relational database.
Definition backend.hpp:23
virtual ~Cursor()
empty
Definition backend.hpp:26
virtual void setCacheSize(int s)
if inherited Cursor can cache its data to speed up iteration, this method is used to set cache size.
Definition backend.hpp:31
virtual Record fetchOne()=0
returns one result row.
Definition backend.hpp:36
virtual size_t recordNum() const =0
returns number of rows (records) in result set
virtual size_t fieldNum() const =0
returns number of columns (fields) in result set
virtual Record fields() const =0
returns names of columns (fields) of the result set
virtual ~Result()
empty
Definition backend.hpp:39
virtual Records records() const =0
returns result set
An abstract base class for interfacing with relational databases.
Definition backend.hpp:19
virtual string getInsertID() const
if backend supports this, new primary key of the last insert is returned
Definition backend.hpp:64
virtual Cursor * cursor(const string &query) const =0
executes SQL-query
virtual ~Backend()
empty
Definition backend.hpp:51
virtual void rollback() const
rollback SQL transaction
Definition backend.hpp:70
virtual string groupInsert(Record tables, Records fields, Records values, const string &sequence) const
executes multiple INSERT-statements and assigns same 'row id' for first field of every record
Definition backend.cpp:33
virtual bool supportsSequences() const
return true if backend supports CREATE SEQUENCE - SQL-statements
Definition backend.hpp:54
virtual string getRowIDType() const
backend may want to set an AUTO_INCREMENT-attribute for table's primary key field.
Definition backend.hpp:59
static Backend * getBackend(const string &type, const string &connInfo)
returns a backend according to Backendtype in type, parameters are specific to backend and are separa...
Definition backend.cpp:61
virtual void begin() const
begin SQL transaction, may or may not have an effect
Definition backend.hpp:66
virtual Result * execute(const string &query) const =0
executes SQL-query
virtual void commit() const
commit SQL transaction
Definition backend.hpp:68
SQL data row wrapper.
Definition types.hpp:20
contains class Record and typedef Records
std::vector< Record > Records
shortcut
Definition types.hpp:26

SourceForge.net Logo