[odb-users] odb - stored procedure issue

Ha, Anthony Anthony.Ha at ga-asi.com
Fri Sep 5 18:33:45 EDT 2014


Hi,
Appreciate any pointer on getting stored procedure called from ODB "view" to work on mySql
We have many legacy stored procedures and hope to move forward using ORM but being able to continue using legacy SQL.
I'm not even sure I'm taking the right approach but I have seen this issue mentioned once at stackoverflow<http://stackoverflow.com/questions/24491479/executing-stored-procedure-with-odb-orm/24646919#24646919>  and trying to use that as a starting point.

What I have done:

*         Goal : call a stored procedure from ODB "view"

*         Stored procedure: example from mysqltutorial<http://www.mysqltutorial.org/getting-started-with-mysql-stored-procedures.aspx>

*         Loaded the test database "classicmodels"

*         Test calling the SP from the mysql> promt - success

*         Created a simple example from the "view/employee"

Tried to build the example and got the following compiling error:

make -k
odb -d mysql --generate-schema --generate-query -s -q -p boost/date-time --default-pointer std::tr1::shared_ptr employee.hxx
g++  -DDATABASE_MYSQL -W -Wall -Wno-unknown-pragmas -O3 -c driver.cxx -o driver.o
driver.cxx: In function 'int main(int, char**)':
driver.cxx:29:18: error: invalid use of 'class odb::query<StoredProc>'
     Result r( db.query<StoredProc>( Query::_val(1) ) );
                  ^
make: *** [driver.o] Error 1
g++  -DDATABASE_MYSQL -W -Wall -Wno-unknown-pragmas -O3 -c employee-odb.cxx -o employee-odb.o
employee-odb.cxx: In static member function 'static odb::access::view_traits_impl<StoredProc, (odb::database_id)0u>::query_base_type odb::access::view_traits_impl<StoredProc, (odb::database_id)0u>::query_statement(const query_base_type&)':
employee-odb.cxx:773:32: error: expected ')' before string constant
       "exec getallproducts" + q";");
                                ^
make: *** [employee-odb.o] Error 1
make: Target `driver' not remade because of errors.
Employee.hxx:

#pragma db view query("exec getallproducts(?);")
struct StoredProc
{
  int cust_no;
  std::string cust_name;
};

Driver.cxx
int
main (int argc, char* argv[])
{
  try
  {
    auto_ptr<database> db (create_database (argc, argv));
    typedef odb::result<StoredProc> Result;
    typedef odb::query<StoredProc> Query;
    transaction t (db->begin());

    Result r( db.query<StoredProc>( Query::_val(1) ) );
  }
  catch (const odb::exception& e)
  {
    cerr << e.what () << endl;
    return 1;
  }
}

mailto:Anthony.Ha at ga-asi.com

[cid:image001.jpg at 01CFC91C.EA73D240]

-------------- next part --------------
A non-text attachment was scrubbed...
Name: image001.jpg
Type: image/jpeg
Size: 1936 bytes
Desc: image001.jpg
Url : http://codesynthesis.com/pipermail/odb-users/attachments/20140905/256b1541/image001.jpg


More information about the odb-users mailing list