passion053
passion053

Reputation: 493

MariaDB, Syntax error when executing stored procedure in c++ program

First of all, thank you for read this question and apologize for my poor english.

I'm now converting my DB from SQL-Server to MariaDB. I installed MySQL ODBC driver and added 'system DSN'. ( C:\Windows\SysWOW64\odbcad32.exe )

The problem occured at executing a stored procedure.

When I created an procedure in SQLyog, There was no error and execution also runs fine. But When I execute stored procedure in my c++ application syntax error occurs.

Database [MySQL][ODBC 5.3(w) Driver][mysqld-5.5.5-10.0.20-MariaDB]You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'get_bookProperty ?' at line 1

My C++ code is...

bool LoadbookProperty::OnExecute(db::IDbProcesser* dbProcesser)
{
    const char* bookName = m_bookName.c_str();

    dbProcesser->BindParams(bookName);
    if (!dbProcesser->Execute("get_bookProperty"))
        return false;
    char type[PROPERTY_NAME_LEN];
    char value[PROPERTY_VALUE_LEN];
    dbProcesser->BindCols(type, value);
    dbProcesser->FetchWith([this, &type, &value]()
    {
        m_properties.push_back(std::make_pair(type, value));
    });
    return true;
}

And my procedure is...

USE bookInfoDB;

-- GetbookProperty

DELIMITER ;;

CREATE PROCEDURE get_bookProperty (
    IN pi_bookName VARCHAR(32)
)
this_proc:BEGIN

    DECLARE EXIT HANDLER FOR SQLEXCEPTION
    BEGIN
        ROLLBACK;
    END;

    SELECT bookName, bookPrice FROM bookProperty WHERE bookName = pi_bookName;

END ;;

DELIMITER ;

I really don't know what's the matter. Please help me.

Upvotes: 1

Views: 1515

Answers (1)

passion053
passion053

Reputation: 493

Solved it! The cause is EXECUTION function. When my team used SQL Server, EXECUTION function's string combination was EXEC and no bracket. (As you all know, SQL Server execute procedure by 'EXEC sp_name arg1 arg2 ...')

But MySQL(and also MariaDB)'s procedure execution syntax is 'CALL sp_name (arg1, arg2 ...). Our programmer have changed EXECTION function's string combination. And? It works perfectly!

Upvotes: 1

Related Questions