1515package queries
1616
1717import (
18+ "github.com/dolthub/vitess/go/mysql"
1819 "math"
1920 "time"
2021
@@ -140,76 +141,76 @@ var ScriptTests = []ScriptTest{
140141 Name : "String-to-number comparison operators should behave consistently" ,
141142 Assertions : []ScriptTestAssertion {
142143 {
143- Dialect : "mysql" ,
144- Query : "SELECT ('A') = (0)" ,
145- Expected : []sql.Row {{true }},
146- // ExpectedWarningsCount: 1,
147- // ExpectedWarning: mysql.ERTruncatedWrongValue,
148- // ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
144+ Dialect : "mysql" ,
145+ Query : "SELECT ('A') = (0)" ,
146+ Expected : []sql.Row {{true }},
147+ ExpectedWarningsCount : 1 ,
148+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
149+ ExpectedWarningMessageSubstring : "Truncated incorrect double value: A" ,
149150 },
150151 {
151- Dialect : "mysql" ,
152- Query : "SELECT ('A') IN (0)" ,
153- Expected : []sql.Row {{true }},
154- // ExpectedWarningsCount: 1,
155- // ExpectedWarning: mysql.ERTruncatedWrongValue,
156- // ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
152+ Dialect : "mysql" ,
153+ Query : "SELECT ('A') IN (0)" ,
154+ Expected : []sql.Row {{true }},
155+ ExpectedWarningsCount : 1 ,
156+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
157+ ExpectedWarningMessageSubstring : "Truncated incorrect double value: A" ,
157158 },
158159 {
159- Dialect : "mysql" ,
160- Query : "SELECT ('A') != (0)" ,
161- Expected : []sql.Row {{false }},
162- // ExpectedWarningsCount: 1,
163- // ExpectedWarning: mysql.ERTruncatedWrongValue,
164- // ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
160+ Dialect : "mysql" ,
161+ Query : "SELECT ('A') != (0)" ,
162+ Expected : []sql.Row {{false }},
163+ ExpectedWarningsCount : 1 ,
164+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
165+ ExpectedWarningMessageSubstring : "Truncated incorrect double value: A" ,
165166 },
166167 {
167- Dialect : "mysql" ,
168- Query : "SELECT ('A') <> (0)" ,
169- Expected : []sql.Row {{false }},
170- // ExpectedWarningsCount: 1,
171- // ExpectedWarning: mysql.ERTruncatedWrongValue,
172- // ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
168+ Dialect : "mysql" ,
169+ Query : "SELECT ('A') <> (0)" ,
170+ Expected : []sql.Row {{false }},
171+ ExpectedWarningsCount : 1 ,
172+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
173+ ExpectedWarningMessageSubstring : "Truncated incorrect double value: A" ,
173174 },
174175 {
175- Dialect : "mysql" ,
176- Query : "SELECT ('A') < (0)" ,
177- Expected : []sql.Row {{false }},
178- // ExpectedWarningsCount: 1,
179- // ExpectedWarning: mysql.ERTruncatedWrongValue,
180- // ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
176+ Dialect : "mysql" ,
177+ Query : "SELECT ('A') < (0)" ,
178+ Expected : []sql.Row {{false }},
179+ ExpectedWarningsCount : 1 ,
180+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
181+ ExpectedWarningMessageSubstring : "Truncated incorrect double value: A" ,
181182 },
182183 {
183- Dialect : "mysql" ,
184- Query : "SELECT ('A') <= (0)" ,
185- Expected : []sql.Row {{true }},
186- // ExpectedWarningsCount: 1,
187- // ExpectedWarning: mysql.ERTruncatedWrongValue,
188- // ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
184+ Dialect : "mysql" ,
185+ Query : "SELECT ('A') <= (0)" ,
186+ Expected : []sql.Row {{true }},
187+ ExpectedWarningsCount : 1 ,
188+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
189+ ExpectedWarningMessageSubstring : "Truncated incorrect double value: A" ,
189190 },
190191 {
191- Dialect : "mysql" ,
192- Query : "SELECT ('A') > (0)" ,
193- Expected : []sql.Row {{false }},
194- // ExpectedWarningsCount: 1,
195- // ExpectedWarning: mysql.ERTruncatedWrongValue,
196- // ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
192+ Dialect : "mysql" ,
193+ Query : "SELECT ('A') > (0)" ,
194+ Expected : []sql.Row {{false }},
195+ ExpectedWarningsCount : 1 ,
196+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
197+ ExpectedWarningMessageSubstring : "Truncated incorrect double value: A" ,
197198 },
198199 {
199- Dialect : "mysql" ,
200- Query : "SELECT ('A') >= (0)" ,
201- Expected : []sql.Row {{true }},
202- // ExpectedWarningsCount: 1,
203- // ExpectedWarning: mysql.ERTruncatedWrongValue,
204- // ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
200+ Dialect : "mysql" ,
201+ Query : "SELECT ('A') >= (0)" ,
202+ Expected : []sql.Row {{true }},
203+ ExpectedWarningsCount : 1 ,
204+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
205+ ExpectedWarningMessageSubstring : "Truncated incorrect double value: A" ,
205206 },
206207 {
207- Dialect : "mysql" ,
208- Query : "SELECT ('A') NOT IN (0)" ,
209- Expected : []sql.Row {{false }},
210- // ExpectedWarningsCount: 1,
211- // ExpectedWarning: mysql.ERTruncatedWrongValue,
212- // ExpectedWarningMessageSubstring: "Truncated incorrect double value: A",
208+ Dialect : "mysql" ,
209+ Query : "SELECT ('A') NOT IN (0)" ,
210+ Expected : []sql.Row {{false }},
211+ ExpectedWarningsCount : 1 ,
212+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
213+ ExpectedWarningMessageSubstring : "Truncated incorrect double value: A" ,
213214 },
214215 },
215216 },
@@ -11755,8 +11756,8 @@ select * from t1 except (
1175511756 {"5.932887e7abc" , float32 (5.932887e+07 )},
1175611757 {"a1a1" , float32 (0 )},
1175711758 },
11758- // ExpectedWarningsCount: 12,
11759- // ExpectedWarning: mysql.ERTruncatedWrongValue,
11759+ ExpectedWarningsCount : 12 ,
11760+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
1176011761 },
1176111762 {
1176211763 Dialect : "mysql" ,
@@ -11781,8 +11782,8 @@ select * from t1 except (
1178111782 {"5.932887e7abc" , 5.932887e+07 },
1178211783 {"a1a1" , 0.0 },
1178311784 },
11784- // ExpectedWarningsCount: 12,
11785- // ExpectedWarning: mysql.ERTruncatedWrongValue,
11785+ ExpectedWarningsCount : 12 ,
11786+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
1178611787 },
1178711788 {
1178811789 Dialect : "mysql" ,
@@ -11807,8 +11808,8 @@ select * from t1 except (
1180711808 {"5.932887e7abc" , 5 },
1180811809 {"a1a1" , 0 },
1180911810 },
11810- // ExpectedWarningsCount: 12 ,
11811- // ExpectedWarning: mysql.ERTruncatedWrongValue,
11811+ ExpectedWarningsCount : 16 ,
11812+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
1181211813 },
1181311814 {
1181411815 Dialect : "mysql" ,
@@ -11833,8 +11834,10 @@ select * from t1 except (
1183311834 {"5.932887e7abc" , uint64 (5 )},
1183411835 {"a1a1" , uint64 (0 )},
1183511836 },
11836- //ExpectedWarningsCount: 19,
11837- //ExpectedWarning: mysql.ERTruncatedWrongValue,
11837+ // TODO: Should be 19. Missing warnings for "Cast to unsigned converted negative integer to its positive
11838+ // complement" (1105)
11839+ ExpectedWarningsCount : 16 ,
11840+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
1183811841 },
1183911842 {
1184011843 Dialect : "mysql" ,
@@ -11859,13 +11862,14 @@ select * from t1 except (
1185911862 {"5.932887e7abc" , "59328870.000" },
1186011863 {"a1a1" , "0.000" },
1186111864 },
11862- //ExpectedWarningsCount: 13,
11863- //ExpectedWarning: mysql.ERTruncatedWrongValue,
11865+ // TODO: should be 13. Missing warning for "Incorrect DECIMAL value: '0' for column '' at row -1" (1366)
11866+ ExpectedWarningsCount : 12 ,
11867+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
1186411868 },
1186511869 {
11866- Query : "select * from test01 where pk in ('11')" ,
11867- Expected : []sql.Row {{"11" }},
11868- // ExpectedWarningsCount: 0,
11870+ Query : "select * from test01 where pk in ('11')" ,
11871+ Expected : []sql.Row {{"11" }},
11872+ ExpectedWarningsCount : 0 ,
1186911873 },
1187011874 {
1187111875 // https://github.com/dolthub/dolt/issues/9739
@@ -11878,8 +11882,8 @@ select * from t1 except (
1187811882 {"11d" },
1187911883 {"11wha?" },
1188011884 },
11881- // ExpectedWarningsCount: 12,
11882- // ExpectedWarning: mysql.ERTruncatedWrongValue,
11885+ ExpectedWarningsCount : 12 ,
11886+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
1188311887 },
1188411888 {
1188511889 // https://github.com/dolthub/dolt/issues/9739
@@ -11891,8 +11895,8 @@ select * from t1 except (
1189111895 {" 3. 12 4" },
1189211896 {"3. 12 4" },
1189311897 },
11894- // ExpectedWarningsCount: 12,
11895- // ExpectedWarning: mysql.ERTruncatedWrongValue,
11898+ ExpectedWarningsCount : 12 ,
11899+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
1189611900 },
1189711901 {
1189811902 // https://github.com/dolthub/dolt/issues/9739
@@ -11906,26 +11910,77 @@ select * from t1 except (
1190611910 {"+3.1234" },
1190711911 {"3. 12 4" },
1190811912 },
11909- // ExpectedWarningsCount: 20,
11910- // ExpectedWarning: mysql.ERTruncatedWrongValue,
11913+ ExpectedWarningsCount : 20 ,
11914+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
1191111915 },
1191211916 {
1191311917 // https://github.com/dolthub/dolt/issues/9739
11914- Skip : true ,
11915- Dialect : "mysql" ,
11916- Query : "select * from test02 where pk in ('11asdf')" ,
11917- Expected : []sql.Row {{"11" }},
11918- // ExpectedWarningsCount: 1,
11919- // ExpectedWarning: mysql.ERTruncatedWrongValue,
11918+ Skip : true ,
11919+ Dialect : "mysql" ,
11920+ Query : "select * from test02 where pk in ('11asdf')" ,
11921+ Expected : []sql.Row {{"11" }},
11922+ ExpectedWarningsCount : 1 ,
11923+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
1192011924 },
1192111925 {
1192211926 // https://github.com/dolthub/dolt/issues/9739
11923- Skip : true ,
11924- Dialect : "mysql" ,
11925- Query : "select * from test02 where pk='11.12asdf'" ,
11926- Expected : []sql.Row {},
11927- //ExpectedWarningsCount: 1,
11928- //ExpectedWarning: mysql.ERTruncatedWrongValue,
11927+ Skip : true ,
11928+ Dialect : "mysql" ,
11929+ Query : "select * from test02 where pk='11.12asdf'" ,
11930+ Expected : []sql.Row {},
11931+ ExpectedWarningsCount : 1 ,
11932+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
11933+ },
11934+ },
11935+ },
11936+ {
11937+ // https://github.com/dolthub/dolt/issues/9821
11938+ Name : "strings convert to booleans" ,
11939+ Assertions : []ScriptTestAssertion {
11940+ {
11941+ Query : `select '3bxu' and true` ,
11942+ Expected : []sql.Row {{true }},
11943+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
11944+ ExpectedWarningsCount : 1 ,
11945+ },
11946+ {
11947+ Query : "select '3bxu' or false" ,
11948+ Expected : []sql.Row {{true }},
11949+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
11950+ ExpectedWarningsCount : 1 ,
11951+ },
11952+ {
11953+ Query : "select '3bxu' xor false" ,
11954+ Expected : []sql.Row {{true }},
11955+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
11956+ ExpectedWarningsCount : 1 ,
11957+ },
11958+ {
11959+ Query : "select '' or false" ,
11960+ Expected : []sql.Row {{false }},
11961+ ExpectedWarningsCount : 0 ,
11962+ },
11963+ {
11964+ Query : "select '0' or false" ,
11965+ Expected : []sql.Row {{false }},
11966+ ExpectedWarningsCount : 0 ,
11967+ },
11968+ {
11969+ Query : "select '00' or false" ,
11970+ Expected : []sql.Row {{false }},
11971+ ExpectedWarningsCount : 0 ,
11972+ },
11973+ {
11974+ Query : "select '00asdf' or false" ,
11975+ Expected : []sql.Row {{false }},
11976+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
11977+ ExpectedWarningsCount : 1 ,
11978+ },
11979+ {
11980+ Query : "select 'asdf' or false" ,
11981+ Expected : []sql.Row {{false }},
11982+ ExpectedWarning : mysql .ERTruncatedWrongValue ,
11983+ ExpectedWarningsCount : 1 ,
1192911984 },
1193011985 },
1193111986 },
0 commit comments