github.com/dolthub/go-mysql-server@v0.18.0/enginetest/queries/blob_queries.go (about)

     1  // Copyright 2022 Dolthub, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package queries
    16  
    17  import (
    18  	"github.com/dolthub/go-mysql-server/sql"
    19  	"github.com/dolthub/go-mysql-server/sql/types"
    20  )
    21  
    22  var BlobQueries = []QueryTest{
    23  	{
    24  		Query: "select i, hex(b) from blobt",
    25  		Expected: []sql.Row{
    26  			{1, "666972737420726F77"},
    27  			{2, "7365636F6E6420726F77"},
    28  			{3, "746869726420726F77"},
    29  		},
    30  	},
    31  	{
    32  		Query: "select * from blobt where i = 1",
    33  		Expected: []sql.Row{
    34  			{1, []byte("first row")},
    35  		},
    36  	},
    37  	{
    38  		Query: "select * from blobt order by b desc",
    39  		Expected: []sql.Row{
    40  			{3, []byte("third row")},
    41  			{2, []byte("second row")},
    42  			{1, []byte("first row")},
    43  		},
    44  	},
    45  	{
    46  		Query: "select * from blobt where b <= 'second row'",
    47  		Expected: []sql.Row{
    48  			{2, []byte("second row")},
    49  			{1, []byte("first row")},
    50  		},
    51  	},
    52  	{
    53  		Query: "select i, hex(t) from textt",
    54  		Expected: []sql.Row{
    55  			{1, "666972737420726F77"},
    56  			{2, "7365636F6E6420726F77"},
    57  			{3, "746869726420726F77"},
    58  		},
    59  	},
    60  	{
    61  		Query: "select * from textt where i = 1",
    62  		Expected: []sql.Row{
    63  			{1, "first row"},
    64  		},
    65  	},
    66  	{
    67  		Query: "select * from textt order by t desc",
    68  		Expected: []sql.Row{
    69  			{3, "third row"},
    70  			{2, "second row"},
    71  			{1, "first row"},
    72  		},
    73  	},
    74  	{
    75  		Query: "select * from textt where t <= 'second row'",
    76  		Expected: []sql.Row{
    77  			{1, "first row"},
    78  			{2, "second row"},
    79  		},
    80  	},
    81  }
    82  
    83  var BlobWriteQueries = []WriteQueryTest{
    84  	{
    85  		WriteQuery:          "insert into blobt values (4, '100000000')",
    86  		ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}},
    87  		SelectQuery:         "select * from blobt where i = 4",
    88  		ExpectedSelect:      []sql.Row{{4, []byte("100000000")}},
    89  	},
    90  	{
    91  		WriteQuery:          "update blobt set b = '100000000' where i = 1",
    92  		ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}},
    93  		SelectQuery:         "select * from blobt where i = 1",
    94  		ExpectedSelect:      []sql.Row{{1, []byte("100000000")}},
    95  	},
    96  	{
    97  		WriteQuery:          "delete from blobt where i = 1",
    98  		ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}},
    99  		SelectQuery:         "select * from blobt",
   100  		ExpectedSelect: []sql.Row{
   101  			{2, []byte("second row")},
   102  			{3, []byte("third row")},
   103  		},
   104  	},
   105  	{
   106  		WriteQuery:          "alter table blobt rename column b to v, add v1 int",
   107  		ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}},
   108  		SelectQuery:         "select * from blobt",
   109  		ExpectedSelect: []sql.Row{
   110  			{1, []byte("first row"), nil},
   111  			{2, []byte("second row"), nil},
   112  			{3, []byte("third row"), nil},
   113  		},
   114  	},
   115  	{
   116  		WriteQuery:          "ALTER TABLE blobt ADD COLUMN v2 BIGINT DEFAULT (i + 2) AFTER b",
   117  		ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}},
   118  		SelectQuery:         "select * from blobt",
   119  		ExpectedSelect: []sql.Row{
   120  			{1, []byte("first row"), 3},
   121  			{2, []byte("second row"), 4},
   122  			{3, []byte("third row"), 5},
   123  		},
   124  	},
   125  	{
   126  		WriteQuery:          "insert into textt values (4, '100000000')",
   127  		ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}},
   128  		SelectQuery:         "select * from textt where i = 4",
   129  		ExpectedSelect:      []sql.Row{{4, "100000000"}},
   130  	},
   131  	{
   132  		WriteQuery:          "update textt set t = '100000000' where i = 1",
   133  		ExpectedWriteResult: []sql.Row{{newUpdateResult(1, 1)}},
   134  		SelectQuery:         "select * from textt where i = 1",
   135  		ExpectedSelect:      []sql.Row{{1, "100000000"}},
   136  	},
   137  	{
   138  		WriteQuery:          "delete from textt where i = 1",
   139  		ExpectedWriteResult: []sql.Row{{types.NewOkResult(1)}},
   140  		SelectQuery:         "select * from textt",
   141  		ExpectedSelect: []sql.Row{
   142  			{2, "second row"},
   143  			{3, "third row"},
   144  		},
   145  	},
   146  	{
   147  		WriteQuery:          "alter table textt rename column t to v, add v1 int",
   148  		ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}},
   149  		SelectQuery:         "select * from textt",
   150  		ExpectedSelect: []sql.Row{
   151  			{1, "first row", nil},
   152  			{2, "second row", nil},
   153  			{3, "third row", nil},
   154  		},
   155  	},
   156  	{
   157  		WriteQuery:          "ALTER TABLE textt ADD COLUMN v2 BIGINT DEFAULT (i + 2) AFTER t",
   158  		ExpectedWriteResult: []sql.Row{{types.NewOkResult(0)}},
   159  		SelectQuery:         "select * from textt",
   160  		ExpectedSelect: []sql.Row{
   161  			{1, "first row", 3},
   162  			{2, "second row", 4},
   163  			{3, "third row", 5},
   164  		},
   165  	},
   166  }
   167  
   168  var BlobErrors = []QueryErrorTest{
   169  	{
   170  		Query:       "alter table mytable modify s blob",
   171  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   172  	},
   173  	{
   174  		Query:       "alter table mytable modify s text",
   175  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   176  	},
   177  	{
   178  		Query:       "alter table blobt add index bidx (b)",
   179  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   180  	},
   181  	{
   182  		Query:       "alter table blobt add index tidx (i, b)",
   183  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   184  	},
   185  	{
   186  		Query:       "alter table blobt add index bidx (b(3073))",
   187  		ExpectedErr: sql.ErrKeyTooLong,
   188  	},
   189  	{
   190  		Query:       "alter table textt add index tidx (t)",
   191  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   192  	},
   193  	{
   194  		Query:       "alter table textt add index tidx (t(769))",
   195  		ExpectedErr: sql.ErrKeyTooLong,
   196  	},
   197  	{
   198  		Query:       "alter table textt add index tidx (i, t)",
   199  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   200  	},
   201  	{
   202  		Query:       "create table b (b blob primary key)",
   203  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   204  	},
   205  	{
   206  		Query:       "create table b (b tinyblob primary key)",
   207  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   208  	},
   209  	{
   210  		Query:       "create table t (t text primary key)",
   211  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   212  	},
   213  	{
   214  		Query:       "create table t (t text, primary key (t))",
   215  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   216  	},
   217  	{
   218  		Query:       "create table b (b blob, primary key (b))",
   219  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   220  	},
   221  	{
   222  		Query:       "create table b (b blob, primary key (b(3073)))",
   223  		ExpectedErr: sql.ErrKeyTooLong,
   224  	},
   225  	{
   226  		Query:       "create table t (t text, primary key (t(769)))",
   227  		ExpectedErr: sql.ErrKeyTooLong,
   228  	},
   229  	{
   230  		Query:       "create table b (i int primary key, b blob, index bidx(b))",
   231  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   232  	},
   233  	{
   234  		Query:       "create table b (i int primary key, b blob, index bidx(b(3073)))",
   235  		ExpectedErr: sql.ErrKeyTooLong,
   236  	},
   237  	{
   238  		Query:       "CREATE TABLE b (pk BIGINT PRIMARY KEY, v1 TEXT, INDEX (v1));",
   239  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   240  	},
   241  	{
   242  		Query:       "CREATE TABLE b (pk BIGINT PRIMARY KEY, v1 TINYTEXT, INDEX (v1));",
   243  		ExpectedErr: sql.ErrInvalidBlobTextKey,
   244  	},
   245  }
   246  
   247  var BlobUnsupported = []QueryTest{
   248  	{
   249  		Query: "select convert(`b` using utf8) from blobt",
   250  		Expected: []sql.Row{
   251  			{1, "first row"},
   252  			{2, "second row"},
   253  			{3, "third row"},
   254  		},
   255  	},
   256  }