[ODBC-356] Unsused variable leads to unnecessary if condition in ma_string.c (and possibly bugs) Created: 2022-03-16  Updated: 2022-04-25  Resolved: 2022-04-25

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

Type: Bug Priority: Major
Reporter: Robert Pellmann Assignee: Lawrin Novitsky
Resolution: Fixed Votes: 0
Labels: None

Attachments: Text File ma_string.c    

 Description   

In the file https://github.com/mariadb-corporation/mariadb-connector-odbc/blob/master/ma_string.c there a two lines who contradict each other:
On https://github.com/mariadb-corporation/mariadb-connector-odbc/blob/852f63465b03045dba73cc36fc5710aea0f55b5c/ma_string.c#L213 the int variable Flag is created with an initial value of 0 and in https://github.com/mariadb-corporation/mariadb-connector-odbc/blob/852f63465b03045dba73cc36fc5710aea0f55b5c/ma_string.c#L257 the condition is true if the Flag value is 0, which is always the case, since the Flag value never changes after initialization.

As far as i can tell the value of flag should depend on the values of PrimaryCount and/or UniqueCount, to avoid to compare all columns and not just the primary key/unique columns.

A quick fix is to set the value of Flag prior to the for loop (line 262):

...
if(PrimaryCount)
{
    Flag = PRI_KEY_FLAG;
}
else if(UniqueCount) 
{
    Flag = UNIQUE_KEY_FLAG;
}
for (i= 0; i < MADB_STMT_COLUMN_COUNT(Stmt); i++)
{
...

I have attached a "corrected" version of ma_string.c for comparison.



 Comments   
Comment by Lawrin Novitsky [ 2022-03-22 ]

Thank you for your report. I suspect that was at some deliberately left like this. But it's apparently the time to fix it

Comment by Lawrin Novitsky [ 2022-03-23 ]

Exactly as I remembered - some tests are failing. So, it's not just this.

Comment by Lawrin Novitsky [ 2022-04-25 ]

Fixed support of unique indexes for positioned operations

The report is talking only about code creating WHERE clause, but that was not enough to make it work. Some optimizations ere done along the way to reduce number of calls to collect required metadata. Index information is also preserved for that purpose(reducing number of queries to collect metadata).

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