Other sop/dbicpp

Table Of Contents

Previous topic

DBI Overlay Versioning Bug

Next topic

Admin Operating Procedures for SVN/Trac/MySQL

This Page

Daya Bay Links

Content Skeleton

DBI from C++

Almost all of DBI is usable from python using the DybDbi interface. It is unwise to use C++ when python can be used instead.

Primer for C++ usage of DBI

All table row instances are subclasses of DbiTableRow

These subclasses are generated from .spec by building DybDbi, include the generated header with:

#include "genDbi/GSupernovaTrigger.h"

Instanciate one of those and use API inherited from DbiTableRow.h to for example create the DB tables.

GSupernovaTrigger* st = GSupernovaTrigger();
st->CreateDatabaseTables( 0, "SupernovaTrigger" );

Raw C++ DBI

It is possible to use DBI from C++ entirely without DybDbi (other than DbiTableRow subclass generation). This is verbosely documented at Database

Such an approach would be based on the below classes, eg

#include "DatabaseInterface/DbiResultPtr.tpl"
template class  DbiResultPtr<GSupernovaTrigger>;

#include "DatabaseInterface/DbiWriter.tpl"
template class  DbiWriter<GSupernovaTrigger>;

C++ DybDbi

It is also possible to use the C++ DybDbi helper classes

  • DybRpt<T>
  • DybWrt<T>
  • DbiCtx

where T corresponds to a table row subclass such as GSupernovaTrigger

These classes were designed to be easy to use from python, eg by hiding their template nature and providing default contexts etc... and thus enable easy DBI usage.

Using these from C++ is not documented, as no one has had the need to do this, and the only example of usage is that by python DybDbi itself. Examine the generated classes to see what is provided.

  • Database/DybDbi/genDbi/GSupernovaTrigger.cc
  • Database/DybDbi/genDbi/GSupernovaTrigger.h

C++ DybDbi headers

#include "genDbi/GSupernovaTrigger.h"

#include "DybDbi/DbiRpt.tpl"
template class DybRpt<GSupernovaTrigger>

#include "DybDbi/DbiWrt.tpl"
template class DybWrt<GSupernovaTrigger>

#include "DybDbi/DbiCtx.h"