Browse Source

修复pgsql中关键字使用问题

master
lijianbin 14 hours ago
parent
commit
60c84df410
6 changed files with 31 additions and 35 deletions
  1. +7
    -8
      chain.go
  2. +6
    -7
      db.go
  3. +2
    -2
      db_test.go
  4. +3
    -3
      prepare.go
  5. +6
    -7
      transaction.go
  6. +7
    -8
      transaction_chain.go

+ 7
- 8
chain.go View File

@ -231,7 +231,7 @@ func (this *Query) GetTableInfo(table string) (map[string]interface{}, error) {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
stmtSql, err := this.conn.Prepare(sql)
if err != nil {
@ -442,7 +442,7 @@ func (this *Query) BuildSelectSql() (map[string]interface{}, error) {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
return map[string]interface{}{
"sql": sql,
@ -517,7 +517,7 @@ func (this *Query) UpdateStmt() error {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
stmt, err = this.conn.Prepare(sql)
@ -645,7 +645,7 @@ func (this *Query) UpdateAllStmt() error {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
stmt, err = this.conn.Prepare(sql)
@ -740,8 +740,7 @@ func (this *Query) CreateAllStmt() error {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = helper.StringJoin(sql, " RETURNING id")
sql = SqlReplace(sql, "add")
}
stmt, err = this.conn.Prepare(sql)
@ -805,7 +804,7 @@ func (this *Query) CreateStmt() error {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
stmt, err = this.conn.Prepare(sql)
@ -857,7 +856,7 @@ func (this *Query) DeleteStmt() error {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
stmt, err = this.conn.Prepare(sql)


+ 6
- 7
db.go View File

@ -49,8 +49,7 @@ func Insert(dbName, table string, data map[string]string) (int64, error) {
Sql = "insert into " + dbName + " (" + strings.Join(keyList, ",") + ") values (" + strings.Join(keyStr, ",") + ")"
if DB_PROVIDER == "PgsqlDb" {
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = helper.StringJoin(Sql, " RETURNING id")
Sql = SqlReplace(Sql, "add")
stmt, err = DB.Prepare(Sql)
if err != nil {
return 0, errors.New("创建失败:" + err.Error())
@ -131,7 +130,7 @@ func Update(dbName, table string, data map[string]string, where map[string]strin
Sql = "update " + dbName + " set " + strings.Join(keyList, " , ") + " where " + strings.Join(whereStr, " and ")
if DB_PROVIDER == "PgsqlDb" {
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = SqlReplace(Sql, "")
}
result, err := DB.Exec(Sql, valueList...)
@ -194,7 +193,7 @@ func Delete(dbName, table string, data map[string]string, del_count ...string) (
Sql = "delete from " + dbName + " where " + strings.Join(keyList, " and ") + limitStr
if DB_PROVIDER == "PgsqlDb" {
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = SqlReplace(Sql, "")
}
result, err := DB.Exec(Sql, valueList...)
@ -277,7 +276,7 @@ func GetData(dbName, table string, title string, where map[string]string, limit
Sql = "SELECT " + title + " FROM " + dbName + " where " + strings.Join(keyList, " and ") + " " + limitStr
if DB_PROVIDER == "PgsqlDb" {
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = SqlReplace(Sql, "")
}
rows, err = DB.Query(Sql, valueList...)
@ -826,7 +825,7 @@ func GetList(dbName, table string, title string, where map[string]string, limit
Sql = "select " + title + " from " + dbName + " where " + strings.Join(whereStr, " and ") + " " + limitStr
if DB_PROVIDER == "PgsqlDb" {
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = SqlReplace(Sql, "")
}
rows, err = DB.Query(Sql, valueList...)
@ -996,7 +995,7 @@ func GetCount(dbName, table string, where map[string]string, args ...string) (to
Sql = "select count(" + title + ") as count from " + dbName + " where " + strings.Join(whereStr, " and ") + " limit 1"
if DB_PROVIDER == "PgsqlDb" {
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = SqlReplace(Sql, "")
}
rows, err = DB.Query(Sql, valueList...)


+ 2
- 2
db_test.go View File

@ -36,8 +36,8 @@ func Test_Connet(t *testing.T) {
orderby := "id desc"
debug := true
// count, row, err := GetRow(dbname, table, alias, title, join, where, where_or, valueList, orderby, debug)
count, row, err := FetchRows(dbname, table, alias, title, join, where, where_or, valueList, orderby, "", 1, 10, debug)
//count, row, err := GetRow(dbname, table, alias, title, join, where, where_or, valueList, orderby, debug)
count, row, err := FetchRows(dbname, table, alias, title, join, join, where, where_or, valueList, orderby, "", "", 1, 10, debug)
log.Println(count)
log.Println(row)


+ 3
- 3
prepare.go View File

@ -60,7 +60,7 @@ func StmtForRead(dbName, table string, title string, where []string, limit map[s
Sql = "SELECT " + title + " FROM " + dbName + " where " + strings.Join(where, " and ") + limitStr
if DB_PROVIDER == "PgsqlDb" {
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = SqlReplace(Sql, "")
}
stmt, err = DB.Prepare(Sql)
} else {
@ -200,7 +200,7 @@ func StmtForUpdate(dbName, table string, data []string, where []string) (*sql.St
Sql = "update " + dbName + " set " + strings.Join(data, " , ") + " where " + strings.Join(where, " and ")
if DB_PROVIDER == "PgsqlDb" {
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = SqlReplace(Sql, "")
}
stmt, err = DB.Prepare(Sql)
@ -263,7 +263,7 @@ func StmtForInsert(dbName, table string, data []string) (*sql.Stmt, error) {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
//stmt, err = DB.Prepare("insert into " + dbName + " set " + strings.Join(data, " , "))


+ 6
- 7
transaction.go View File

@ -49,8 +49,7 @@ func TxInsert(tx *sql.Tx, dbname, table string, data map[string]string) (int64,
var Sql string
Sql = "insert into " + dbName + " (" + strings.Join(keyList, ",") + ") values (" + strings.Join(keyStr, ",") + ")"
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = helper.StringJoin(Sql, " RETURNING id")
Sql = SqlReplace(Sql, "add")
stmt, err = tx.Prepare(Sql)
if err != nil {
return 0, errors.New("创建失败:" + err.Error())
@ -117,7 +116,7 @@ func TxPreInsert(tx *sql.Tx, dbname, table string, data map[string]interface{})
if DB_PROVIDER == "PgsqlDb" {
Sql := helper.StringJoin("insert into ", dbName, " ("+strings.Join(insert_data, " , ")+")", " VALUES ", "("+strings.Join(value_data, " , ")+")", " RETURNING id")
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = SqlReplace(Sql, "")
stmt, err = tx.Prepare(Sql)
if err != nil {
return 0, errors.New("创建失败:" + err.Error())
@ -204,7 +203,7 @@ func TxUpdate(tx *sql.Tx, dbname, table string, data map[string]string, where ma
Sql = "update " + dbName + " set " + strings.Join(keyList, " , ") + " where " + strings.Join(whereStr, " and ")
if DB_PROVIDER == "PgsqlDb" {
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = SqlReplace(Sql, "")
}
result, err := tx.Exec(Sql, valueList...)
@ -246,7 +245,7 @@ func TxPreUpdate(tx *sql.Tx, dbname, table string, data []string, where []string
sql := "update " + dbName + " set " + strings.Join(data, " , ") + " where " + strings.Join(where, " and ")
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
stmt, err = tx.Prepare(sql)
@ -313,7 +312,7 @@ func TxDelete(tx *sql.Tx, dbname, table string, where map[string]string, del_cou
Sql = "delete from " + dbName + " where " + strings.Join(keyList, " and ") + limitStr
if DB_PROVIDER == "PgsqlDb" {
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = SqlReplace(Sql, "")
}
result, err := tx.Exec(Sql, valueList...)
@ -355,7 +354,7 @@ func TxForRead(tx *sql.Tx, dbName, table string, title string, where []string) (
Sql = "SELECT " + title + " FROM " + dbName + " where " + strings.Join(where, " and ") + " FOR UPDATE"
if DB_PROVIDER == "PgsqlDb" {
Sql = sqlx.Rebind(sqlx.DOLLAR, Sql)
Sql = strings.Replace(Sql, "`", `"`, -1)
Sql = SqlReplace(Sql, "")
}
stmt, err = tx.Prepare(Sql)
} else {


+ 7
- 8
transaction_chain.go View File

@ -356,7 +356,7 @@ func (this *TxQuery) BuildSelectSql() (map[string]interface{}, error) {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
return map[string]interface{}{
"sql": sql,
@ -377,7 +377,7 @@ func (this *TxQuery) GetTableInfo(table string) (map[string]interface{}, error)
sql := "select `" + strings.Join(field, "`,`") + "` from information_schema.COLUMNS where table_name = ? and table_schema = ?"
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
stmtSql, err := this.tx.Prepare(sql)
if err != nil {
@ -486,7 +486,7 @@ func (this *TxQuery) UpdateStmt() error {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
stmt, err = this.tx.Prepare(sql)
@ -610,7 +610,7 @@ func (this *TxQuery) UpdateAllStmt() error {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
stmt, err = this.tx.Prepare(sql)
@ -672,7 +672,7 @@ func (this *TxQuery) CreateStmt() error {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
stmt, err = this.tx.Prepare(sql)
@ -767,8 +767,7 @@ func (this *TxQuery) CreateAllStmt() error {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = helper.StringJoin(sql, " RETURNING id")
sql = SqlReplace(sql, "add")
}
stmt, err = this.tx.Prepare(sql)
@ -817,7 +816,7 @@ func (this *TxQuery) DeleteStmt() error {
}
if DB_PROVIDER == "PgsqlDb" {
sql = sqlx.Rebind(sqlx.DOLLAR, sql)
sql = strings.Replace(sql, "`", `"`, -1)
sql = SqlReplace(sql, "")
}
stmt, err = this.tx.Prepare(sql)


Loading…
Cancel
Save