Compare commits
4 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 155475f40f | |||
| 9ea6acb3f6 | |||
| 6e7fa27d0c | |||
|
802118fbd2 |
3 changed files with 7 additions and 21 deletions
|
|
@ -170,7 +170,7 @@ func (a *App) UpdateRows(c config.SchemaConfigAction, globalColumns map[string]s
|
||||||
updates = append(updates, database.GetNamedParameter(a.DbConfig.Type, col, len(values)+1))
|
updates = append(updates, database.GetNamedParameter(a.DbConfig.Type, col, len(values)+1))
|
||||||
values[len(values)+1] = value.FinalValue()
|
values[len(values)+1] = value.FinalValue()
|
||||||
} else {
|
} else {
|
||||||
updates = append(updates, fmt.Sprintf("%s=%s", database.EscapeColumn(a.DbConfig.Type, col), value.FinalValue()))
|
updates = append(updates, fmt.Sprintf("%s=%s", col, value.FinalValue()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -179,7 +179,7 @@ func (a *App) UpdateRows(c config.SchemaConfigAction, globalColumns map[string]s
|
||||||
value := row[col]
|
value := row[col]
|
||||||
|
|
||||||
if !value.IsString || value.IsNull {
|
if !value.IsString || value.IsNull {
|
||||||
pkeys = append(pkeys, fmt.Sprintf("%s=%s", database.EscapeColumn(a.DbConfig.Type, col), value.FinalValue()))
|
pkeys = append(pkeys, fmt.Sprintf("%s=%s", col, value.FinalValue()))
|
||||||
} else {
|
} else {
|
||||||
pkeys = append(pkeys, database.GetNamedParameter(a.DbConfig.Type, col, len(values)+1))
|
pkeys = append(pkeys, database.GetNamedParameter(a.DbConfig.Type, col, len(values)+1))
|
||||||
values[len(values)+1] = value.FinalValue()
|
values[len(values)+1] = value.FinalValue()
|
||||||
|
|
|
||||||
|
|
@ -15,16 +15,12 @@ func EscapeTable(dbType, table string) string {
|
||||||
return fmt.Sprintf("\"%s\"", table)
|
return fmt.Sprintf("\"%s\"", table)
|
||||||
}
|
}
|
||||||
|
|
||||||
func EscapeColumn(dbType, col string) string {
|
|
||||||
return EscapeTable(dbType, col)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetNamedParameter(dbType, col string, number int) string {
|
func GetNamedParameter(dbType, col string, number int) string {
|
||||||
if dbType == "mysql" {
|
if dbType == "mysql" {
|
||||||
return fmt.Sprintf("%s=?", EscapeColumn(dbType, col))
|
return fmt.Sprintf("%s=?", col)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%s=$%d", EscapeColumn(dbType, col), number)
|
return fmt.Sprintf("%s=$%d", col, number)
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsPgNumberType(value string) bool {
|
func IsPgNumberType(value string) bool {
|
||||||
|
|
@ -84,7 +80,7 @@ func GetRows(db *sql.DB, query, table, dbType string) map[int]map[string]data.Da
|
||||||
if value != nil {
|
if value != nil {
|
||||||
if dbType == "postgres" {
|
if dbType == "postgres" {
|
||||||
if len(columnsTypes[col]) == 0 {
|
if len(columnsTypes[col]) == 0 {
|
||||||
typeQuery := fmt.Sprintf("SELECT pg_typeof(%s) as value FROM %s", EscapeColumn(dbType, col), EscapeTable(dbType, table))
|
typeQuery := fmt.Sprintf("SELECT pg_typeof(%s) as value FROM %s", col, EscapeTable(dbType, table))
|
||||||
db.QueryRow(typeQuery).Scan(&typeValue)
|
db.QueryRow(typeQuery).Scan(&typeValue)
|
||||||
columnsTypes[col] = typeValue
|
columnsTypes[col] = typeValue
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,22 +14,12 @@ func TestEscapeTable(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEscapeColumn(t *testing.T) {
|
|
||||||
if EscapeColumn("mysql", "foo") != "`foo`" {
|
|
||||||
t.Fatalf("TestEscapeColumn: mysql check failed")
|
|
||||||
}
|
|
||||||
|
|
||||||
if EscapeColumn("postgres", "foo") != "\"foo\"" {
|
|
||||||
t.Fatalf("TestEscapeColumn: postgres check failed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestGetNamedParameter(t *testing.T) {
|
func TestGetNamedParameter(t *testing.T) {
|
||||||
if GetNamedParameter("mysql", "foo", 1) != "`foo`=?" {
|
if GetNamedParameter("mysql", "foo", 1) != "foo=?" {
|
||||||
t.Fatalf("TestGetNamedParameter: mysql check failed")
|
t.Fatalf("TestGetNamedParameter: mysql check failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if GetNamedParameter("postgres", "foo", 1) != "\"foo\"=$1" {
|
if GetNamedParameter("postgres", "foo", 1) != "foo=$1" {
|
||||||
t.Fatalf("TestGetNamedParameter: postgres check failed")
|
t.Fatalf("TestGetNamedParameter: postgres check failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue