[odb-users] Problem with 'char' field using ODB w/ SQLite

Tuxedo F. Catus tuxedo.catus at gmail.com
Tue Jan 15 13:04:56 EST 2013

I am having a problem with a char field not coming out of the database
correctly, even though it appears fine when I query the database using
the sqlite3 binary.  Every other field is coming back correctly,
except for the 'EventType' field in the ShockParametersPrimaryKey
structure below.

This is my structure:

-- snip here --

#pragma db value
struct ShockParametersPrimaryKey {
    ShockParametersPrimaryKey() {}
#pragma db type( "VARCHAR(16)" )
    std::string m_Symbol;
    char m_EventType;

#pragma db object table( "ShockParameters" )
class ShockParametersDB {
        friend class odb::access;

#pragma db id
        ShockParametersPrimaryKey m_PrimaryKey;

        double m_AlphaShockScore;
        double m_BetaShockScore;
        double m_GammaShockScore;
        double m_DeltaShockScore;
        double m_EpsilonShockScore;
        double m_ZetaShockScore;
        double m_EtaShockScore;
        double m_ThetaShockScore;
-- snip here --

This is the schema generated:

-- snip here --
CREATE TABLE "ShockParameters" (
  "PrimaryKey_Symbol" VARCHAR(16) NOT NULL,
  "PrimaryKey_EventType" INTEGER NOT NULL,
  "AlphaShockScore" REAL NOT NULL,
  "BetaShockScore" REAL NOT NULL,
  "GammaShockScore" REAL NOT NULL,
  "DeltaShockScore" REAL NOT NULL,
  "EpsilonShockScore" REAL NOT NULL,
  "ZetaShockScore" REAL NOT NULL,
  "EtaShockScore" REAL NOT NULL,
  "ThetaShockScore" REAL NOT NULL,


--snip here--

Data is loaded into the database with a statement like this:

INSERT INTO "ShockParameters"

Then the database is queried with the following code:

          std::cout << "Shock Parameter Query: " << std::endl;
          ShockParametersDBResults shockqueryresult( paramdb->query<
ShockParametersDB >() );
          if( shockqueryresult.empty() ) {
              std::cout << "No shock parameter information available;
default fees will be returned." << std::endl;
          } else {
              std::for_each( shockqueryresult.begin(),
shockqueryresult.end(), [&]( ShockParametersDB& shock ) {
B =>              std::cout << "Shock Parameter Dump: " << std::endl;
<--- Notice debug breakpoint here
                  std::cout << shock << std::endl;

But when I inspect the 'shock' value passed into the lamba at the
breakpoint ( B=> mark (emacs debug mode marker)), GDB shows me this --
notice the event type is not the 'T' that was loaded into the database
with the 'T' value:

$1 = (ShockParametersDB &) @0x634670: {

m_PrimaryKey = {m_Symbol = {static npos = <optimized out>, _M_dataplus
= {<std::allocator<char>> = {<__gnu_cxx::new_allocator<char>> = {<No
data fields>}, <No data fields>}, _M_p = 0x6374f8 "SIRI"}\

m_EventType = 0 '\000'},

m_AlphaShockScore = 0.65000000000000002,
m_BetaShockScore = 0.14999999999999999,
m_GammaShockScore = 0.94999999999999996,
m_DeltaShockScore = 0.59999999999999998,
m_EpsilonShockScore = 0.5,
m_ZetaShockScore = 0.10000000000000001,
m_EtaShockScore = 0.10000000000000001,
m_ThetaShockScore = 0.75


My question is why is the character for m_EventType not coming back
properly, while everything else does come back correctly?

Thank you, in advance, for your assistance.


More information about the odb-users mailing list