Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么我不能在golang中使用多个参数我的sql查询有什么问题?_Sql_Database_Go - Fatal编程技术网

为什么我不能在golang中使用多个参数我的sql查询有什么问题?

为什么我不能在golang中使用多个参数我的sql查询有什么问题?,sql,database,go,Sql,Database,Go,我有多个参数的问题,我不能用sql查询实现2个参数。我仍然得到错误,错误显示mssql:SequenceID附近的语法不正确。我的查询sql有什么问题,或者我的代码有什么问题 package main import ( "database/sql" "fmt" _ "github.com/denisenkom/go-mssqldb" "github.com/gin-gonic/gin" "net/http" "time" ) func main

我有多个参数的问题,我不能用sql查询实现2个参数。我仍然得到错误,错误显示mssql:SequenceID附近的语法不正确。我的查询sql有什么问题,或者我的代码有什么问题

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)
})

由于您的查询不包含任何占位符(
chars),因此
QueryRow
不应该有其他arg。或许可以删除额外的参数:

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

1.永远不要通过连接字符串来建立查询。2.首先测试查询。3.阅读
QueryRow
的文档,思考MobilePhone在那里做什么。4.问一个人(这样效率更高)。谢谢你的建议。我试试看,但仍然会出现错误“mssql:靠近“?”的语法不正确。”