dortmundbvb0624 2019-08-20 22:35
浏览 109
已采纳

使用Go MySQL无法检索输出参数

I have a stored procedure which inserts an entity and returns its new UUID, and while I can generate the code to create the right query, it errors out when using go-sql-driver/mysql. So the following code...

func test_insert() *sql.Rows {
    db := openDbConnection()

    defer db.Close()

    results, err := db.Query("call saveargument(null, 'Test Argument', 'Test Argument', '1', null, null, null, 1, 'test_user', @newargumentid);
select @newargumentid;")

    toolkit.HandleError(err)

    return results
}

func openDbConnection() *sql.DB {
    var db, err = sql.Open("mysql", getConnectionString(entities.GetConfig()))

    toolkit.HandleError(err)

    return db
}

... produces the following error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select @newargumentid' at line 2

I'm not sure why such a basic piece of SQL could be so problematic. Any insights anyone?

  • 写回答

1条回答 默认 最新

  • dougua2309 2019-08-21 00:32
    关注

    You can't run more than one statement in a single db.Query() call. This is true of most query interfaces in all programming languages.

    Call your stored procedure in one call to db.Query(), then query select @newargumentid in a second call to db.Query().

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 找一个QT页面+目标识别(行人检测)的开源项目
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败
  • ¥15 用Ros中的Topic通讯方式控制小乌龟的速度,走矩形;编写订阅器代码
  • ¥15 LLM accuracy检测
  • ¥15 pycharm添加远程解释器报错
  • ¥15 如何让子窗口鼠标滚动独立,不要传递消息给主窗口