[MDEV-29782] Cannot insert value into a column of type YEAR in a CONNECTed MariaDB table Created: 2022-10-12  Updated: 2023-04-18  Resolved: 2023-04-18

Status: Closed
Project: MariaDB Server
Component/s: Storage Engine - Connect
Affects Version/s: 10.3, 10.4, 10.9.3, 10.5, 10.6, 10.7, 10.8, 10.9
Fix Version/s: 10.4.29

Type: Bug Priority: Minor
Reporter: Gisbert W. Selke Assignee: Andrew Hutchings
Resolution: Fixed Votes: 0
Labels: None
Environment:

Windows 10. Problem occurs both with local installation and with server installation (Windows Server).



 Description   

I have a CONNECT to a MariaDB server table which contains a column of type YEAR.
Trying to insert a value into this column always fails. (I have had no problem at all inserting values into other data types that I tried.)

Minimal example using a locally installed MariaDB 10.9.3 server: (Problem came up originally when CONNECTing to a MySQL 5.7.x server – same effect.)

USE test;
CREATE TABLE t0 (jahr year(4) not null);
CREATE TABLE t0_conn ENGINE=CONNECT CONNECTION='mysql://USERNAME:PASSWORD@localhost/test/t0' `TABLE_TYPE`='MYSQL';
INSERT INTO t0 VALUES (2022); -- inserting into underlying table directly works OK
SELECT * FROM t0_conn; -- works OK, shows inserted value 2022
INSERT INTO t0_conn VALUES (2023);
-- fails with error message:
ERROR 1296 (HY000): Got error 122 '(1265) Data truncated for column 'jahr' at row 1 [INSERT INTO `t0` (`jahr`) VALUES ('2023-01-01 00:00:00')]' from CONNECT

It seems that the CONNECT engine over-eagerly converts the value-to-insert from its simple form (2022) into datetime form before sending it over the CONNECTion.
On the receiving end, trying to insert a datetime value into a year field fails. (This latter is expected: trying to insert a datetime directly into the underlying table t0 will also fail, and correctly so.)

Thus, the problem seems to be the over-eager data type conversion performed by the CONNECT engine.



 Comments   
Comment by Alice Sherepa [ 2022-10-13 ]

Thank you for the report!
I repeated as described on 10.3-10.9:

INSTALL SONAME 'ha_connect';
CREATE TABLE t (id year);
CREATE TABLE t_con ENGINE=connect  CONNECTION='mysql://root@localhost/test/t' `TABLE_TYPE`='MYSQL';
insert into t_con values (1999);

mysqltest: At line 8: query 'insert into t_con values (1999)' failed: ER_GET_ERRMSG (1296): Got error 122 '(1265) Data truncated for column 'id' at row 1 [INSERT INTO `t` (`id`) VALUES ('1999-01-01 00:00:00')]' from CONNECT

Comment by Andrew Hutchings [ 2023-02-14 ]

Rebased off 10.4 as 10.3 is too close to EoL.

Generated at Thu Feb 08 10:11:15 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.