Skip to content
Snippets Groups Projects
  • George Joseph's avatar
    3b3d0688
    res_config_mysql: Fix several issues related to recent table changes · 3b3d0688
    George Joseph authored
    Unlike any of the other database drivers, res_config_mysql checks that
    the table definition matches the requirements for every insert and
    update statement.  Since all requirements are forced to 'char', any
    column that isn't a char, like ps_contacts' expiration_time,
    qualify_timeout, etc., will throw a warning.  It's kinda harmless but
    very misleading.  Since no other driver does those checks on insert
    or update, they've been removed from res_config_mysql.  Also, all
    the logic that actually attempted to ALTER the table to fix the issue
    has been removed.  With the move to alembic, the auto-alter
    functionality is not only unnecessary, it's also dangerous.
    
    The other issue is that res_config_mysql calls the mysql_insert_id
    function inside store_mysql.  Presumably the intention was to return
    the number of rows inserted DESPITE A NOTE IN THE CODE THAT THE VALUE
    IS NON_PORTABLE AND MAY CHANGE.  That value is then returned to
    config realtime as the number of rows inserted.  Guess what?  The value
    changed.  It now only returns the number of rows inserted if there's an
    auto increment column on the table, which ps_contacts doesn't have.
    Otherwise it returns 0.  So now, the insert worked but we tell config
    realtime and sorcery that no rows were inserted.  That call to
    mysql_insert_id was removed and we now always return 1 if the insert
    succeeded.  We're only inserting 1 row at a time anyway.  If the insert
    fails, we still return -1.
    
    ASTERISK-26362 #close
    Reported-by: Carlos Chavez
    
    Change-Id: I83ce633efdb477b03c8399946994ee16fefceaf4
    3b3d0688
    History
    res_config_mysql: Fix several issues related to recent table changes
    George Joseph authored
    Unlike any of the other database drivers, res_config_mysql checks that
    the table definition matches the requirements for every insert and
    update statement.  Since all requirements are forced to 'char', any
    column that isn't a char, like ps_contacts' expiration_time,
    qualify_timeout, etc., will throw a warning.  It's kinda harmless but
    very misleading.  Since no other driver does those checks on insert
    or update, they've been removed from res_config_mysql.  Also, all
    the logic that actually attempted to ALTER the table to fix the issue
    has been removed.  With the move to alembic, the auto-alter
    functionality is not only unnecessary, it's also dangerous.
    
    The other issue is that res_config_mysql calls the mysql_insert_id
    function inside store_mysql.  Presumably the intention was to return
    the number of rows inserted DESPITE A NOTE IN THE CODE THAT THE VALUE
    IS NON_PORTABLE AND MAY CHANGE.  That value is then returned to
    config realtime as the number of rows inserted.  Guess what?  The value
    changed.  It now only returns the number of rows inserted if there's an
    auto increment column on the table, which ps_contacts doesn't have.
    Otherwise it returns 0.  So now, the insert worked but we tell config
    realtime and sorcery that no rows were inserted.  That call to
    mysql_insert_id was removed and we now always return 1 if the insert
    succeeded.  We're only inserting 1 row at a time anyway.  If the insert
    fails, we still return -1.
    
    ASTERISK-26362 #close
    Reported-by: Carlos Chavez
    
    Change-Id: I83ce633efdb477b03c8399946994ee16fefceaf4
res_config_mysql.c 51.78 KiB