Menu

Problem with handling bad statement

Anonymous
2015-05-05
2015-05-07
  • Anonymous

    Anonymous - 2015-05-05

    Hi,
    first of all I would like to thank you very much for the tremendous work you have done! OCILIB saved me a lot of time and nerves digging into classic OCI.
    I have recently started using you C++ wrapper and I have a very particular problem.
    When I try to execute "bad" SQL statement which is of type "create function" or "create procedure", the method Statement::execute never returns.
    Say we have:

    create or replace function err_testing return date
    is
      v_date date
    begin
      v_date := to_date('2015-03-01', 'yyyy-mm-dd');
      return v_date;
    end;
    

    As you can see - line 3 does not end with semicolon and is supposed to generate an error.
    When I execute code:

    ostring homeLibs("/home/oracle/app/oracle/Oracle11g/lib");
    Environment::Initialize(Environment::Default | Environment::Threaded, homeLibs);
    Environment::EnableWarnings(true);
    
    ...
    Connection conn;
    conn.Open(dbs, usr, pwd, Environment::SessionDefault);
    
    try
    {
      Statement stmt(conn);
      stmt.Execute(ostring("create or replace function err_testing return date \n\
                            is \n\
                              v_date date \n\
                            begin \n\
                              v_date := sysdate; \n\
                              return v_date; \n\
                            end;\n"));
    
      //the program never reaches this point and exception is not thrown as well
    
    }
    catch(Exception ex)
    {
      ocout << OTEXT("Exception was catched: ") << ex.what() << std::endl;
    }
    
    conn.Close();
    ocout << OTEXT("Done.");
    

    the program stops at "stmt.Execute" and never exits.
    If I correct the error in the SQL, the function is created and compiled without a problem.
    If the statement is just "declare ... begin ... end;" style, it throws an exception well and an error text is shown.

    Is there any way to workaround this?

    Thank you!

     
  • Vincent Rogier

    Vincent Rogier - 2015-05-05

    Hi,

    can you indicate the ocilib version (released packages version , latest sources) ? Ansi build ? Unicode build ?

    thanks

    vincent

     
  • Vincent Rogier

    Vincent Rogier - 2015-05-05

    Do you have the same issue when warnings are not enabled ?

    if not, get latest sources, it shall be fixed :)

     
  • Vincent Rogier

    Vincent Rogier - 2015-05-05

    I've just tried and with warning on, an exception is raised as expected.

    Get latest sources. It has been fixed few weeks ago in the GIT repo.

    Version 4.1.0 is finally getting released this week :)

     
  • Anonymous

    Anonymous - 2015-05-06

    Hi!
    I didn't expect you answer so fast ;). Thank you!
    Yes, the new version fixed the problem. Now it reports with a proper Oracle error.
    Thank you again!

     
  • Anonymous

    Anonymous - 2015-05-06

    Unfortunately there is another issue with the new version:
    When getting datatype of column for a resultset, the returned value for GetColumn() is "?".

    ...
    for(register int i = 1; i <= m_columnCount; ++i) //column index is 1-based
    {
      ocilib::Column column = resultset.GetColumn(i);
      ostring fieldType = column.GetSQLType();
      // fieldType is now "?"
      ...
    }
    

    The funny part is that when using GetFullSQLType() I get the full name and size appropriately.

    I use the ANSI version of the library. Latest release 4.1.0.

     
  • Vincent Rogier

    Vincent Rogier - 2015-05-06

    Ok I will fix that asap !

     
  • Vincent Rogier

    Vincent Rogier - 2015-05-06

    Arrgh ! It was due missing break statements in column.c file that disappeared while performing a nasty code replace operation at so point !
    I've commited the fix. You need to rebuild the library.
    I will release a 4.1.1 this evening...

     
  • Anonymous

    Anonymous - 2015-05-07

    I compiled the lib from the snapshot and it is OK now.
    Thank you!

     
  • Vincent Rogier

    Vincent Rogier - 2015-05-07

    Good :)

    You're welcome.

    Vincent