LiteSQL
Classes | Public Member Functions | Static Public Member Functions | List of all members
litesql::Backend Class Referenceabstract

An abstract base class for interfacing with relational databases. More...

#include <backend.hpp>

Classes

class  Cursor
 An abstract base class for cursors that iterate result sets returned by relational database. More...
 
class  Result
 

Public Member Functions

virtual ~Backend ()
 empty
 
virtual bool supportsSequences () const
 return true if backend supports CREATE SEQUENCE - SQL-statements
 
virtual std::string getSQLType (AT_field_type fieldType, const std::string &length="") const
 
virtual std::string getCreateSequenceSQL (const std::string &name) const
 
virtual std::string getSeqSQL (const std::string &sname) const
 
virtual std::string getRowIDType () const
 backend may want to set an AUTO_INCREMENT-attribute for table's primary key field. More...
 
virtual std::string getInsertID () const
 if backend supports this, new primary key of the last insert is returned
 
virtual void begin () const
 begin SQL transaction, may or may not have an effect
 
virtual void commit () const
 commit SQL transaction
 
virtual void rollback () const
 rollback SQL transaction
 
virtual Resultexecute (const std::string &query) const =0
 executes SQL-query More...
 
virtual Cursorcursor (const std::string &query) const =0
 executes SQL-query More...
 
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 More...
 

Static Public Member Functions

static std::unique_ptr< BackendgetBackend (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 separated by semicolon. More...
 

Detailed Description

An abstract base class for interfacing with relational databases.

Member Function Documentation

◆ cursor()

virtual Cursor* litesql::Backend::cursor ( const std::string &  query) const
pure virtual

executes SQL-query

Parameters
querySQL-query to execute
Returns
Cursor-object which can be used to iterate result set row by row without loading everything to memory

◆ execute()

virtual Result* litesql::Backend::execute ( const std::string &  query) const
pure virtual

executes SQL-query

Parameters
querySQL-query to execute
Returns
Result-object which holds result set of query

Referenced by groupInsert().

◆ getBackend()

unique_ptr< Backend > Backend::getBackend ( const std::string &  type,
const std::string &  connInfo 
)
staticnoexcept

returns a backend according to Backendtype in type, parameters are specific to backend and are separated by semicolon.

Parameters
typetype of the database backend (supported are : "mysql","postgresql","sqlite3","odbc"
connInfodatabase connection specific parameters (parameters are separated by semicolon)
Exceptions
DatabaseErrorif no backend is found

◆ getRowIDType()

virtual std::string litesql::Backend::getRowIDType ( ) const
inlinevirtual

backend may want to set an AUTO_INCREMENT-attribute for table's primary key field.

this method is to deliver the details to database schema

◆ groupInsert()

string Backend::groupInsert ( const Record tables,
const Records fields,
const Records values,
const std::string &  sequence 
) const
virtual

executes multiple INSERT-statements and assigns same 'row id' for first field of every record

Parameters
tablesdestination tables for insert operation
fieldsrecord of field names per table
valuesrecord of values per table
sequencesequence where row id-numbers are pulled
Returns
new row id

References litesql::escapeSQL(), execute(), getInsertID(), litesql::join(), litesql::Backend::Result::records(), and supportsSequences().


The documentation for this class was generated from the following files:

SourceForge.net Logo