diff --git a/models/DocumentSearchResult.go b/models/DocumentSearchResult.go index 8e5097f0..c93477b3 100644 --- a/models/DocumentSearchResult.go +++ b/models/DocumentSearchResult.go @@ -1,6 +1,7 @@ package models import ( + "fmt" "regexp" "strings" "time" @@ -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{} } @@ -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) @@ -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 @@ -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) diff --git a/models/MemberResult.go b/models/MemberResult.go index 8688e85b..4983c4ac 100644 --- a/models/MemberResult.go +++ b/models/MemberResult.go @@ -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