Qt + Postgres + Composite key

Open discussion on QxOrm library

Qt + Postgres + Composite key

Postby ramirezcris.cris » Wed Sep 21, 2011 2:45 pm

I have a doubt with composite keys: :roll:

I want to use a composite key in a class, I want the composite key for two long integer type fields each, however to make the declaration of the class with the composite key type using two long integers, the program generates a compile error, but if I declare the composite key with a string and a long integer, the error is not generated and the program runs correctly.

Although it works well, I wish that the statement could do with the two long integers.

Now annex the examples database, main.cpp, BTipoListado.h without error and BTipoListado.h with error:

Database:

Create two tables in postgres: bTipoListado and bTipoListado with the following SQL:

!—Tabla Tipo Secuencial
CREATE TABLE bListado
(
PK_CodigoListado int8 DEFAULT NEXTVAL('PK_CodigoListado_seq') NOT NULL,
DescripcionListado varchar(100),
primary key (PK_CodigoListado)
);

CREATE SEQUENCE PK_CodigoListado_seq;

!—Tabla Tipo Clave Compuesta
CREATE TABLE bTipoListado (
PK_CodigoTipoListado int8 not null,
FK_CodigoListado int8 not null,
DescripcionTipoListado varchar(100),
primary key (PK_CodigoTipoListado, FK_CodigoListado)
);


Main.cpp:

Code: Select all
#include "../include/precompiled.h"
#include "../include/bListado.h"
#include "../include/bTipoListado.h"
#include <QtCore/qcoreapplication.h>
#include <QxMemLeak.h>
#include <QtGui/qapplication.h>

int main(int argc, char * argv[])
{
    // Aplicación Qt
    QApplication app(argc, argv);

    // ************************ BASE DE DATOS ************************

    // Inicializa los parámetros para la comunicación con la base de datos
    qx::QxSqlDatabase::getSingleton()->setDriverName("QPSQL");
    qx::QxSqlDatabase::getSingleton()->setDatabaseName("BD1.2");
    qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
    qx::QxSqlDatabase::getSingleton()->setUserName("postgres");
    qx::QxSqlDatabase::getSingleton()->setPassword("postgres");
    qx::QxSqlDatabase::getSingleton()->setPort(5432);



    // ************************ INSERTAR OBJETOS ************************

    // Control de errores
    QSqlError daoError;

    qx::QxSqlQuery query("WHERE bTipoListado.DescripcionTipoListado = 'Calculados'");

    lista_btipo lista;

    daoError = qx::dao::fetch_by_query(query, lista);

    for (long l = 0; l < lista.count(); ++l)
    {
       bTipoListado_ptr p = lista.getByIndex(l);
       qDebug() << "DescripcionTipoListado: " << qPrintable(p->DescripcionTipoListado);
       qDebug() << "CodigoTipoListado: " << p->GetPK_CodigoTipoListado();
       qDebug() << "CodigoListado: " << p->GetFK_CodigoListado();
    }
    return 0;
}


BTipoListado.h - Example without error:

Code: Select all
#include "../include/bListado.h"
#ifndef _QX_SUITE_BTIPOLISTADO_H_
#define _QX_SUITE_BTIPOLISTADO_H_

class QX_SUITE_DLL_EXPORT bTipoListado
{
public:
   // Clave compuesta (multiples-columnas de clave primaria en la base de datos)
   typedef boost::tuple<QString, long> QCompuesta;
   static QString str_composite_key() { return "PK_CodigoTipoListado|FK_CodigoListado"; }

   QCompuesta PK_Compuesta;
   QString DescripcionTipoListado;

   // Constructor y Destructor
   bTipoListado(): PK_Compuesta("0",0) { ; }
   virtual ~bTipoListado() { ; }

   // Metodos "Get" para la clave compuesta
   QCompuesta GetClaveCompuesta() const {return PK_Compuesta;}
   QString GetPK_CodigoTipoListado() const {return boost::tuples::get<0>(PK_Compuesta);}
   long GetFK_CodigoListado() const {return boost::tuples::get<1>(PK_Compuesta);}

   // Metodos "Set" para la clave compuesta
   void SetPK_CodigoTipoListado(QString codigoTipoListado) {boost::tuples::get<0>(PK_Compuesta) = codigoTipoListado;}
   void SetPK_CodigoListado(long codigoListado) {boost::tuples::get<1>(PK_Compuesta) = codigoListado;}
};

QX_REGISTER_PRIMARY_KEY(bTipoListado, bTipoListado::QCompuesta)
QX_REGISTER_HPP_QX_SUITE(bTipoListado, qx::trait::no_base_class_defined, 0)

// Crea objeto 'bListado'
typedef boost::shared_ptr<bTipoListado> bTipoListado_ptr;

// Lista de objetos 'bTipoListado'
typedef qx::QxCollection<bTipoListado::QCompuesta, bTipoListado_ptr> lista_btipo;

#endif


Results generated without error:

Code: Select all
Debugging starts
QxOrm.DllMain() ---> DLL_PROCESS_ATTACH
QxOrm.DllMain() ---> DLL_THREAD_ATTACH
[QxOrm] qx::QxSqlDatabase : create new database connection in thread '3636' with key '{a01dbe90-a538-4607-ad93-27724399e191}'
[QxOrm] sql query (2572 ms) : SELECT bTipoListado.PK_CodigoTipoListado AS bTipoListado_PK_CodigoTipoListado_0, bTipoListado.FK_CodigoListado AS bTipoListado_FK_CodigoListado_0, bTipoListado.DescripcionTipoListado AS bTipoListado_DescripcionTipoListado_0 FROM bTipoListado WHERE bTipoListado.DescripcionTipoListado = 'Calculados'
DescripcionTipoListado:  Calculados
CodigoTipoListado:  "2"
CodigoListado:  1
QxOrm.DllMain() ---> DLL_THREAD_DETACH
QxOrm.DllMain() ---> DLL_PROCESS_DETACH
Debugging has finished


