本文整理汇总了Golang中github.com/ziutek/mymysql/mysql.Transaction.Query方法的典型用法代码示例。如果您正苦于以下问题:Golang Transaction.Query方法的具体用法?Golang Transaction.Query怎么用?Golang Transaction.Query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ziutek/mymysql/mysql.Transaction
的用法示例。
在下文中一共展示了Transaction.Query方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: AddFeed
func AddFeed(transaction mysql.Transaction, uri string) (uint64, error) {
doc := xmlx.New()
if err := doc.LoadUriClient(uri, http.DefaultClient, CharsetReader); err != nil {
return 0, errors.New("Unable to load URI: " + uri)
}
getTitle := func() string {
title := doc.Root.S("*", "title")
if title == "" {
title = doc.SelectNode("*", "channel").S("*", "title")
}
return title
}
getDescription := func() string {
description := doc.Root.S("*", "subtitle")
if description == "" {
description = doc.SelectNode("*", "channel").S("*", "description")
}
return description
}
getLink := func() string {
link := ""
for _, node := range doc.SelectNodes("*", "link") {
if node.As("", "rel") == "alternate" {
link = node.As("", "href")
}
}
if link == "" {
link = doc.SelectNode("*", "channel").S("*", "link")
}
return link
}
_, res, err := transaction.Query("INSERT INTO `feed`(`title`,`description`,`link`,`last_update`,`feedURL`) VALUES ('%s','%s','%s',0,'%s')",
getTitle(),
getDescription(),
getLink(),
uri)
if err != nil {
return 0, err
}
feedId := res.InsertId()
if err := UpdateFeedDocument(transaction, feedId, doc); err != nil {
return 0, err
}
return feedId, nil
}
示例2: updatePriorities
func updatePriorities(transaction mysql.Transaction, userId int, newPriorities map[string]GroupInfo) error {
for feedIdStr, priority := range newPriorities {
feedId, err := strconv.ParseInt(feedIdStr, 10, 64)
if err != nil {
return err
}
_, _, err = transaction.Query("UPDATE `user_feed` SET `priority`=%d, `group`='%s' WHERE feed_id=%d AND user_id=%d",
priority.Priority,
gConn.Escape(priority.Group),
feedId,
userId)
if err != nil {
return err
}
}
return nil
}
示例3: UpdateFeedDocument
func UpdateFeedDocument(transaction mysql.Transaction, feedId uint64, doc *xmlx.Document) (retErr error) {
defer func() {
if e := recover(); e != nil {
retErr = e.(error)
}
}()
const ns = "*"
findFeedEntry := func(title string, content string, date string, guid string) bool {
search := ""
if len(guid) > 0 {
search = fmt.Sprintf("`guid`='%s'", gConn.Escape(guid))
} else {
where := make([]string, 0)
if len(date) > 0 {
where = append(where, fmt.Sprintf("`published`='%s'", gConn.Escape(date)))
}
if len(content) > 0 {
where = append(where, fmt.Sprintf("`content`='%s'", gConn.Escape(content)))
}
if len(title) > 0 {
where = append(where, fmt.Sprintf("`title`='%s'", gConn.Escape(title)))
}
if len(where) == 0 {
panic(fmt.Sprintf("Can not search item! %s", title))
}
search = strings.Join(where, " OR ")
}
rows, _, err := transaction.Query("SELECT `id` FROM `feed_entry` WHERE `feed_id`=%d AND (%s)",
feedId,
search)
if err != nil {
panic(err)
}
if len(rows) > 1 {
ids := make([]string, len(rows))
for i, row := range rows {
ids[i] = row.Str(0)
}
err := fmt.Sprintf("Found more than one answer! (%s)", strings.Join(ids, ","))
panic(errors.New(err))
}
return len(rows) == 1
}
findItems(doc.Root, func(node *xmlx.Node) {
content := getContent(node)
link := getLink(node)
author := getAuthor(node)
guid := getGUID(node)
title := node.S(ns, "title")
published := node.S(ns, "pubDate")
if len(published) == 0 {
published = node.S(ns, "published")
}
parsedTime, err := parseTime(published)
if err != nil {
fmt.Printf("Warning: Failed to parse (%s)\n", published)
}
if parsedTime.After(time.Now()) {
parsedTime = time.Now()
}
//Thanks VGCats! You have no content! http://www.vgcats.com/vgcats.rdf.xml
//if content == "" {
// panic(errors.New("Could not find content"))
//}
if findFeedEntry(title, content, published, guid) {
return
}
_, _, err = transaction.Query("INSERT INTO `feed_entry`(`feed_id`,`title`,`content`,`published`,`updated`,`author`,`link`,`guid`) VALUES (%d,'%s','%s','%s',%d,'%s','%s','%s')",
feedId,
gConn.Escape(title),
gConn.Escape(content),
gConn.Escape(published),
parsedTime.Unix(),
gConn.Escape(author),
gConn.Escape(link),
gConn.Escape(guid))
if err != nil {
panic(err)
//.........这里部分代码省略.........