Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions models/DocumentSearchResult.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package models

import (
"fmt"
"regexp"
"strings"
"time"
Expand Down Expand Up @@ -36,6 +37,15 @@ func need_escape(keyword string) bool {
return false
}

func escape_name(name string) string {
dbadapter, _ := web.AppConfig.String("db_adapter")
ch := "`"
if strings.EqualFold(dbadapter, "postgres") {
ch = `"`
}
return fmt.Sprintf("%s%s%s", ch, name, ch)
}

func NewDocumentSearchResult() *DocumentSearchResult {
return &DocumentSearchResult{}
}
Expand Down Expand Up @@ -294,7 +304,7 @@ WHERE (book.privately_owned = 0 OR rel1.relationship_id > 0 or team.team_member_
func (m *DocumentSearchResult) SearchDocument(keyword string, bookId int) (docs []*DocumentSearchResult, err error) {
o := orm.NewOrm()

sql := "SELECT * FROM md_documents WHERE book_id = ? AND (document_name LIKE ? OR `release` LIKE ?) "
sql := fmt.Sprintf("SELECT * FROM md_documents WHERE book_id = ? AND (document_name LIKE ? OR %s LIKE ?) ", escape_name("release"))
keyword = "%" + keyword + "%"

_need_escape := need_escape(keyword)
Expand All @@ -304,7 +314,6 @@ func (m *DocumentSearchResult) SearchDocument(keyword string, bookId int) (docs
}
return sql
}

_, err = o.Raw(escape_sql(sql), bookId, keyword, keyword).QueryRows(&docs)

return
Expand All @@ -314,7 +323,7 @@ func (m *DocumentSearchResult) SearchDocument(keyword string, bookId int) (docs
func (m *DocumentSearchResult) SearchAllDocument(keyword string) (docs []*DocumentSearchResult, err error) {
o := orm.NewOrm()

sql := "SELECT * FROM md_documents WHERE (document_name LIKE ? OR `release` LIKE ?) "
sql := fmt.Sprintf("SELECT * FROM md_documents WHERE (document_name LIKE ? OR %s LIKE ?) ", escape_name("release"))
keyword = "%" + keyword + "%"

_need_escape := need_escape(keyword)
Expand Down
2 changes: 1 addition & 1 deletion models/MemberResult.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (m *MemberRelationshipResult) FindNotJoinUsersByAccount(bookId, limit int,
func (m *MemberRelationshipResult) FindNotJoinUsersByAccountOrRealName(bookId, limit int, keyWord string) ([]*Member, error) {
o := orm.NewOrm()

sql := "SELECT m.* FROM md_members as m LEFT JOIN md_relationship as rel ON rel.member_id = m.member_id AND rel.book_id = ? WHERE rel.relationship_id IS NULL AND (m.real_name LIKE ? OR m.account LIKE ?) LIMIT 0,?;"
sql := "SELECT m.* FROM md_members as m LEFT JOIN md_relationship as rel ON rel.member_id = m.member_id AND rel.book_id = ? WHERE rel.relationship_id IS NULL AND (m.real_name LIKE ? OR m.account LIKE ?) LIMIT ? OFFSET 0;"

var members []*Member

Expand Down
Loading