[odb-users] Error trying to create schema with polymorphic pragma

Stroud, Sean T ststrou at sandia.gov
Wed Sep 26 13:08:11 EDT 2012


Hi,

I get the following runtime error trying to create schema via the schema_catalog:

   Error: 1005 (HY000): Can't create table 'TEST_DB.Sensor_Product' (errno: 150)

I can't figure out what I am doing wrong.

Here are some details:
- I'm on RHEL 5.8
- I'm using ODB 2.1.0
- I have two classes Product and Sensor_Product (see files below).
- Sensor_Product inherits from Product.  Both use the "polymorphic" pragma.
- If I remove the "polymorphic" pragma, I no longer get the error.

Here is how I invoke odb on product.h and sensor_product.h:

  % which odb
  /home/ststrou/ODB2.1/odb-2.1.0-x86_64-linux-gnu/bin/odb

  % odb -d mysql -q -I /home/ststrou/ODB2.1_install/include --generate-schema --schema-format embedded product.h sensor_product.h

The "/home/ststrou/ODB2.1_install/" directory is where I've installed the odb 2.1.0 includes and libraries.

Here are the files I am using:

------------ file main.cc -----------------
#include <odb/database.hxx>
#include <odb/transaction.hxx>
#include <odb/mysql/database.hxx>
#include <odb/schema-catalog.hxx>

#include <iostream>
#include <stdlib.h>

using namespace std;
using namespace odb::core;

int main(int argc, char *argv[])
{
  try {
    auto_ptr<database> db (new odb::mysql::database (argc, argv));

    transaction t (db->begin ());
    schema_catalog::create_schema (*db);
    t.commit ();
  } catch ( odb::exception &ex) {
    cout << "Error: " << ex.what() << endl;
    exit(1);
  }
}

------------ file product.h -----------------
#ifndef Product_H
#define Product_H

#include <odb/core.hxx>

#pragma db object polymorphic
class Product {
  public:
    Product();

    virtual ~Product();

  protected:
    friend class odb::access;

    #pragma db id
    int  m_product_id;
};

#endif

------------ file product.cc -----------------
#include "product.h"

Product::Product()
{
  m_product_id = -1;
}

Product::~Product()
{
}

------------ file sensor_product.h -----------------
#ifndef Sensor_Product_H
#define Sensor_Product_H

#include "product.h"
#include <vector>

#include <odb/core.hxx>

#pragma db object polymorphic
class Sensor_Product : public Product {
  public:
    Sensor_Product();

    virtual ~Sensor_Product();

  private:
    friend class odb::access;

    #pragma db type("MEDIUMBLOB")
    std::vector<char> m_sensor_data;
};

#endif

------------ file sensor_product.cc -----------------
#include "sensor_product.h"

Sensor_Product::Sensor_Product()
{
}

Sensor_Product::~Sensor_Product()
{
}





More information about the odb-users mailing list