[Devel] unixodbc bugs

Alex Gradinar Alex.Gradinar at cartel.md
Tue Feb 28 16:13:13 CET 2006


1. function convert_rows in file res.c
while allocationg memery to columns of row in this code

==========
      CON_ROW(_h) = (strn*)pkg_malloc((int)columns);
==========
allocate only amount of bytes as number of columns,
but we have to allocate number of columns * sizeof struct strn
This is correct code
==========
      CON_ROW(_h) = (strn*)pkg_malloc((int)columns*sizeof(strn));
==========
2. function convert_rows in file res.c
while getting data from odbc in this code
==========
ret = SQLGetData(CON_RESULT(_h), i, SQL_C_CHAR,
        (CON_ROW(_h)[i-1]).s, 1024, &indicator);

==========
write 1024 bytes, but if we chage size of variable 's' in struct strn
we have to keep in mind that this number of bytes we have to change too.
This is correct code
==========
ret = SQLGetData(CON_RESULT(_h), i, SQL_C_CHAR,
        (CON_ROW(_h)[i-1]).s, sizeof((CON_ROW(_h)[i-1]).s), &indicator);

==========
3. function submit_query in dbase.c
in this code
==========
        if(CON_RESULT(_h))
        {
                ret = SQLFreeStmt(&CON_RESULT(_h), SQL_CLOSE);
                if (!SQL_SUCCEEDED(ret))
                {
                        LOG(L_ERR, "Statement allocation error %d\n",
                                (int)(long)CON_CONNECTION(_h));
                        extract_error("SQLAllocStmt", CON_CONNECTION(_h), 
SQL_HANDLE_DBC);
                        return ret;
                }
        }

==========
3.1. call the function SQLFreeStmt, but error about allocation

3.2. with my odbc driver (OpenLink) SQLFreeStmt returned Error
I recomend to change this code to
==========
        if(CON_RESULT(_h))
        {
            SQLFreeStmt(&CON_RESULT(_h), SQL_RESET_PARAMS);
            SQLFreeStmt(&CON_RESULT(_h), SQL_UNBIND);
            SQLFreeStmt(&CON_RESULT(_h), SQL_CLOSE);
            SQLFreeStmt(&CON_RESULT(_h), SQL_DROP)
        }
==========




More information about the Devel mailing list