[odb-users] calling oracle procedure with odb

roberto minarelli roberto.minarelli.de at gmail.com
Mon May 22 11:23:42 EDT 2023


Hi Boris
Thanks a lot for you reply.
Yes I imagined something like that but I also navigate through the
documentation and tried to build a query on the example basis
But it never compiles

following is the code fragment

#include <string>
#include <odb/core.hxx>

#pragma db view query("CALL mp_vrdba.get_freetg((?))")
struct get_freetg
{
        unsigned short tg;
};

..............
            typedef odb::query<get_freetg> query;
            transaction t(db->begin());
            get_freetg gf(db->query<get_freetg>(query::_val(0)));
            spdlog::get("daily_logger")->info("got free tg {}", gf.tg);
            t.commit();
............

and these are the compilation errors I got

/home/minarelli/sdg-root/sdg-rest-api/src/db/DbUtil.cpp: In member function
‘TGV DbUtil::getFreeTGV()’:
/home/minarelli/sdg-root/sdg-rest-api/src/db/DbUtil.cpp:268:56: error: no
matching function for call to
‘odb::database::query<get_freetg>(odb::oracle::val_bind<int>)’
      get_freetg gf(db->query<get_freetg>(query::_val(0)));
                                                        ^
In file included from /usr/local/include/odb/oracle/database.hxx:14:0,
                 from
/home/minarelli/sdg-root/sdg-rest-api/src/db/../../provaStored-odb.cxx:14,
                 from
/home/minarelli/sdg-root/sdg-rest-api/src/db/DbUtil.cpp:8:
/usr/local/include/odb/database.hxx:263:5: note: candidate: template<class
T> odb::result<T> odb::database::query(bool)
     query (bool cache = true);
     ^~~~~
/usr/local/include/odb/database.hxx:263:5: note:   template argument
deduction/substitution failed:
/home/minarelli/sdg-root/sdg-rest-api/src/db/DbUtil.cpp:268:53: note:
cannot convert ‘odb::oracle::query_base::_val<int>(0, 4095, 4095)’ (type
‘odb::oracle::val_bind<int>’) to type ‘bool’
      get_freetg gf(db->query<get_freetg>(query::_val(0)));
                                          ~~~~~~~~~~~^~~
In file included from /usr/local/include/odb/oracle/database.hxx:14:0,
                 from
/home/minarelli/sdg-root/sdg-rest-api/src/db/../../provaStored-odb.cxx:14,
                 from
/home/minarelli/sdg-root/sdg-rest-api/src/db/DbUtil.cpp:8:
/usr/local/include/odb/database.hxx:267:5: note: candidate: template<class
T> odb::result<T> odb::database::query(const char*, bool)
     query (const char*, bool cache = true);
     ^~~~~
/usr/local/include/odb/database.hxx:267:5: note:   template argument
deduction/substitution failed:
/home/minarelli/sdg-root/sdg-rest-api/src/db/DbUtil.cpp:268:53: note:
cannot convert ‘odb::oracle::query_base::_val<int>(0, 4095, 4095)’ (type
‘odb::oracle::val_bind<int>’) to type ‘const char*’
      get_freetg gf(db->query<get_freetg>(query::_val(0)));
                                          ~~~~~~~~~~~^~~
In file included from /usr/local/include/odb/oracle/database.hxx:14:0,
                 from
/home/minarelli/sdg-root/sdg-rest-api/src/db/../../provaStored-odb.cxx:14,
                 from
/home/minarelli/sdg-root/sdg-rest-api/src/db/DbUtil.cpp:8:
/usr/local/include/odb/database.hxx:271:5: note: candidate: template<class
T> odb::result<T> odb::database::query(const string&, bool)
     query (const std::string&, bool cache = true);
     ^~~~~
/usr/local/include/odb/database.hxx:271:5: note:   template argument
deduction/substitution failed:
/home/minarelli/sdg-root/sdg-rest-api/src/db/DbUtil.cpp:268:53: note:
cannot convert ‘odb::oracle::query_base::_val<int>(0, 4095, 4095)’ (type
‘odb::oracle::val_bind<int>’) to type ‘const string& {aka const
std::basic_string<char>&}’
      get_freetg gf(db->query<get_freetg>(query::_val(0)));
                                          ~~~~~~~~~~~^~~
In file included from /usr/local/include/odb/oracle/database.hxx:14:0,
                 from
/home/minarelli/sdg-root/sdg-rest-api/src/db/../../provaStored-odb.cxx:14,
                 from
/home/minarelli/sdg-root/sdg-rest-api/src/db/DbUtil.cpp:8:
/usr/local/include/odb/database.hxx:275:5: note: candidate: template<class
T> odb::result<T> odb::database::query(const odb::query<T>&, bool)
     query (const odb::query<T>&, bool cache = true);
     ^~~~~
/usr/local/include/odb/database.hxx:275:5: note:   template argument
deduction/substitution failed:
/home/minarelli/sdg-root/sdg-rest-api/src/db/DbUtil.cpp:268:53: note:
cannot convert ‘odb::oracle::query_base::_val<int>(0, 4095, 4095)’ (type
‘odb::oracle::val_bind<int>’) to type ‘const odb::query<get_freetg>&’
      get_freetg gf(db->query<get_freetg>(query::_val(0)));
                                          ~~~~~~~~~~~^~~

That I cannot figured how to get rid of

If you could help me please I would really appreciate it as I really like
using odb

Thanks in advance

Roberto Minarelli Della Valle



Il giorno lun 22 mag 2023 alle ore 16:18 Boris Kolpackov <
boris at codesynthesis.com> ha scritto:

> roberto minarelli <roberto.minarelli.de at gmail.com> writes:
>
> > #pragma db view query("CALL my_procedure(?)")
> > struct my_procedure
> > {
> >   unsigned short myvalue;
> > };
> >
> > then in the code part I wrote
> >
> >             struct get_freetg xtg;
> >             using query1=odb::query<get_freetg>;
> >             transaction t(db->begin());
> >             db->query<get_freetg>(&xtg.tg);
> >             t.commit();
> >
> > But this does not works at all
>
> No surprise there: passing a pointer as a query parameter in the hopes
> that the result will end up there is not how it works in ODB.
>
> Take a look at an example of calling stored procedures in the manual
> and see if you cannot figure it out:
>
> https://www.codesynthesis.com/products/odb/doc/manual.xhtml#17.7
>


More information about the odb-users mailing list