C++ Database API Reference

The tef::Database and tef::Db<class FetchBuffer> classes provide an unified SQL-like interface (WebSQL) to both relational and non-relational (NoSQL) databases.

Database(const wchar_t* name);
Db(const wchar_t* name);
name: specifies a configured database connection.
See Database connections.
Database& operator<<(int sqlpart);
Database& operator<<(long long sqlpart);
Database& operator<<(double sqlpart);
Database& operator<<(const char* sqlpart);
Database& operator<<(const wchar_t* sqlpart);
Builds a SQL string.
template<typename F>
Db& operator>>(F& field);
Binds a fetch buffer.
bool HasTransaction() const;
tef::db::Transolation GetTransaction() const;
void SetTransaction(tef::db::Transolation value = tef::db::default);
void Commit();
void Rollback();
Provides the transaction support.
template<typename F>
void ExecuteAsync(F&& callback);
int Execute();
bool Fetch();
Executes the SQL.
void ThrowIfError(); Throws an exception in case of an error.
void BeginAttributes();
void EndAttributes();
Writes custom attributes specific to the database driver: HTTP request headers, etc. Note: custom attributes must be written before the SQL string. Every HTTP header must end with "\r\n". See the example bellow.
const wchar_t* ResponseAttribute(const wchar_t* name);
int ResponseAttributeInt32(const wchar_t* name);
Reads custom attributes specific to the database driver: HTTP response headers, etc. Note: the returned pointer is valid within lifetime of the tef::Database instance. See the example bellow.

ODBC Example:

tef::Database db(L"ms");
db << L"insert ROOT (UID, USR) values (" << uid << L",'" << usr << L"')";
db.Execute();
        
struct Record
{
    tef::db::type<__int64> uid;
    tef::db::type<wchar_t, 30> usr;
};
tef::Db<Record> db(L"ms");
db << L"select UID, USR from ROOT";
db >> db->uid >> db->usr;
while( db.Fetch() ) {
    printf_s("%I64d", db->uid.value);
}
        

JSON Example:

tef::Database db(L"doc");
db.BeginAttributes();
db << "If-Match: \"" << _etag << "\"\r\n";
db.EndAttributes();
db << "replace ROOT { \"UID\": " << uid << ", \"USR\": \"" << usr << "\"}";
db.ExecuteAsync([](tef::Database& db) {
    try {
        db.ThrowIfError();
        int charge = db.ResponseAttributeInt32(L"x-ms-request-charge");
    } catch(std::exception& e) {
    }
});
        
tef::Db<tef::db::json> db(L"doc");
db << "select * from ROOT";
db.ExecuteAsync([](tef::Db<tef::db::json>& db) {
    try {
        while( db.Fetch() ) {
            printf_s("%I64d", db["UID"]);
        }
    } catch(std::exception& e) {
    }
});
        

See Also:

C++ API Reference

WebSQL Reference

Table of Contents