[ODBC-323] Selects wrong unique index when accessing table data from MSAccess Created: 2021-06-15  Updated: 2022-09-26  Resolved: 2022-09-26

Status: Closed
Project: MariaDB Connector/ODBC
Component/s: General
Affects Version/s: 3.1.11
Fix Version/s: 3.1.16

Type: Bug Priority: Major
Reporter: Walter van der Geest Assignee: Lawrin Novitsky
Resolution: Duplicate Votes: 0
Labels: None
Environment:

Windows 10, MariaDB Server 10.5



 Description   

When linking from MSAccess to a table on MariaDB which has a primary key and a second unique key on a field which allows NULL values, the key with the alphabetically lower name is selected. This results into wrong displayed records in MSAccess table view.

Details:
While linking to a table on MariaDB, the ODBC queries MariaDB for possible unique key candidates with the statement

SELECT TABLE_SCHEMA AS TABLE_CAT, NULL AS TABLE_SCHEM, TABLE_NAME, NON_UNIQUE, NULL AS INDEX_QUALIFIER, INDEX_NAME, 3 AS TYPE, SEQ_IN_INDEX AS ORDINAL_POSITION, COLUMN_NAME, COLLATION AS ASC_OR_DESC, CARDINALITY, NULL AS PAGES, NULL AS FILTER_CONDITION FROM INFORMATION_SCHEMA.STATISTICS WHERE TABLE_SCHEMA LIKE IF(DATABASE() IS NOT NULL, DATABASE(), '%') AND TABLE_NAME LIKE 'mytab' ORDER BY NON_UNIQUE, INDEX_NAME, ORDINAL_POSITION}}

It WANTS to have an absolute unique field name in order to retrieve the correct record, but it does not consider that UNIQUE Indexes in MariaDB can contain NULL values (multiple times), only the NON-NULL values have to be unique.
When it happens that the name of the unique key starts with a term lesser than 'PRIMARY KEY', this key is selected thus requesting all records with this key field in the condition.

This results in e.g. MSAccess table view to multiple Queries like 'SELECT * FROM myTab WHERE a_unique_id IS NULL', which returns more than one row, but only the first is displayed.

So, has a table this format and entries:

CREATE TABLE mytab (
  mytab_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  text_1 VARCHAR(100) NOT NULL,
  a_unique_id VARCHAR(20) NULL UNIQUE KEY
);
 
INSERT INTO mytab (text_1, a_unique_id) VALUES 
  ('first entry', '1st'),
  ('second entry', '2nd'),
  ('third entry', NULL),
  ('fourth entry', NULL);

In Access the table view shows the records:

  • third entry
  • third entry
  • first entry
  • second entry


 Comments   
Comment by Walter van der Geest [ 2022-09-24 ]

Same as ODBC-361

Comment by Lawrin Novitsky [ 2022-09-26 ]

Thank you for the high quality report, and sorry - I'd got it off my radar, it could save some time on problem investigation. I am closing this issue as a duplicate, since you do not say that the problem is still present.

Generated at Thu Feb 08 03:27:52 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.