mirror of https://github.com/go-gorm/gorm.git
38 lines
927 B
Go
38 lines
927 B
Go
package tests_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
. "github.com/jinzhu/gorm/tests"
|
|
)
|
|
|
|
func TestExceptionsWithInvalidSql(t *testing.T) {
|
|
var columns []string
|
|
if DB.Where("sdsd.zaaa = ?", "sd;;;aa").Pluck("aaa", &columns).Error == nil {
|
|
t.Errorf("Should got error with invalid SQL")
|
|
}
|
|
|
|
if DB.Model(&User{}).Where("sdsd.zaaa = ?", "sd;;;aa").Pluck("aaa", &columns).Error == nil {
|
|
t.Errorf("Should got error with invalid SQL")
|
|
}
|
|
|
|
if DB.Where("sdsd.zaaa = ?", "sd;;;aa").Find(&User{}).Error == nil {
|
|
t.Errorf("Should got error with invalid SQL")
|
|
}
|
|
|
|
var count1, count2 int64
|
|
DB.Model(&User{}).Count(&count1)
|
|
if count1 <= 0 {
|
|
t.Errorf("Should find some users")
|
|
}
|
|
|
|
if DB.Where("name = ?", "jinzhu; delete * from users").First(&User{}).Error == nil {
|
|
t.Errorf("Should got error with invalid SQL")
|
|
}
|
|
|
|
DB.Model(&User{}).Count(&count2)
|
|
if count1 != count2 {
|
|
t.Errorf("No user should not be deleted by invalid SQL")
|
|
}
|
|
}
|