LiteSQL
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 
13 #include <memory>
14 #include "litesql/types.hpp"
15 #include "litesql/commontypes.h"
16 
17 namespace litesql {
18 
20  class Backend {
21  public:
24  class Cursor {
25  public:
27  virtual ~Cursor() {}
32  virtual void setCacheSize(int /*s*/ ) {}
35  virtual Record fetchOne()=0;
36  };
37  class Result {
38  public:
40  virtual ~Result() {}
42  virtual size_t fieldNum() const=0;
44  virtual Record fields() const=0;
46  virtual size_t recordNum() const=0;
48  virtual Records records() const=0;
49 
50  };
52  virtual ~Backend() {}
55  virtual bool supportsSequences() const {
56  return false;
57  }
58 
59  virtual std::string getSQLType(AT_field_type fieldType, const std::string& length="") const;
60  virtual std::string getCreateSequenceSQL(const std::string& name) const;
61  virtual std::string getSeqSQL(const std::string& sname) const;
62 
65  virtual std::string getRowIDType() const {
66  return "INTEGER PRIMARY KEY";
67  }
68 
71  virtual std::string getInsertID() const { return ""; }
73  virtual void begin() const {}
75  virtual void commit() const {}
77  virtual void rollback() const {}
81  virtual Result* execute(const std::string& query) const = 0;
86  virtual Cursor* cursor(const std::string& query) const = 0;
94  virtual std::string groupInsert(const Record& tables,
95  const Records& fields,
96  const Records& values,
97  const std::string& sequence) const;
103  static std::unique_ptr<Backend> getBackend(const std::string& type, const std::string& connInfo) noexcept(false);// DatabaseError);
104 
105  };
106 }
107 
108 #endif
An abstract base class for cursors that iterate result sets returned by relational database.
Definition: backend.hpp:24
virtual ~Cursor()
empty
Definition: backend.hpp:27
virtual void setCacheSize(int)
if inherited Cursor can cache its data to speed up iteration, this method is used to set cache size.
Definition: backend.hpp:32
virtual Record fetchOne()=0
returns one result row.
Definition: backend.hpp:37
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:40
virtual Records records() const =0
returns result set
An abstract base class for interfacing with relational databases.
Definition: backend.hpp:20
virtual Cursor * cursor(const std::string &query) const =0
executes SQL-query
virtual ~Backend()
empty
Definition: backend.hpp:52
virtual void rollback() const
rollback SQL transaction
Definition: backend.hpp:77
virtual bool supportsSequences() const
return true if backend supports CREATE SEQUENCE - SQL-statements
Definition: backend.hpp:55
virtual std::string getInsertID() const
if backend supports this, new primary key of the last insert is returned
Definition: backend.hpp:71
virtual std::string groupInsert(const Record &tables, const Records &fields, const Records &values, const std::string &sequence) const
executes multiple INSERT-statements and assigns same 'row id' for first field of every record
Definition: backend.cpp:74
virtual void begin() const
begin SQL transaction, may or may not have an effect
Definition: backend.hpp:73
static std::unique_ptr< Backend > getBackend(const std::string &type, const std::string &connInfo) noexcept(false)
returns a backend according to Backendtype in type, parameters are specific to backend and are separa...
Definition: backend.cpp:205
virtual Result * execute(const std::string &query) const =0
executes SQL-query
virtual std::string getRowIDType() const
backend may want to set an AUTO_INCREMENT-attribute for table's primary key field.
Definition: backend.hpp:65
virtual void commit() const
commit SQL transaction
Definition: backend.hpp:75
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