C++ mysql存储过程错误代码1327

标签 c++ mysql

我有这张 table

create table utilizator(
      utilizatorId bigint not null auto_increment primary key,
      loghin varchar(500),
      password varchar(50) not null,
      tip bigint not null,
      persoanaId bigint not null,
      evenimentId bigint not null);

和这段c++代码

 string vU="demo",vP="1234";
 Driver * vDriver = get_driver_instance();
 auto_ptr< Connection > vCon(vDriver->connect(getHost(),getUser() , getPassword() ));
 vCon->setSchema(getDB());
 auto_ptr< Statement > vStmt(vCon->createStatement());

 vStmt->execute("DROP PROCEDURE IF EXISTS fLoghin");   
 vStmt->execute("CREATE PROCEDURE fLoghin(in pUser varchar(200),in pPass varchar(200),out pUId int,out pTip int,out pEId int) BEGIN   select utilizatorId into pUId ,tip into pTip,evenimentId into pEId from utilizator where loghin=pUser and password=pPass ;  END ; ");
 vStmt->execute("CALL fLoghin("+vU+","+vP+", @out1,@out2,@out3)");

 auto_ptr<ResultSet > res(vStmt->executeQuery("SELECT @out1,@out2,@out3 AS _reply"));
    while (res->next())
      cout << "... @output = " << res->getString("_reply") << endl;

在行 vStmt->execute("CREATE PROCEDURE ... 我得到这个错误

 ERR: Undeclared variable: tip (MySQL error code: 1327, SQLState: 42000 )

最佳答案

尝试

CREATE PROCEDURE fLoghin(in pUser varchar(200),
                         in pPass varchar(200),
                         out pUId int,
                         out pTip int,
                         out pEId int) 
BEGIN   
    select pUId = utilizatorId, pTip = tip, pEId = evenimentId
    from utilizator 
    where loghin=pUser and password=pPass ;  
END ; 

我现在无法验证。也许你需要在你的变量前面放一个 @ ,比如

@PUId = utilizatorId ...

关于C++ mysql存储过程错误代码1327,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10140313/

相关文章:

c++ - 谁能解释这个程序的类型提升以及为什么输出相同

c++ - 在 C++ 中取消引用字符串时会发生什么

php - 使用 for 循环将值添加到 MySQL 插入查询

php - 如何更改 Yii -> ECSVExport 的标题

c++ - 在 C++ 中搜索和替换 C 风格的字符串

c++ - 类内在线非静态字段初始化 + 对象池 -> 降低可维护性/可读性

python - 类型错误 : 'connection' object is not callable in python using mysqldb

mysql - 在备份期间保持两个独立数据存储之间的完整性(MySQL 和 MongoDB)

c++ - Linux/C++ 将字符串复制到剪贴板

php连接到sql本地服务器