зеркало из https://github.com/github/vitess-gh.git
fix - null as primary key is allowed in an insert statement with auto_increment
This commit is contained in:
Родитель
11c08ca717
Коммит
928c58d4c9
|
@ -47,6 +47,15 @@ func IsValue(node ValExpr) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
// IsNull returns true if the ValExpr is nil.
|
||||
func IsNull(node ValExpr) bool {
|
||||
switch node.(type) {
|
||||
case *NullVal:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// HasINClause returns true if any of the conditions has an IN clause.
|
||||
func HasINClause(conditions []BoolExpr) bool {
|
||||
for _, node := range conditions {
|
||||
|
|
|
@ -617,6 +617,30 @@ func TestNocacheCases(t *testing.T) {
|
|||
framework.TestQuery("commit"),
|
||||
},
|
||||
},
|
||||
&framework.MultiCase{
|
||||
Name: "insert with null auto_increment",
|
||||
Cases: []framework.Testable{
|
||||
framework.TestQuery("alter table vitess_e auto_increment = 1"),
|
||||
framework.TestQuery("begin"),
|
||||
&framework.TestCase{
|
||||
Query: "insert /* auto_increment */ into vitess_e(eid, name, foo) values (NULL, 'aaaa', 'cccc')",
|
||||
Rewritten: []string{
|
||||
"insert /* auto_increment */ into vitess_e(eid, name, foo) values (null, 'aaaa', 'cccc') /* _stream vitess_e (eid id name ) (null 1 'YWFhYQ==' )",
|
||||
},
|
||||
RowsAffected: 1,
|
||||
},
|
||||
framework.TestQuery("commit"),
|
||||
&framework.TestCase{
|
||||
Query: "select * from vitess_e",
|
||||
Result: [][]string{
|
||||
{"1", "1", "aaaa", "cccc"},
|
||||
},
|
||||
},
|
||||
framework.TestQuery("begin"),
|
||||
framework.TestQuery("delete from vitess_e"),
|
||||
framework.TestQuery("commit"),
|
||||
},
|
||||
},
|
||||
&framework.MultiCase{
|
||||
Name: "insert with number default value",
|
||||
Cases: []framework.Testable{
|
||||
|
|
|
@ -494,7 +494,7 @@ func getInsertPKValues(pkColumnNumbers []int, rowList sqlparser.Values, tableInf
|
|||
return nil, errors.New("column count doesn't match value count")
|
||||
}
|
||||
node := row[columnNumber]
|
||||
if !sqlparser.IsValue(node) {
|
||||
if !sqlparser.IsNull(node) && !sqlparser.IsValue(node) {
|
||||
return nil, nil
|
||||
}
|
||||
var err error
|
||||
|
|
Загрузка…
Ссылка в новой задаче