Skip to content

Commit 9944f31

Browse files
committed
add tests
1 parent 5a790fb commit 9944f31

File tree

2 files changed

+94
-5
lines changed

2 files changed

+94
-5
lines changed

enginetest/memory_engine_test.go

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -200,24 +200,103 @@ func TestSingleQueryPrepared(t *testing.T) {
200200

201201
// Convenience test for debugging a single query. Unskip and set to the desired query.
202202
func TestSingleScript(t *testing.T) {
203-
t.Skip()
203+
// t.Skip()
204204
var scripts = []queries.ScriptTest{
205205
{
206-
Name: "AS OF propagates to nested CALLs",
206+
Name: "Reproduction test for issue 9872: TEXT(m) syntax support",
207207
SetUpScript: []string{},
208208
Assertions: []queries.ScriptTestAssertion{
209209
{
210-
Query: "create procedure create_proc() create table t (i int primary key, j int);",
210+
// https://github.com/dolthub/dolt/issues/9872 - Support for mysql `Text(m)` syntax
211+
Query: "CREATE TABLE task_instance_note (ti_id VARCHAR(36) NOT NULL, user_id VARCHAR(128), content TEXT(1000), created_at TIMESTAMP(6) NOT NULL, updated_at TIMESTAMP(6) NOT NULL, CONSTRAINT task_instance_note_pkey PRIMARY KEY (ti_id))",
212+
Expected: []sql.Row{
213+
{types.NewOkResult(0)},
214+
},
215+
},
216+
{
217+
Query: "CREATE TABLE test_text_small (id INT PRIMARY KEY, small_text TEXT(255))",
218+
Expected: []sql.Row{
219+
{types.NewOkResult(0)},
220+
},
221+
},
222+
{
223+
Query: "CREATE TABLE test_text_large (id INT PRIMARY KEY, large_text TEXT(65535))",
224+
Expected: []sql.Row{
225+
{types.NewOkResult(0)},
226+
},
227+
},
228+
{
229+
Query: "CREATE TABLE test_text_medium (id INT PRIMARY KEY, medium_text TEXT(16777215))",
230+
Expected: []sql.Row{
231+
{types.NewOkResult(0)},
232+
},
233+
},
234+
{
235+
Query: "CREATE TABLE test_text_10k (id INT PRIMARY KEY, text_10k TEXT(10000))",
211236
Expected: []sql.Row{
212237
{types.NewOkResult(0)},
213238
},
214239
},
215240
{
216-
Query: "call create_proc()",
241+
Query: "CREATE TABLE test_text_100k (id INT PRIMARY KEY, text_100k TEXT(100000))",
217242
Expected: []sql.Row{
218243
{types.NewOkResult(0)},
219244
},
220245
},
246+
{
247+
Query: "CREATE TABLE test_text_1m (id INT PRIMARY KEY, text_1m TEXT(1000000))",
248+
Expected: []sql.Row{
249+
{types.NewOkResult(0)},
250+
},
251+
},
252+
{
253+
Query: "CREATE TABLE test_text_no_length (id INT PRIMARY KEY, text_no_length TEXT)",
254+
Expected: []sql.Row{
255+
{types.NewOkResult(0)},
256+
},
257+
},
258+
{
259+
Query: "DESCRIBE test_text_small",
260+
Expected: []sql.Row{
261+
{"id", "int", "NO", "PRI", nil, ""},
262+
{"small_text", "text", "YES", "", nil, ""},
263+
},
264+
},
265+
{
266+
Query: "DESCRIBE test_text_large",
267+
Expected: []sql.Row{
268+
{"id", "int", "NO", "PRI", nil, ""},
269+
{"large_text", "mediumtext", "YES", "", nil, ""},
270+
},
271+
},
272+
{
273+
Query: "DESCRIBE test_text_medium",
274+
Expected: []sql.Row{
275+
{"id", "int", "NO", "PRI", nil, ""},
276+
{"medium_text", "longtext", "YES", "", nil, ""},
277+
},
278+
},
279+
{
280+
Query: "DESCRIBE test_text_10k",
281+
Expected: []sql.Row{
282+
{"id", "int", "NO", "PRI", nil, ""},
283+
{"text_10k", "text", "YES", "", nil, ""},
284+
},
285+
},
286+
{
287+
Query: "DESCRIBE test_text_100k",
288+
Expected: []sql.Row{
289+
{"id", "int", "NO", "PRI", nil, ""},
290+
{"text_100k", "mediumtext", "YES", "", nil, ""},
291+
},
292+
},
293+
{
294+
Query: "DESCRIBE test_text_1m",
295+
Expected: []sql.Row{
296+
{"id", "int", "NO", "PRI", nil, ""},
297+
{"text_1m", "mediumtext", "YES", "", nil, ""},
298+
},
299+
},
221300
},
222301
},
223302
}

sql/types/conversion.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,17 @@ func ColumnTypeToType(ct *sqlparser.ColumnType) (sql.Type, error) {
268268
if err != nil {
269269
return nil, err
270270
}
271-
return CreateString(sqltypes.Text, length, collation)
271+
// MySQL automatically chooses the appropriate TEXT type based on length
272+
// TEXT(1) to TEXT(65534) → text (65535 max)
273+
// TEXT(65535) to TEXT(16777215) → mediumtext (16777215 max)
274+
// TEXT(16777216) to TEXT(4294967295) → longtext (4294967295 max)
275+
if length < TextBlobMax {
276+
return CreateString(sqltypes.Text, TextBlobMax/collation.CharacterSet().MaxLength(), collation)
277+
} else if length <= MediumTextBlobMax {
278+
return CreateString(sqltypes.Text, MediumTextBlobMax/collation.CharacterSet().MaxLength(), collation)
279+
} else {
280+
return CreateString(sqltypes.Text, LongTextBlobMax/collation.CharacterSet().MaxLength(), collation)
281+
}
272282
case "mediumtext", "mediumblob", "long", "long varchar":
273283
collation, err := sql.ParseCollation(ct.Charset, collate, ct.BinaryCollate)
274284
if err != nil {

0 commit comments

Comments
 (0)