[odb-users] unknown database schema ''

Diego Fernando lordvampyre at gmail.com
Thu Jan 29 13:56:24 EST 2015


I follow the tutorial to compile libodb-qt to use in Qt Creator.
Always return unknown database schema ''.

employee.hxx
#ifndef EMPLOYEE
#define EMPLOYEE

#include <string>

#include <odb/core.hxx>

#include <QtCore/QString>

using namespace std;
using namespace odb::core;

#pragma db object table("employee")
class Employee
{
public:
    Employee(const QString &name) : name_(name) {}
    ~Employee();

    void set_name(const QString &value);
    QString name() const;

private:
    friend class odb::access;
    Employee() {}

    #pragma db id auto
    int id_;

#pragma db column("name_employee") type("varchar(60)")
    QString name_;
};

main.cpp
#include <QCoreApplication>
#include <QDebug>
#include <memory>   // std::auto_ptr
#include <iostream>

#include <odb/database.hxx>
#include <odb/transaction.hxx>
#include <odb/schema-catalog.hxx>
#include <odb/database.hxx>
#  include <odb/pgsql/database.hxx>

//#include "database.h" // create_database

#include "employee.hxx"
#include "employee-odb.hxx"

using namespace std;
using namespace odb::core;


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    try
     {
       auto_ptr<database> db (new odb::pgsql::database(
                                  "postgres"
                                  , "1234"
                                  , "odb_test"
                                  , "localhost"
                                  , 5432));
        {

        transaction t (db->begin ());
        schema_catalog::create_schema(*db);
        t.commit ();
        }
     }
     catch (const odb::exception& e)
     {
       std::cout << "ERROR: " << e.what() << std::endl;
     }

    return a.exec();
}

.pro

#-------------------------------------------------
#
# Project created by QtCreator 2015-01-24T13:44:23
#
#-------------------------------------------------

QT       += core

QT       -= gui

TARGET = testodb
CONFIG   += console
CONFIG   -= app_bundle

TEMPLATE = app
DESTDIR += "_bin"
#LIBS += -L"_bin"
LIBS += -L"/usr/local/lib"

SOURCES += main.cpp \
    employee.cpp

# List of header files that should be compiled with the ODB compiler.
#
ODB_FILES += employee.hxx

# ODB compiler flags.
#
ODB_FLAGS = --database pgsql --profile qt --generate-schema
--generate-query --generate-session --std c++11

# Select the database we are going to use.
#
DEFINES += DATABASE_PGSQL

# Suppress unknown pragmas GCC warnings.
#
QMAKE_CXXFLAGS_WARN_ON = $$QMAKE_CXXFLAGS_WARN_ON -Wno-unknown-pragmas

# Link to the ODB runtime libraries.
#
LIBS += -lodb-pgsql
LIBS += -lodb-qt
LIBS += -lodb

# ODB compilation rules. Normally you don't need to change anything here.
#

# Add the Qt headers directory to the ODB include directory list.
#
ODB_FLAGS += -I$$[QT_INSTALL_HEADERS]

# Newer versions of QtCreator do builds in a separate directory. As a
# result, we need to append the source directory to ODB files.
#
for(dir, ODB_FILES) {
  ODB_PWD_FILES += $$PWD/$${dir}
}

odb.name = odb ${QMAKE_FILE_IN}
odb.input = ODB_PWD_FILES
odb.output = ${QMAKE_FILE_BASE}-odb.cxx
odb.commands = odb $$ODB_FLAGS ${QMAKE_FILE_IN}
odb.depends = $$ODB_PWD_FILES
odb.variable_out = SOURCES
odb.clean = ${QMAKE_FILE_BASE}-odb.cxx ${QMAKE_FILE_BASE}-odb.hxx
${QMAKE_FILE_BASE}-odb.ixx ${QMAKE_FILE_BASE}.sql
QMAKE_EXTRA_COMPILERS += odb

odbh.name = odb ${QMAKE_FILE_IN}
odbh.input = ODB_PWD_FILES
odbh.output = ${QMAKE_FILE_BASE}-odb.hxx
odbh.commands = @true
odbh.CONFIG = no_link
odbh.depends = ${QMAKE_FILE_BASE}-odb.cxx
QMAKE_EXTRA_COMPILERS += odbh

HEADERS += \
    database.h \
    employee.hxx


More information about the odb-users mailing list