我正在尝试从存储过程中检索OUT参数,但出现异常。从MySQL Workbench控制台执行时,存储过程可以正常工作。
这是演示程序。在我的原始过程中,我将记录插入表中,并检索SQL状态(字符(5))以检查记录是否已成功插入。
环境
nanodbc version: 2.13.0
DBMS name/version: MySQL 5.7
OS and Compiler: Windows 10 Professional 64-bits, Visual C++ 15.9.11
CMake settings:
例外
[2019-04-22 12:26:24.091] [error] d:\libraries\nanodbc\nanodbc\nanodbc.cpp:1683: HY00: [MySQL][ODBC 8.0(a) Driver][mysqld-5.7.25-log]OUT or INOUT argument 1 for routine seimens_plc.test_procedure is not a variable or NEW pseudo-variable in BEFORE trigger
最小工作示例
#include "pch.h"
#include <array>
#include <iostream>
#include <nanodbc/nanodbc.h>
#include <spdlog/spdlog.h>
#pragma comment(lib, "nanodbc.lib")
int main()
{
try
{
int result;
nanodbc::string dns = "PLC_Interface";
nanodbc::string user_name = "root";
nanodbc::string password = "tantra";
nanodbc::connection conn(dns, user_name, password);
nanodbc::statement stmt;
stmt.prepare(conn, "{CALL test_procedure(?);}");
stmt.bind(0, &result, nanodbc::statement::PARAM_OUT);
stmt.execute();
std::cout << result;
conn.disconnect();
}
catch (const std::exception& ex)
{
spdlog::error(ex.what());
}
}
存储过程
DROP procedure IF EXISTS `test_procedure`;
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `test_procedure`(OUT a INT)
BEGIN
set a = 10;
END$$
DELIMITER ;