duanli4146 2019-02-12 10:08
浏览 77

为什么我不能在golang中使用多个参数,而我的sql查询又出了什么问题?

I have problem with multiple parameter , I cannot implementing 2 parameter with sql query. and I'm still get error , error display mssql: Incorrect syntax near 'SequenceID'. what wrong with my query sql or maybe I wrong with my code ?

package main

import (
    "database/sql"
    "fmt"
    _ "github.com/denisenkom/go-mssqldb"
    "github.com/gin-gonic/gin"
    "net/http"
    "time"
)

func main()  {
    db, err :=  sql.Open("sqlserver","sqlserver://sa:@localhost:1433?database=CONFINS&connection+timeout=30")
    if err != nil{
        fmt.Print(err.Error())
    }


err = db.Ping()

if err != nil {
    fmt.Print(err.Error())
}
defer db.Close()

type SMSBlast struct {
    SequenceID  int
    MobilePhone string
    Output  string
    WillBeSentDate *time.Time
    SentDate *time.Time
    Status *string
    DtmUpd *time.Time
}

router := gin.Default()

//Get a SMSBlast  detail
router.POST("/SMSBlast/:SequenceID", func(context *gin.Context) {
    var(
        smsblast SMSBlast
        result gin.H
    )

SequenceID := context.Param("SequenceID")
MobilePhone := context.Param("MobilePhone")

    err := db.QueryRow("select SequenceID, MobilePhone, Output, WillBeSentDate, SentDate, Status, DtmUpd from SMSblast2 where SequenceID  IS NOT NULL  AND MobilePhone IS NOT NULL  "+SequenceID , MobilePhone).Scan(&smsblast.SequenceID, &smsblast.MobilePhone, &smsblast.Output, &smsblast.WillBeSentDate, &smsblast.SentDate, &smsblast.Status, &smsblast.DtmUpd)
    //fmt.Println(row)
    fmt.Println(err)
    //err = row.Scan(&smsblast.SequenceID, &smsblast.MobilePhone, &smsblast.Output, &smsblast.WillBeSentDate, &smsblast.SentDate, &smsblast.Status, &smsblast.DtmUpd)
    if err != nil{
        //if no results send null
        result = gin.H{
            "result": nil,
            "count":  0,
        }
        }else{
            result = gin.H{
                "result" : smsblast,
                "count" : 1,
            }
        }

    context.JSON(http.StatusOK, result)
})
  • 写回答

1条回答 默认 最新

  • dsuxcxqep31023992 2019-02-12 10:15
    关注

    Since your query doesn't contain any placeholders (? chars), there should be no additional args to QueryRow. Perhaps remove the extra args:

    db.QueryRow("select SequenceID, MobilePhone, Output, WillBeSentDate, SentDate, Status, DtmUpd from SMSblast2 where SequenceID  IS NOT NULL AND MobilePhone IS NOT NULL").Scan[...]
    
    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!