From b3e9b1d9a1b11cfb0c8991f22dfcd48e05b12b00 Mon Sep 17 00:00:00 2001 From: a74589669 <290198252@qq.com> Date: Sun, 6 Oct 2019 14:03:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4mongodb=E7=9A=84=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/sqlManager.go | 2 +- main.go | 6 +++--- model/blog.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/db/sqlManager.go b/db/sqlManager.go index ba22746..45d189e 100644 --- a/db/sqlManager.go +++ b/db/sqlManager.go @@ -21,7 +21,7 @@ var gMongo *mgo.Session func Init() { mysqlconf := config.GetMysqlConfig() blogConf := config.GetMysqlBlogConfig() - InitMongoDb() + //InitMongoDb() blogDb = Database{Type: string(""), DB: initMysql(blogConf)} gDb = Database{Type: string(""), DB: initMysqlTLS(mysqlconf)} } diff --git a/main.go b/main.go index 1748ca6..d7be1b8 100644 --- a/main.go +++ b/main.go @@ -70,9 +70,9 @@ func main() { InitRedis() InitMysql() - mgo := db.GetMongoDb() - mgo = mgo - config.GetMongoDBConfig() + //o := db.GetMongoDb() + //mgo = mgo + //config.GetMongoDBConfig() r := gin.Default() store := sessions.NewCookieStore([]byte("secret123")) r.Use(sessions.Middleware("sess_store", store)) diff --git a/model/blog.go b/model/blog.go index 374f422..3c25df9 100644 --- a/model/blog.go +++ b/model/blog.go @@ -40,7 +40,7 @@ func CreateDoc(doc Doc) error { FROM DUAL WHERE - NOT EXISTS ( SELECT * FROM doc WHERE doc.title = '%s' );`, doc.Title, doc.Content, doc.Author, doc.Type,doc.Title) + NOT EXISTS ( SELECT * FROM doc WHERE doc.title = '%s' );`, doc.Title, strings.Replace(doc.Content, "'", "\\'", -1), doc.Author, doc.Type,doc.Title) _, e := db.GetMysqlClient().Query(sql) if nil != e { logs.Error(e.Error()) @@ -51,7 +51,7 @@ WHERE func UpdateDoc(doc Doc) error{ sql := fmt.Sprintf(`update doc set doc.author = '%s' ,doc.title = '%s',doc.type = '%d',doc.content = '%s' where doc.id = '%d'; `, - doc.Author, strings.Replace(doc.Title, "'", "\\'", -1), doc.Type, + doc.Author, doc.Title, doc.Type, strings.Replace(doc.Content, "'", "\\'", -1),doc.ID) _, e := db.GetMysqlClient().Query(sql) if nil != e {