@@ -50,6 +50,7 @@ type QueryTest struct {
5050 // such as the use of the SIGNAL statement.
5151 ExpectedErrStr string
5252 // ExpectedWarning contains the expected warning code when a query generates warnings but not errors.
53+ // The ExpectedWarningsCount field must be set as well.
5354 ExpectedWarning int
5455 // ExpectedWarningsCount is used to test the expected number of warnings generated by a query.
5556 // The ExpectedWarning field must be set for warning counts to be checked.
@@ -62,6 +63,8 @@ type QueryTest struct {
6263 ExpectedColumns sql.Schema
6364 // Bindings are the bind values for the query, if provided
6465 Bindings map [string ]sqlparser.Expr
66+ // Skip indicates that the query should be skipped
67+ Skip bool
6568 // SkipPrepared indicates that the query should be skipped when testing prepared statements
6669 SkipPrepared bool
6770 // SkipServerEngine indicates that the query should be skipped when testing a server engine (as opposed to the
@@ -4175,9 +4178,121 @@ SELECT * FROM cte WHERE d = 2;`,
41754178 Expected : []sql.Row {{"9999-12-31 23:59:59.999999" }},
41764179 },
41774180 {
4181+ // This returns null in MySQL, but we are able to truncate the string and convert to a datetime
4182+ Skip : true ,
41784183 Query : "SELECT date_add('9999-12-31:23:59:59.99999944444444444-', INTERVAL 0 day);" ,
41794184 Expected : []sql.Row {{nil }},
41804185 },
4186+ // https://github.com/dolthub/dolt/issues/9917
4187+ {
4188+ Query : "select cast('2020-01-01 a' as datetime)" ,
4189+ ExpectedWarning : 1292 ,
4190+ ExpectedWarningsCount : 1 ,
4191+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC )}},
4192+ },
4193+ {
4194+ Query : "select cast('2020-01-01 abc123' as datetime)" ,
4195+ ExpectedWarning : 1292 ,
4196+ ExpectedWarningsCount : 1 ,
4197+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 0 , 0 , 0 , 0 , time .UTC )}},
4198+ },
4199+ {
4200+ Query : "select cast('2020-01-01 12:30asdf123' as datetime)" ,
4201+ ExpectedWarning : 1292 ,
4202+ ExpectedWarningsCount : 1 ,
4203+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 30 , 0 , 0 , time .UTC )}},
4204+ },
4205+ {
4206+ Query : "select cast('2020-01-01 12:34:56abc' as datetime);" ,
4207+ ExpectedWarning : 1292 ,
4208+ ExpectedWarningsCount : 1 ,
4209+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 0 , time .UTC )}},
4210+ },
4211+ {
4212+ Query : "select cast('2020-01-01 12:34:56 abc' as datetime);" ,
4213+ ExpectedWarning : 1292 ,
4214+ ExpectedWarningsCount : 1 , // MySQL has 2 warnings, but we don't have a warning for deprecated delimiter
4215+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 0 , time .UTC )}},
4216+ },
4217+ {
4218+ Query : "select cast('2020-01-01 12:34:56.1 abc' as datetime);" ,
4219+ ExpectedWarning : 1292 ,
4220+ ExpectedWarningsCount : 1 , // MySQL has 2 warnings, but we don't have a warning for deprecated delimiter
4221+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 0 , time .UTC )}},
4222+ },
4223+ {
4224+ Query : "select cast('2020-01-01 12:34:56:123456 abc' as datetime);" ,
4225+ ExpectedWarning : 1292 ,
4226+ ExpectedWarningsCount : 1 ,
4227+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 0 , time .UTC )}},
4228+ },
4229+ {
4230+ Query : "select cast('2020-01-01 12:34:56...123456 abc' as datetime);" ,
4231+ ExpectedWarning : 1292 ,
4232+ ExpectedWarningsCount : 1 ,
4233+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 0 , time .UTC )}},
4234+ },
4235+ {
4236+ Query : "select cast('2020-01-01 12:34:56-123456 abc' as datetime);" ,
4237+ ExpectedWarning : 1292 ,
4238+ ExpectedWarningsCount : 1 ,
4239+ // MySQL returns null, but we are able to truncate and convert
4240+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 0 , time .UTC )}},
4241+ },
4242+ {
4243+ Query : "select cast('2020-01-01 12:34:56.123456abc' as datetime(0));" ,
4244+ ExpectedWarning : 1292 ,
4245+ ExpectedWarningsCount : 1 ,
4246+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 0 , time .UTC )}},
4247+ },
4248+ {
4249+ // TODO: implement precision for datetime casting
4250+ Skip : true ,
4251+ Query : "select cast('2020-01-01 12:34:56.123456abc' as datetime(1));" ,
4252+ ExpectedWarning : 1292 ,
4253+ ExpectedWarningsCount : 1 ,
4254+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 100000000 , time .UTC )}},
4255+ },
4256+ {
4257+ // TODO: implement precision for datetime casting
4258+ Skip : true ,
4259+ Query : "select cast('2020-01-01 12:34:56.123456abc' as datetime(2));" ,
4260+ ExpectedWarning : 1292 ,
4261+ ExpectedWarningsCount : 1 ,
4262+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 120000000 , time .UTC )}},
4263+ },
4264+ {
4265+ // TODO: implement precision for datetime casting
4266+ Skip : true ,
4267+ Query : "select cast('2020-01-01 12:34:56.123456abc' as datetime(3));" ,
4268+ ExpectedWarning : 1292 ,
4269+ ExpectedWarningsCount : 1 ,
4270+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 123000000 , time .UTC )}},
4271+ },
4272+ {
4273+ // TODO: implement precision for datetime casting
4274+ Skip : true ,
4275+ Query : "select cast('2020-01-01 12:34:56.123456abc' as datetime(4));" ,
4276+ ExpectedWarning : 1292 ,
4277+ ExpectedWarningsCount : 1 ,
4278+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 123500000 , time .UTC )}},
4279+ },
4280+ {
4281+ // TODO: implement precision for datetime casting
4282+ Skip : true ,
4283+ Query : "select cast('2020-01-01 12:34:56.123456abc' as datetime(5));" ,
4284+ ExpectedWarning : 1292 ,
4285+ ExpectedWarningsCount : 1 ,
4286+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 123460000 , time .UTC )}},
4287+ },
4288+ {
4289+ // TODO: implement precision for datetime casting
4290+ Skip : true ,
4291+ Query : "select cast('2020-01-01 12:34:56.123456abc' as datetime(6));" ,
4292+ ExpectedWarning : 1292 ,
4293+ ExpectedWarningsCount : 1 ,
4294+ Expected : []sql.Row {{time .Date (2020 , time .January , 1 , 12 , 34 , 56 , 123456000 , time .UTC )}},
4295+ },
41814296 {
41824297 Query : `SELECT * FROM (SELECT * FROM (SELECT * FROM (SELECT * FROM othertable) othertable_one) othertable_two) othertable_three WHERE s2 = 'first'` ,
41834298 Expected : []sql.Row {
0 commit comments