building prepared queries (with positional params)
This commit is contained in:
parent
39ebc75c43
commit
41c3d15963
@ -136,3 +136,13 @@ func BuildRangeInsertQuery(databaseName, originalTableName, ghostTableName strin
|
|||||||
rangeStartComparison, rangeEndComparison)
|
rangeStartComparison, rangeEndComparison)
|
||||||
return query, nil
|
return query, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BuildRangeInsertPreparedQuery(databaseName, originalTableName, ghostTableName string, sharedColumns []string, uniqueKey string, uniqueKeyColumns []string) (string, error) {
|
||||||
|
rangeStartValues := make([]string, len(uniqueKeyColumns), len(uniqueKeyColumns))
|
||||||
|
rangeEndValues := make([]string, len(uniqueKeyColumns), len(uniqueKeyColumns))
|
||||||
|
for i := range uniqueKeyColumns {
|
||||||
|
rangeStartValues[i] = "?"
|
||||||
|
rangeEndValues[i] = "?"
|
||||||
|
}
|
||||||
|
return BuildRangeInsertQuery(databaseName, originalTableName, ghostTableName, sharedColumns, uniqueKey, uniqueKeyColumns, rangeStartValues, rangeEndValues)
|
||||||
|
}
|
||||||
|
@ -155,3 +155,24 @@ func TestBuildRangeInsertQuery(t *testing.T) {
|
|||||||
test.S(t).ExpectEquals(normalizeQuery(query), normalizeQuery(expected))
|
test.S(t).ExpectEquals(normalizeQuery(query), normalizeQuery(expected))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBuildRangeInsertPreparedQuery(t *testing.T) {
|
||||||
|
databaseName := "mydb"
|
||||||
|
originalTableName := "tbl"
|
||||||
|
ghostTableName := "ghost"
|
||||||
|
sharedColumns := []string{"id", "name", "position"}
|
||||||
|
{
|
||||||
|
uniqueKey := "name_position_uidx"
|
||||||
|
uniqueKeyColumns := []string{"name", "position"}
|
||||||
|
|
||||||
|
query, err := BuildRangeInsertPreparedQuery(databaseName, originalTableName, ghostTableName, sharedColumns, uniqueKey, uniqueKeyColumns)
|
||||||
|
test.S(t).ExpectNil(err)
|
||||||
|
expected := `
|
||||||
|
insert /* gh-osc mydb.tbl */ ignore into mydb.ghost (id, name, position)
|
||||||
|
(select id, name, position from mydb.tbl force index (name_position_uidx)
|
||||||
|
where (((name > ?) or (((name = ?)) AND (position > ?)) or ((name = ?) and (position = ?))) and ((name < ?) or (((name = ?)) AND (position < ?)) or ((name = ?) and (position = ?))))
|
||||||
|
)
|
||||||
|
`
|
||||||
|
test.S(t).ExpectEquals(normalizeQuery(query), normalizeQuery(expected))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user