BTipoListado.h - Example with error:

Code: Select all
#include "../include/bListado.h"
#ifndef _QX_SUITE_BTIPOLISTADO_H_
#define _QX_SUITE_BTIPOLISTADO_H_

class QX_SUITE_DLL_EXPORT bTipoListado
{
public:
   // Clave compuesta (multiples-columnas de clave primaria en la base de datos)
   typedef boost::tuple<long, long> QCompuesta;
   static QString str_composite_key() { return "PK_CodigoTipoListado|FK_CodigoListado"; }

   QCompuesta PK_Compuesta;
   QString DescripcionTipoListado;

   // Constructor y Destructor
   bTipoListado(): PK_Compuesta(0,0) { ; }
   virtual ~bTipoListado() { ; }

   // Metodos "Get" para la clave compuesta
   QCompuesta GetClaveCompuesta() const {return PK_Compuesta;}
   long GetPK_CodigoTipoListado() const {return boost::tuples::get<0>(PK_Compuesta);}
   long GetFK_CodigoListado() const {return boost::tuples::get<1>(PK_Compuesta);}

   // Metodos "Set" para la clave compuesta
   void SetPK_CodigoTipoListado(long codigoTipoListado) {boost::tuples::get<0>(PK_Compuesta) = codigoTipoListado;}
   void SetPK_CodigoListado(long codigoListado) {boost::tuples::get<1>(PK_Compuesta) = codigoListado;}
};

QX_REGISTER_PRIMARY_KEY(bTipoListado, bTipoListado::QCompuesta)
QX_REGISTER_HPP_QX_SUITE(bTipoListado, qx::trait::no_base_class_defined, 0)

// Crea objeto 'bListado'
typedef boost::shared_ptr<bTipoListado> bTipoListado_ptr;

// Lista de objetos 'bTipoListado'
typedef qx::QxCollection<bTipoListado::QCompuesta, bTipoListado_ptr> lista_btipo;

#endif


Compile error:

Code: Select all
Running build steps for project qxEjemplo1.2...
Configuration unchanged, skipping qmake step.
Starting: "D:\Qt\qtcreator-2.2.1\mingw\bin\mingw32-make.exe"
D:/Qt/qtcreator-2.2.1/mingw/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `D:/Qt/QxOrm/test/qxEjemplo1-2-build-desktop'
g++ -c -include debug\precompiled.h -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -D_CONSTRUYENDO_QX_SUITE -DQT_DLL -DQT_SQL_LIB -DQT_XML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\4.7.3\include\QtCore" -I"..\..\..\4.7.3\include\QtNetwork" -I"..\..\..\4.7.3\include\QtGui" -I"..\..\..\4.7.3\include\QtXml" -I"..\..\..\4.7.3\include\QtSql" -I"..\..\..\4.7.3\include" -I"..\qxEjemplo1.2\include" -I"..\..\boost" -I"..\..\include" -I"..\..\..\4.7.3\include\ActiveQt" -I"qt\moc" -I"..\qxEjemplo1.2" -I"." -I"..\..\..\4.7.3\mkspecs\win32-g++" -o debug\bTipoListado.o ..\qxEjemplo1.2\src\bTipoListado.cpp
g++ -c -include debug\precompiled.h -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -D_CONSTRUYENDO_QX_SUITE -DQT_DLL -DQT_SQL_LIB -DQT_XML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\..\4.7.3\include\QtCore" -I"..\..\..\4.7.3\include\QtNetwork" -I"..\..\..\4.7.3\include\QtGui" -I"..\..\..\4.7.3\include\QtXml" -I"..\..\..\4.7.3\include\QtSql" -I"..\..\..\4.7.3\include" -I"..\qxEjemplo1.2\include" -I"..\..\boost" -I"..\..\include" -I"..\..\..\4.7.3\include\ActiveQt" -I"qt\moc" -I"..\qxEjemplo1.2" -I"." -I"..\..\..\4.7.3\mkspecs\win32-g++" -o debug\main.o ..\qxEjemplo1.2\src\main.cpp
In file included from ..\..\boost/boost/functional/hash/hash.hpp:494,
                 from ..\..\boost/boost/functional/hash.hpp:6,
                 from ..\..\boost/boost/unordered/unordered_map.hpp:17,
                 from ..\..\boost/boost/unordered_map.hpp:16,
                 from ..\..\include/QxPrecompiled.h:84,
                 from ..\..\include/QxOrm.h:49,
                 from ..\qxEjemplo1.2\include\precompiled.h:4:
..\..\boost/boost/functional/hash/extensions.hpp: In member function 'size_t boost::hash<T>::operator()(const T&) const [with T = boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>]':
..\..\boost/boost/multi_index/hashed_index.hpp:439:   instantiated from 'boost::multi_index::detail::hashed_index_iterator<boost::multi_index::detail::hashed_index_node<typename SuperMeta::type::node_type>, boost::multi_index::detail::bucket_array<typename SuperMeta::type::final_allocator_type> > boost::multi_index::detail::hashed_index<KeyFromValue, Hash, Pred, SuperMeta, TagList, Category>::find(const CompatibleKey&, const CompatibleHash&, const CompatiblePred&) const [with CompatibleKey = boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, CompatibleHash = boost::hash<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, CompatiblePred = std::equal_to<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, KeyFromValue = boost::multi_index::member<QPair<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >, boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, &QPair<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >::first>, Hash = boost::hash<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, Pred = std::equal_to<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, SuperMeta = boost::multi_index::detail::nth_layer<2, QPair<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >, boost::multi_index::indexed_by<boost::multi_index::random_access<boost::multi_index::tag<mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na> >, boost::multi_index::hashed_unique<boost::multi_index::member<QPair<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >, boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, &QPair<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >::first>, mpl_::na, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<QPair<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> > > >, TagList = boost::mpl::vector0<mpl_::na>, Category = boost::multi_index::detail::hashed_unique_tag]'
..\..\boost/boost/multi_index/hashed_index.hpp:429:   instantiated from 'boost::multi_index::detail::hashed_index_iterator<boost::multi_index::detail::hashed_index_node<typename SuperMeta::type::node_type>, boost::multi_index::detail::bucket_array<typename SuperMeta::type::final_allocator_type> > boost::multi_index::detail::hashed_index<KeyFromValue, Hash, Pred, SuperMeta, TagList, Category>::find(const CompatibleKey&) const [with CompatibleKey = boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, KeyFromValue = boost::multi_index::member<QPair<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >, boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, &QPair<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >::first>, Hash = boost::hash<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, Pred = std::equal_to<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >, SuperMeta = boost::multi_index::detail::nth_layer<2, QPair<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >, boost::multi_index::indexed_by<boost::multi_index::random_access<boost::multi_index::tag<mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na> >, boost::multi_index::hashed_unique<boost::multi_index::member<QPair<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >, boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, &QPair<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >::first>, mpl_::na, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<QPair<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> > > >, TagList = boost::mpl::vector0<mpl_::na>, Category = boost::multi_index::detail::hashed_unique_tag]'
..\..\include/QxCollection/../../inl/QxCollection/QxCollection.inl:179:   instantiated from 'bool qx::QxCollection<Key, Value>::contains(const Key&) const [with Key = boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, Value = boost::shared_ptr<bTipoListado>]'
..\..\include/QxCollection/../../inl/QxCollection/QxCollection.inl:185:   instantiated from 'bool qx::QxCollection<Key, Value>::exist(const Key&) const [with Key = boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, Value = boost::shared_ptr<bTipoListado>]'
..\..\include/QxCollection/../../inl/QxCollection/QxCollection.inl:209:   instantiated from 'bool qx::QxCollection<Key, Value>::insert(const Key&, const Value&) [with Key = boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, Value = boost::shared_ptr<bTipoListado>]'
..\..\include/QxTraits/generic_container.h:311:   instantiated from 'static void qx::trait::generic_container<qx::QxCollection<Key, Value> >::insertItem(qx::QxCollection<Key, Value>&, qx::trait::generic_container_item<Key, Value>&) [with Key = boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, Value = boost::shared_ptr<bTipoListado>]'
..\..\include/QxDao/../../inl/QxDao/QxDao_FetchAll.inl:87:   instantiated from 'static void qx::dao::detail::QxDao_FetchAll_Container<T>::insertNewItem(T&, qx::dao::detail::QxDao_Helper_Container<T>&) [with T = qx::QxCollection<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >]'
..\..\include/QxDao/../../inl/QxDao/QxDao_FetchAll.inl:68:   instantiated from 'static QSqlError qx::dao::detail::QxDao_FetchAll_Container<T>::fetchAll(const qx::QxSqlQuery&, T&, QSqlDatabase*, const QStringList&) [with T = qx::QxCollection<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >]'
..\..\include/QxDao/../../inl/QxDao/QxDao_FetchAll.inl:111:   instantiated from 'static QSqlError qx::dao::detail::QxDao_FetchAll<T>::fetchAll(const qx::QxSqlQuery&, T&, QSqlDatabase*, const QStringList&) [with T = qx::QxCollection<boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>, boost::shared_ptr<bTipoListado> >]'
..\..\include/QxDao/QxDao.h:703:   instantiated from 'QSqlError qx::dao::fetch_by_query(const qx::QxSqlQuery&, T&) [with T = lista_btipo]'
..\qxEjemplo1.2\src\main.cpp:32:   instantiated from here
..\..\boost/boost/functional/hash/extensions.hpp:176: error: no hay una función coincidente para la llamada a 'hash_value(const boost::tuples::tuple<long int, long int, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>&)'
..\..\boost/boost/functional/hash/hash.hpp:120: nota: los candidatos son: size_t boost::hash_value(bool)
..\..\boost/boost/functional/hash/hash.hpp:125: nota:                     size_t boost::hash_value(char)
..\..\boost/boost/functional/hash/hash.hpp:130: nota:                     size_t boost::hash_value(unsigned char)
..\..\boost/boost/functional/hash/hash.hpp:135: nota:                     size_t boost::hash_value(signed char)
..\..\boost/boost/functional/hash/hash.hpp:140: nota:                     size_t boost::hash_value(short int)
..\..\boost/boost/functional/hash/hash.hpp:145: nota:                     size_t boost::hash_value(short unsigned int)
..\..\boost/boost/functional/hash/hash.hpp:150: nota:                     size_t boost::hash_value(int)
..\..\boost/boost/functional/hash/hash.hpp:155: nota:                     size_t boost::hash_value(unsigned int)
..\..\boost/boost/functional/hash/hash.hpp:160: nota:                     size_t boost::hash_value(long int)
..\..\boost/boost/functional/hash/hash.hpp:165: nota:                     size_t boost::hash_value(long unsigned int)
..\..\boost/boost/functional/hash/hash.hpp:171: nota:                     size_t boost::hash_value(wchar_t)
..\..\boost/boost/functional/hash/hash.hpp:178: nota:                     size_t boost::hash_value(boost::long_long_type)
..\..\boost/boost/functional/hash/hash.hpp:183: nota:                     size_t boost::hash_value(boost::ulong_long_type)
..\..\boost/boost/functional/hash/hash.hpp:297: nota:                     size_t boost::hash_value(float)
..\..\boost/boost/functional/hash/hash.hpp:302: nota:                     size_t boost::hash_value(double)
..\..\boost/boost/functional/hash/hash.hpp:307: nota:                     size_t boost::hash_value(long double)
mingw32-make[1]: Leaving directory `D:/Qt/QxOrm/test/qxEjemplo1-2-build-desktop'
mingw32-make[1]: *** [debug/main.o] Error 1
mingw32-make: *** [debug] Error 2
The process "D:\Qt\qtcreator-2.2.1\mingw\bin\mingw32-make.exe" exited with code 2.
Error while building project qxEjemplo1.2 (target: Desktop)
When executing build step 'Make'


