Browse Source

MySQL Error 1040: Too many connections

Vova Tkach 6 years ago
parent
commit
ab82491eda

+ 3 - 0
engine/builder/data_table.go

@@ -2,6 +2,8 @@ package builder
 
 import (
 	"database/sql"
+	_ "github.com/go-sql-driver/mysql"
+
 	"fmt"
 	"html"
 	"math"
@@ -141,6 +143,7 @@ func DataTable(
 					result += `</tr>`
 				}
 			}
+			rows.Close()
 		}
 		if !have_records {
 			result += `<tr><td colspan="50">No any data found</td></tr>`

+ 3 - 1
engine/wrapper/wrapper.go

@@ -1,8 +1,10 @@
 package wrapper
 
 import (
-	"bytes"
 	"database/sql"
+	_ "github.com/go-sql-driver/mysql"
+
+	"bytes"
 	"errors"
 	"fmt"
 	"html/template"

+ 2 - 0
modules/module_blog.go

@@ -2,6 +2,8 @@ package modules
 
 import (
 	"database/sql"
+	_ "github.com/go-sql-driver/mysql"
+
 	"html"
 	"strings"
 

+ 6 - 2
modules/module_blog_categories.go

@@ -30,6 +30,7 @@ func (this *Modules) blog_GetCategorySelectOptions(wrap *wrapper.Wrapper, id int
 		;`,
 	)
 	if err == nil {
+		defer rows.Close()
 		values := make([]string, 5)
 		scan := make([]interface{}, len(values))
 		for i := range values {
@@ -62,7 +63,7 @@ func (this *Modules) blog_GetCategorySelectOptions(wrap *wrapper.Wrapper, id int
 
 func (this *Modules) blog_GetCategoryParentId(wrap *wrapper.Wrapper, id int) int {
 	var parentId int
-	_ = wrap.DB.QueryRow(`
+	err := wrap.DB.QueryRow(`
 		SELECT
 			parent.id
 		FROM
@@ -80,6 +81,9 @@ func (this *Modules) blog_GetCategoryParentId(wrap *wrapper.Wrapper, id int) int
 	).Scan(
 		&parentId,
 	)
+	if err != nil {
+		return 0
+	}
 	return parentId
 }
 
@@ -134,7 +138,7 @@ func (this *Modules) blog_ActionCategoryUpdate(wrap *wrapper.Wrapper, pf_id, pf_
 
 	if utils.StrToInt(pf_parent) == parentId {
 		// If parent not changed, just update category data
-		_, err := wrap.DB.Query(`
+		_, err := wrap.DB.Exec(`
 			UPDATE blog_cats SET
 				name = ?,
 				alias = ?

+ 3 - 3
modules/module_index.go

@@ -344,7 +344,7 @@ func (this *Modules) RegisterAction_IndexModify() *Action {
 
 		if pf_id == "0" {
 			// Add new page
-			_, err := wrap.DB.Query(
+			_, err := wrap.DB.Exec(
 				`INSERT INTO pages SET
 					user = ?,
 					name = ?,
@@ -373,7 +373,7 @@ func (this *Modules) RegisterAction_IndexModify() *Action {
 			wrap.Write(`window.location='/cp/';`)
 		} else {
 			// Update page
-			_, err := wrap.DB.Query(
+			_, err := wrap.DB.Exec(
 				`UPDATE pages SET
 					name = ?,
 					alias = ?,
@@ -417,7 +417,7 @@ func (this *Modules) RegisterAction_IndexDelete() *Action {
 		}
 
 		// Delete page
-		_, err := wrap.DB.Query(
+		_, err := wrap.DB.Exec(
 			`DELETE FROM pages WHERE id = ?;`,
 			utils.StrToInt(pf_id),
 		)

+ 1 - 1
modules/module_index_act_cypress.go

@@ -35,7 +35,7 @@ func (this *Modules) RegisterAction_IndexCypressReset() *Action {
 		os.Remove(wrap.DConfig + string(os.PathSeparator) + ".installed")
 		os.Remove(wrap.DConfig + string(os.PathSeparator) + "mysql.json")
 
-		db.Query(
+		_, _ = db.Exec(
 			`DROP TABLE
 				blog_cats,
 				blog_cat_post_rel,

+ 1 - 1
modules/module_index_act_first_user.go

@@ -50,7 +50,7 @@ func (this *Modules) RegisterAction_IndexFirstUser() *Action {
 			return
 		}
 
-		_, err = wrap.DB.Query(
+		_, err = wrap.DB.Exec(
 			`INSERT INTO users SET
 				id = 1,
 				first_name = ?,

+ 2 - 2
modules/module_index_act_update_profile.go

@@ -28,7 +28,7 @@ func (this *Modules) RegisterAction_IndexUserUpdateProfile() *Action {
 
 		if pf_password != "" {
 			// Update with password if set
-			_, err := wrap.DB.Query(
+			_, err := wrap.DB.Exec(
 				`UPDATE users SET
 					first_name = ?,
 					last_name = ?,
@@ -49,7 +49,7 @@ func (this *Modules) RegisterAction_IndexUserUpdateProfile() *Action {
 			}
 		} else {
 			// Update without password if not set
-			_, err := wrap.DB.Query(
+			_, err := wrap.DB.Exec(
 				`UPDATE users SET
 					first_name = ?,
 					last_name = ?,

+ 4 - 4
modules/module_users.go

@@ -283,7 +283,7 @@ func (this *Modules) RegisterAction_UsersModify() *Action {
 				wrap.MsgError(`Please specify user password`)
 				return
 			}
-			_, err := wrap.DB.Query(
+			_, err := wrap.DB.Exec(
 				`INSERT INTO users SET
 					first_name = ?,
 					last_name = ?,
@@ -307,7 +307,7 @@ func (this *Modules) RegisterAction_UsersModify() *Action {
 		} else {
 			// Update user
 			if pf_password == "" {
-				_, err := wrap.DB.Query(
+				_, err := wrap.DB.Exec(
 					`UPDATE users SET
 						first_name = ?,
 						last_name = ?,
@@ -329,7 +329,7 @@ func (this *Modules) RegisterAction_UsersModify() *Action {
 					return
 				}
 			} else {
-				_, err := wrap.DB.Query(
+				_, err := wrap.DB.Exec(
 					`UPDATE users SET
 						first_name = ?,
 						last_name = ?,
@@ -368,7 +368,7 @@ func (this *Modules) RegisterAction_UsersDelete() *Action {
 		}
 
 		// Delete user
-		_, err := wrap.DB.Query(
+		_, err := wrap.DB.Exec(
 			`DELETE FROM users WHERE id = ? and id <> 1;`,
 			utils.StrToInt(pf_id),
 		)