本文整理匯總了Golang中mysql.Client.Escape方法的典型用法代碼示例。如果您正苦於以下問題:Golang Client.Escape方法的具體用法?Golang Client.Escape怎麽用?Golang Client.Escape使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類mysql.Client
的用法示例。
在下文中一共展示了Client.Escape方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Authenticate
func Authenticate(username string,
passwordHash string,
dbConn *mysql.Client) (reply *AuthenticationReply, err os.Error) {
// Default return argument
reply = NewAuthenticationReply(false, -1, "")
// Escape input
username = dbConn.Escape(username)
password := dbConn.Escape(passwordHash)
fmt.Printf("Authenticating user: '%s:%s'\n", username, password)
err = dbConn.Query("SELECT * FROM users WHERE nick = '" + username + "' AND password = '" + password + "' limit 1")
if err != nil {
return
}
result, err := dbConn.UseResult()
defer dbConn.FreeResult()
if err != nil {
return
}
// Fetch the row
row := result.FetchMap()
// If we found it the client got the username and password right
if row != nil {
id := row["id"].(int64)
nick := row["nick"].(string)
reply = NewAuthenticationReply(true, id, nick)
return
} else {
err = os.NewError("Wrong username or password.")
}
return
}