Thanks again for any help. :)
ramirezcris.cris
 

Re: Qt + Postgres + Composite key

Postby QxOrm admin » Wed Sep 21, 2011 4:13 pm

Hi,

Your code compiles fine with Visual C++.
But I think there is a problem in the file './QxOrm/include/QxCommon/QxHashValue.h', all 'hash_value' functions must be included into namespace boost.
So you can try to apply this patch in the 'QxHashValue.h' file :

Code: Select all
#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
#include <boost/tuple/tuple_io.hpp>

namespace boost {

inline std::size_t hash_value(const QString & s)      { return qHash(s); }
inline std::size_t hash_value(const QDate & d)        { return qHash(d.toJulianDay()); }

......

} // namespace boost

#endif // _QX_HASH_VALUE_H_


Another thing : when you use qx::QxSqlQuery class, it is better to use placeholder in your SQL query, for example :
Code: Select all
qx::QxSqlQuery query("WHERE bTipoListado.DescripcionTipoListado = :my_variable");
query.bind(":my_variable", "Calculados");
QxOrm admin
 

Qt + Postgres + Composite key

Postby ramirez.cris » Wed Sep 21, 2011 8:52 pm

Hello again:

Thanks for answering:

I try to make the patch mentioned in the file '. / QxOrm / include / QxCommon / QxHashValue.h', however, when I compile with "make" gives me error and not allow the compilation:

QxHashValue.h

Code: Select all
/****************************************************************************
**
** http://www.qxorm.com/
** http://sourceforge.net/projects/qxorm/
** Original file by Lionel Marty
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software.
**
** GNU Lesser General Public License Usage
** This file must be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file 'license.lgpl.txt' included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you have questions regarding the use of this file, please contact :
** contact@qxorm.com
**
****************************************************************************/

#ifndef _QX_HASH_VALUE_H_
#define _QX_HASH_VALUE_H_

#ifdef _MSC_VER
#pragma once
#endif

/*!
 * \file QxHashValue.h
 * \author Lionel Marty
 * \ingroup QxCommon
 * \brief Specialize hash_value function for some Qt and boost types (used for example by qx::QxCollection<Key, Value> container)
 */

#include <QtCore/qstring.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qvariant.h>

#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
#include <boost/tuple/tuple_io.hpp>

namespace boost {
inline std::size_t hash_value(const QString & s)      { return qHash(s); }
inline std::size_t hash_value(const QDate & d)        { return qHash(d.toJulianDay()); }
inline std::size_t hash_value(const QTime & t)        { return qHash(t.toString()); }
inline std::size_t hash_value(const QDateTime & dt)   { return qHash(dt.toString()); }
inline std::size_t hash_value(const QVariant & v)     { return qHash(v.toString()); }

template <typename T0, typename T1>
inline std::size_t hash_value(const boost::tuple<T0, T1> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   return seed;
}

template <typename T0, class T1, typename T2>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3, typename T4>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   boost::hash_combine(seed, boost::get<4>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   boost::hash_combine(seed, boost::get<4>(tu));
   boost::hash_combine(seed, boost::get<5>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   boost::hash_combine(seed, boost::get<4>(tu));
   boost::hash_combine(seed, boost::get<5>(tu));
   boost::hash_combine(seed, boost::get<6>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   boost::hash_combine(seed, boost::get<4>(tu));
   boost::hash_combine(seed, boost::get<5>(tu));
   boost::hash_combine(seed, boost::get<6>(tu));
   boost::hash_combine(seed, boost::get<7>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   boost::hash_combine(seed, boost::get<4>(tu));
   boost::hash_combine(seed, boost::get<5>(tu));
   boost::hash_combine(seed, boost::get<6>(tu));
   boost::hash_combine(seed, boost::get<7>(tu));
   boost::hash_combine(seed, boost::get<8>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   boost::hash_combine(seed, boost::get<4>(tu));
   boost::hash_combine(seed, boost::get<5>(tu));
   boost::hash_combine(seed, boost::get<6>(tu));
   boost::hash_combine(seed, boost::get<7>(tu));
   boost::hash_combine(seed, boost::get<8>(tu));
   boost::hash_combine(seed, boost::get<9>(tu));
   return seed;
}
} // namespace boost
#endif // _QX_HASH_VALUE_H_


Compile error:

Code: Select all
D:\Qt\QxOrm>qmake

D:\Qt\QxOrm>make
mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory `D:/Qt/QxOrm'
g++ -x c++-header -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGE
FILE_SUPPORT -D_QX_BUILDING_QX_ORM -DQT_DLL -DQT_SQL_LIB -DQT_XML_LIB -DQT_GUI_L
IB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -D
QT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\4.7.3\include\QtCore" -I
"..\4.7.3\include\QtNetwork" -I"..\4.7.3\include\QtGui" -I"..\4.7.3\include\QtXm
l" -I"..\4.7.3\include\QtSql" -I"..\4.7.3\include" -I"include" -I"boost" -I"..\4
.7.3\include\ActiveQt" -I"qt\moc" -I"..\4.7.3\mkspecs\win32-g++" -o debug\QxPrec
ompiled.h.gch\c++ include\QxPrecompiled.h
g++ -c -include debug\QxPrecompiled.h -g -frtti -fexceptions -mthreads -Wall -DU
NICODE -DQT_LARGEFILE_SUPPORT -D_QX_BUILDING_QX_ORM -DQT_DLL -DQT_SQL_LIB -DQT_X
ML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW
 -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\4.7.3\i
nclude\QtCore" -I"..\4.7.3\include\QtNetwork" -I"..\4.7.3\include\QtGui" -I"..\4
.7.3\include\QtXml" -I"..\4.7.3\include\QtSql" -I"..\4.7.3\include" -I"include"
-I"boost" -I"..\4.7.3\include\ActiveQt" -I"qt\moc" -I"..\4.7.3\mkspecs\win32-g++
" -o debug\bool_array.o src\QxMemLeak\bool_array.cpp
g++ -c -include debug\QxPrecompiled.h -g -frtti -fexceptions -mthreads -Wall -DU
NICODE -DQT_LARGEFILE_SUPPORT -D_QX_BUILDING_QX_ORM -DQT_DLL -DQT_SQL_LIB -DQT_X
ML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW
 -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\4.7.3\i
nclude\QtCore" -I"..\4.7.3\include\QtNetwork" -I"..\4.7.3\include\QtGui" -I"..\4
.7.3\include\QtXml" -I"..\4.7.3\include\QtSql" -I"..\4.7.3\include" -I"include"
-I"boost" -I"..\4.7.3\include\ActiveQt" -I"qt\moc" -I"..\4.7.3\mkspecs\win32-g++
" -o debug\debug_new.o src\QxMemLeak\debug_new.cpp
g++ -c -include debug\QxPrecompiled.h -g -frtti -fexceptions -mthreads -Wall -DU
NICODE -DQT_LARGEFILE_SUPPORT -D_QX_BUILDING_QX_ORM -DQT_DLL -DQT_SQL_LIB -DQT_X
ML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW
 -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\4.7.3\i
nclude\QtCore" -I"..\4.7.3\include\QtNetwork" -I"..\4.7.3\include\QtGui" -I"..\4
.7.3\include\QtXml" -I"..\4.7.3\include\QtSql" -I"..\4.7.3\include" -I"include"
-I"boost" -I"..\4.7.3\include\ActiveQt" -I"qt\moc" -I"..\4.7.3\mkspecs\win32-g++
" -o debug\mem_pool_base.o src\QxMemLeak\mem_pool_base.cpp
g++ -c -include debug\QxPrecompiled.h -g -frtti -fexceptions -mthreads -Wall -DU
NICODE -DQT_LARGEFILE_SUPPORT -D_QX_BUILDING_QX_ORM -DQT_DLL -DQT_SQL_LIB -DQT_X
ML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW
 -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\4.7.3\i
nclude\QtCore" -I"..\4.7.3\include\QtNetwork" -I"..\4.7.3\include\QtGui" -I"..\4
.7.3\include\QtXml" -I"..\4.7.3\include\QtSql" -I"..\4.7.3\include" -I"include"
-I"boost" -I"..\4.7.3\include\ActiveQt" -I"qt\moc" -I"..\4.7.3\mkspecs\win32-g++
" -o debug\static_mem_pool.o src\QxMemLeak\static_mem_pool.cpp
g++ -c -include debug\QxPrecompiled.h -g -frtti -fexceptions -mthreads -Wall -DU
NICODE -DQT_LARGEFILE_SUPPORT -D_QX_BUILDING_QX_ORM -DQT_DLL -DQT_SQL_LIB -DQT_X
ML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW
 -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\4.7.3\i
nclude\QtCore" -I"..\4.7.3\include\QtNetwork" -I"..\4.7.3\include\QtGui" -I"..\4
.7.3\include\QtXml" -I"..\4.7.3\include\QtSql" -I"..\4.7.3\include" -I"include"
-I"boost" -I"..\4.7.3\include\ActiveQt" -I"qt\moc" -I"..\4.7.3\mkspecs\win32-g++
" -o debug\IxSingleton.o src\QxSingleton\IxSingleton.cpp
g++ -c -include debug\QxPrecompiled.h -g -frtti -fexceptions -mthreads -Wall -DU
NICODE -DQT_LARGEFILE_SUPPORT -D_QX_BUILDING_QX_ORM -DQT_DLL -DQT_SQL_LIB -DQT_X
ML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW
 -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\4.7.3\i
nclude\QtCore" -I"..\4.7.3\include\QtNetwork" -I"..\4.7.3\include\QtGui" -I"..\4
.7.3\include\QtXml" -I"..\4.7.3\include\QtSql" -I"..\4.7.3\include" -I"include"
-I"boost" -I"..\4.7.3\include\ActiveQt" -I"qt\moc" -I"..\4.7.3\mkspecs\win32-g++
" -o debug\QxSingletonX.o src\QxSingleton\QxSingletonX.cpp
g++ -c -include debug\QxPrecompiled.h -g -frtti -fexceptions -mthreads -Wall -DU
NICODE -DQT_LARGEFILE_SUPPORT -D_QX_BUILDING_QX_ORM -DQT_DLL -DQT_SQL_LIB -DQT_X
ML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW
 -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\4.7.3\i
nclude\QtCore" -I"..\4.7.3\include\QtNetwork" -I"..\4.7.3\include\QtGui" -I"..\4
.7.3\include\QtXml" -I"..\4.7.3\include\QtSql" -I"..\4.7.3\include" -I"include"
-I"boost" -I"..\4.7.3\include\ActiveQt" -I"qt\moc" -I"..\4.7.3\mkspecs\win32-g++
" -o debug\IxFactory.o src\QxFactory\IxFactory.cpp
g++ -c -include debug\QxPrecompiled.h -g -frtti -fexceptions -mthreads -Wall -DU
NICODE -DQT_LARGEFILE_SUPPORT -D_QX_BUILDING_QX_ORM -DQT_DLL -DQT_SQL_LIB -DQT_X
ML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW
 -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\4.7.3\i
nclude\QtCore" -I"..\4.7.3\include\QtNetwork" -I"..\4.7.3\include\QtGui" -I"..\4
.7.3\include\QtXml" -I"..\4.7.3\include\QtSql" -I"..\4.7.3\include" -I"include"
-I"boost" -I"..\4.7.3\include\ActiveQt" -I"qt\moc" -I"..\4.7.3\mkspecs\win32-g++
" -o debug\QxFactoryX.o src\QxFactory\QxFactoryX.cpp
g++ -c -include debug\QxPrecompiled.h -g -frtti -fexceptions -mthreads -Wall -DU
NICODE -DQT_LARGEFILE_SUPPORT -D_QX_BUILDING_QX_ORM -DQT_DLL -DQT_SQL_LIB -DQT_X
ML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW
 -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\4.7.3\i
nclude\QtCore" -I"..\4.7.3\include\QtNetwork" -I"..\4.7.3\include\QtGui" -I"..\4
.7.3\include\QtXml" -I"..\4.7.3\include\QtSql" -I"..\4.7.3\include" -I"include"
-I"boost" -I"..\4.7.3\include\ActiveQt" -I"qt\moc" -I"..\4.7.3\mkspecs\win32-g++
" -o debug\QxCollection.o src\QxCollection\QxCollection.cpp
g++ -c -include debug\QxPrecompiled.h -g -frtti -fexceptions -mthreads -Wall -DU
NICODE -DQT_LARGEFILE_SUPPORT -D_QX_BUILDING_QX_ORM -DQT_DLL -DQT_SQL_LIB -DQT_X
ML_LIB -DQT_GUI_LIB -DQT_NETWORK_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW
 -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -I"..\4.7.3\i
nclude\QtCore" -I"..\4.7.3\include\QtNetwork" -I"..\4.7.3\include\QtGui" -I"..\4
.7.3\include\QtXml" -I"..\4.7.3\include\QtSql" -I"..\4.7.3\include" -I"include"
-I"boost" -I"..\4.7.3\include\ActiveQt" -I"qt\moc" -I"..\4.7.3\mkspecs\win32-g++
" -o debug\QxCache.o src\QxCommon\QxCache.cpp
In file included from boost/boost/functional/hash/hash.hpp:494,
                 from boost/boost/functional/hash.hpp:6,
                 from boost/boost/unordered/unordered_map.hpp:17,
                 from boost/boost/unordered_map.hpp:16,
                 from include\QxPrecompiled.h:84:
boost/boost/functional/hash/extensions.hpp: In member function 'size_t boost::ha
sh<T>::operator()(const T&) const [with T = QString]':
boost/boost/multi_index/hashed_index.hpp:289:   instantiated from 'size_t boost:
:multi_index::detail::hashed_index<KeyFromValue, Hash, Pred, SuperMeta, TagList,
 Category>::erase(typename boost::call_traits<typename KeyFromValue::result_type
>::param_type) [with KeyFromValue = boost::multi_index::member<QPair<QString, st
d::pair<long int, boost::any> >, QString, &QPair<QString, std::pair<long int, bo
ost::any> >::first>, Hash = boost::hash<QString>, Pred = std::equal_to<QString>,
 SuperMeta = boost::multi_index::detail::nth_layer<2, QPair<QString, std::pair<l
ong int, boost::any> >, boost::multi_index::indexed_by<boost::multi_index::rando
m_access<boost::multi_index::tag<mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::n
a, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::n
a, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na> >, boos
t::multi_index::hashed_unique<boost::multi_index::member<QPair<QString, std::pai
r<long int, boost::any> >, QString, &QPair<QString, std::pair<long int, boost::a
ny> >::first>, mpl_::na, mpl_::na, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_
::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_
::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocato
r<QPair<QString, std::pair<long int, boost::any> > > >, TagList = boost::mpl::ve
ctor0<mpl_::na>, Category = boost::multi_index::detail::hashed_unique_tag]'
include/QxCollection/../../inl/QxCollection/QxCollection.inl:275:   instantiated
 from 'bool qx::QxCollection<Key, Value>::removeByKey(const Key&) [with Key = QS
tring, Value = std::pair<long int, boost::any>]'
src\QxCommon\QxCache.cpp:56:   instantiated from here
boost/boost/functional/hash/extensions.hpp:176: error: no hay una funci¾n coinci
dente para la llamada a 'hash_value(const QString&)'
boost/boost/functional/hash/hash.hpp:120: nota: los candidatos son: size_t boost
::hash_value(bool)
boost/boost/functional/hash/hash.hpp:125: nota:                     size_t boost
::hash_value(char)
boost/boost/functional/hash/hash.hpp:130: nota:                     size_t boost
::hash_value(unsigned char)
boost/boost/functional/hash/hash.hpp:135: nota:                     size_t boost
::hash_value(signed char)
boost/boost/functional/hash/hash.hpp:140: nota:                     size_t boost
::hash_value(short int)
boost/boost/functional/hash/hash.hpp:145: nota:                     size_t boost
::hash_value(short unsigned int)
boost/boost/functional/hash/hash.hpp:150: nota:                     size_t boost
::hash_value(int)
boost/boost/functional/hash/hash.hpp:155: nota:                     size_t boost
::hash_value(unsigned int)
boost/boost/functional/hash/hash.hpp:160: nota:                     size_t boost
::hash_value(long int)
boost/boost/functional/hash/hash.hpp:165: nota:                     size_t boost
::hash_value(long unsigned int)
boost/boost/functional/hash/hash.hpp:171: nota:                     size_t boost
::hash_value(wchar_t)
boost/boost/functional/hash/hash.hpp:178: nota:                     size_t boost
::hash_value(boost::long_long_type)
boost/boost/functional/hash/hash.hpp:183: nota:                     size_t boost
::hash_value(boost::ulong_long_type)
boost/boost/functional/hash/hash.hpp:297: nota:                     size_t boost
::hash_value(float)
boost/boost/functional/hash/hash.hpp:302: nota:                     size_t boost
::hash_value(double)
boost/boost/functional/hash/hash.hpp:307: nota:                     size_t boost
::hash_value(long double)
mingw32-make[1]: *** [debug/QxCache.o] Error 1
mingw32-make[1]: Leaving directory `D:/Qt/QxOrm'
mingw32-make: *** [debug] Error 2


I find a way to declare my class difference, to make use of two long "hidden mode":

Main.cpp:

Code: Select all
#include "../include/precompiled.h"
#include "../include/bListado.h"
#include "../include/bTipoListado.h"
#include <QtCore/qcoreapplication.h>
#include <QxMemLeak.h>
#include <QtGui/qapplication.h>

int main(int argc, char * argv[])
{
    // Aplicación Qt
    QApplication app(argc, argv);

    // ************************ BASE DE DATOS ************************

    // Inicializa los parámetros para la comunicación con la base de datos
    qx::QxSqlDatabase::getSingleton()->setDriverName("QPSQL");
    qx::QxSqlDatabase::getSingleton()->setDatabaseName("BD1.2");
    qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
    qx::QxSqlDatabase::getSingleton()->setUserName("postgres");
    qx::QxSqlDatabase::getSingleton()->setPassword("postgres");
    qx::QxSqlDatabase::getSingleton()->setPort(5432);

    // ************************ INSERTAR OBJETOS ************************

    // Control de errores
    QSqlError daoError;

    qx::QxSqlQuery query("WHERE bTipoListado.DescripcionTipoListado = :Descripcion");
    query.bind(":Descripcion", "Calculados");

    lista_btipo lista;
    daoError = qx::dao::fetch_by_query(query, lista);
    for (long l = 0; l < lista.count(); ++l)
    {
       bTipoListado_ptr p = lista.getByIndex(l);
       qDebug() << "DescripcionTipoListado: " << qPrintable(p->DescripcionTipoListado);
       qDebug() << "CodigoTipoListado: " << p->GetPK_CodigoTipoListado();
       qDebug() << "CodigoListado: " << p->GetFK_CodigoListado()->PK_CodigoListado;
    }
    return 0;
}


BTipoListado.h - Example without error:

Code: Select all
#include "../include/bListado.h"
#ifndef _QX_SUITE_BTIPOLISTADO_H_
#define _QX_SUITE_BTIPOLISTADO_H_

class QX_SUITE_DLL_EXPORT bTipoListado
{
public:
   // Clave compuesta (multiples-columnas de clave primaria en la base de datos)
   typedef boost::tuple<long, bListado_ptr> QCompuesta;
   static QString str_composite_key() { return "PK_CodigoTipoListado|FK_CodigoListado"; }

   QCompuesta PK_Compuesta;
   QString DescripcionTipoListado;

   // Constructor y Destructor
   bTipoListado(): PK_Compuesta() { ; }
   virtual ~bTipoListado() { ; }

   // Metodos "Get" para la clave compuesta
   QCompuesta GetClaveCompuesta() const {return PK_Compuesta;}
   long GetPK_CodigoTipoListado() const {return boost::tuples::get<0>(PK_Compuesta);}
   bListado_ptr GetFK_CodigoListado() const {return boost::tuples::get<1>(PK_Compuesta);}

   // Metodos "Set" para la clave compuesta
   void SetPK_CodigoTipoListado(long codigoTipoListado) {boost::tuples::get<0>(PK_Compuesta) = codigoTipoListado;}
   void SetPK_CodigoListado(bListado_ptr codigoListado) {boost::tuples::get<1>(PK_Compuesta) = codigoListado;}
};

QX_REGISTER_PRIMARY_KEY(bTipoListado, bTipoListado::QCompuesta)
QX_REGISTER_HPP_QX_SUITE(bTipoListado, qx::trait::no_base_class_defined, 0)

// Crea objeto 'bListado'
typedef boost::shared_ptr<bTipoListado> bTipoListado_ptr;

// Lista de objetos 'bTipoListado'
typedef qx::QxCollection<bTipoListado::QCompuesta, bTipoListado_ptr> lista_btipo;

#endif


Results generated without error:

Code: Select all
Debugging starts
QxOrm.DllMain() ---> DLL_PROCESS_ATTACH
QxOrm.DllMain() ---> DLL_THREAD_ATTACH
[QxOrm] qx::QxSqlDatabase : create new database connection in thread '2964' with key '{9ba6fee9-efb0-4170-aa8f-1c56329fb019}'
[QxOrm] sql query (639 ms) : SELECT bTipoListado.PK_CodigoTipoListado AS bTipoListado_PK_CodigoTipoListado_0, bTipoListado.FK_CodigoListado AS bTipoListado_FK_CodigoListado_0, bTipoListado.DescripcionTipoListado AS bTipoListado_DescripcionTipoListado_0 FROM bTipoListado WHERE bTipoListado.DescripcionTipoListado = :Descripcion
DescripcionTipoListado:  Calculados
CodigoTipoListado:  2
CodigoListado:  1
QxOrm.DllMain() ---> DLL_THREAD_DETACH
QxOrm.DllMain() ---> DLL_PROCESS_DETACH
Debugging has finished


However, it would be nice to know how to solve the statement of two long "<long, long>."

Thanks for the recommendations.
ramirez.cris
 

Re: Qt + Postgres + Composite key

Postby QxOrm admin » Thu Sep 22, 2011 7:56 am

I can reproduce your problem using mingw.
I think I found the solution after reading boost::hash documentation :
You have to implement the 'hash_value' function inside the same namespace as your custom type (here boost::tuple<...>).

So here is the patch for the file 'QxHashValue.h' : boost::tuple is defined into the namespace 'boost::tuples', so :
Code: Select all
/****************************************************************************
**
** http://www.qxorm.com/
** http://sourceforge.net/projects/qxorm/
** Original file by Lionel Marty
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software.
**
** GNU Lesser General Public License Usage
** This file must be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file 'license.lgpl.txt' included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you have questions regarding the use of this file, please contact :
** contact@qxorm.com
**
****************************************************************************/

#ifndef _QX_HASH_VALUE_H_
#define _QX_HASH_VALUE_H_

#ifdef _MSC_VER
#pragma once
#endif

/*!
 * \file QxHashValue.h
 * \author Lionel Marty
 * \ingroup QxCommon
 * \brief Specialize hash_value function for some Qt and boost types (used for example by qx::QxCollection<Key, Value> container)
 */

#include <QtCore/qstring.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qvariant.h>

#include <boost/tuple/tuple.hpp>
#include <boost/tuple/tuple_comparison.hpp>
#include <boost/tuple/tuple_io.hpp>

inline std::size_t hash_value(const QString & s)      { return qHash(s); }
inline std::size_t hash_value(const QDate & d)        { return qHash(d.toJulianDay()); }
inline std::size_t hash_value(const QTime & t)        { return qHash(t.toString()); }
inline std::size_t hash_value(const QDateTime & dt)   { return qHash(dt.toString()); }
inline std::size_t hash_value(const QVariant & v)     { return qHash(v.toString()); }

namespace boost {
namespace tuples {

template <typename T0, typename T1>
inline std::size_t hash_value(const boost::tuple<T0, T1> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   return seed;
}

template <typename T0, class T1, typename T2>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3, typename T4>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   boost::hash_combine(seed, boost::get<4>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   boost::hash_combine(seed, boost::get<4>(tu));
   boost::hash_combine(seed, boost::get<5>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   boost::hash_combine(seed, boost::get<4>(tu));
   boost::hash_combine(seed, boost::get<5>(tu));
   boost::hash_combine(seed, boost::get<6>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   boost::hash_combine(seed, boost::get<4>(tu));
   boost::hash_combine(seed, boost::get<5>(tu));
   boost::hash_combine(seed, boost::get<6>(tu));
   boost::hash_combine(seed, boost::get<7>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   boost::hash_combine(seed, boost::get<4>(tu));
   boost::hash_combine(seed, boost::get<5>(tu));
   boost::hash_combine(seed, boost::get<6>(tu));
   boost::hash_combine(seed, boost::get<7>(tu));
   boost::hash_combine(seed, boost::get<8>(tu));
   return seed;
}

template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> & tu)
{
   std::size_t seed = 0;
   boost::hash_combine(seed, boost::get<0>(tu));
   boost::hash_combine(seed, boost::get<1>(tu));
   boost::hash_combine(seed, boost::get<2>(tu));
   boost::hash_combine(seed, boost::get<3>(tu));
   boost::hash_combine(seed, boost::get<4>(tu));
   boost::hash_combine(seed, boost::get<5>(tu));
   boost::hash_combine(seed, boost::get<6>(tu));
   boost::hash_combine(seed, boost::get<7>(tu));
   boost::hash_combine(seed, boost::get<8>(tu));
   boost::hash_combine(seed, boost::get<9>(tu));
   return seed;
}

} // namespace tuples
} // namespace boost

#endif // _QX_HASH_VALUE_H_


Thank you very much to have found this bug, I will fix it in the next version of QxOrm library (1.1.9)...

PS: if you don't want to apply any patch in your current version of QxOrm library (1.1.8), you can use std::pair<long, long> for your composite key instead of boost::tuple (because you have only 2 types for your composite key, so std::pair<long, long> should work).
QxOrm admin
 

Re: Qt + Postgres + Composite key

Postby ramirez.cris » Fri Sep 23, 2011 6:59 pm

Excellent, it's nice to help them. I will continue doing tests.

I applied the patch to file 'QxHashValue.h' mentioned by you in the version of QxOrm library (1.1.8). Thanks for the correction. :D
ramirez.cris
 


Return to QxOrm - Open discussion

Who is online

Users browsing this forum: No registered users and 15 guests