"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/libs/zbxdbupgrade/dbupgrade_macros.c" between
zabbix-5.4.2.tar.gz and zabbix-5.4.3.tar.gz

About: ZABBIX is an enterprise-class distributed monitoring solution for servers and applications.

dbupgrade_macros.c  (zabbix-5.4.2):dbupgrade_macros.c  (zabbix-5.4.3)
skipping to change at line 24 skipping to change at line 24
** **
** You should have received a copy of the GNU General Public License ** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software ** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US A. ** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, US A.
**/ **/
#include "common.h" #include "common.h"
#include "db.h" #include "db.h"
#include "dbupgrade.h" #include "dbupgrade.h"
#include "dbupgrade_macros.h" #include "dbupgrade_macros.h"
#include "log.h"
/****************************************************************************** /******************************************************************************
* * * *
* Function: str_rename_macro * * Function: str_rename_macro *
* * * *
* Purpose: rename macros in the string * * Purpose: rename macros in the string *
* * * *
* Parameters: in - [IN] the input string * * Parameters: in - [IN] the input string *
* oldmacro - [IN] the macro to rename * * oldmacro - [IN] the macro to rename *
* newmacro - [IN] the new macro name * * newmacro - [IN] the new macro name *
skipping to change at line 101 skipping to change at line 102
* fields - [IN] the table fields to check for macros and * * fields - [IN] the table fields to check for macros and *
* rename if found * * rename if found *
* fields_num - [IN] the number of fields to check * * fields_num - [IN] the number of fields to check *
* oldmacro - [IN] the macro to rename * * oldmacro - [IN] the macro to rename *
* newmacro - [IN] the new macro name * * newmacro - [IN] the new macro name *
* * * *
* Return value: SUCCEED - macros were renamed successfully * * Return value: SUCCEED - macros were renamed successfully *
* FAIL - database error occurred * * FAIL - database error occurred *
* * * *
******************************************************************************/ ******************************************************************************/
int db_rename_macro(DB_RESULT result, const char *table, const char *pkey, co nst char **fields, int fields_num, int db_rename_macro(DB_RESULT result, const char *table, const char *pkey, zb x_field_len_t *fields, int fields_num,
const char *oldmacro, const char *newmacro) const char *oldmacro, const char *newmacro)
{ {
DB_ROW row; DB_ROW row;
char *sql = 0, *field = NULL, *field_esc; char *sql = 0, *value = NULL, *value_esc;
size_t sql_alloc = 4096, sql_offset = 0, field_alloc = 0, old_of fset; size_t sql_alloc = 4096, sql_offset = 0, field_alloc = 0, old_of fset;
int i, ret = SUCCEED; int i, ret = SUCCEED;
zbx_field_len_t *field;
sql = zbx_malloc(NULL, sql_alloc); sql = zbx_malloc(NULL, sql_alloc);
DBbegin_multiple_update(&sql, &sql_alloc, &sql_offset); DBbegin_multiple_update(&sql, &sql_alloc, &sql_offset);
while (NULL != (row = DBfetch(result))) while (NULL != (row = DBfetch(result)))
{ {
old_offset = sql_offset; old_offset = sql_offset;
for (i = 0; i < fields_num; i++) for (i = 0; i < fields_num; i++)
{ {
if (SUCCEED == str_rename_macro(row[i + 1], oldmacro, new field = fields + i;
macro, &field, &field_alloc))
if (SUCCEED == str_rename_macro(row[i + 1], oldmacro, new
macro, &value, &field_alloc))
{ {
if (0 != field->max_len && zbx_strlen_utf8(value)
> field->max_len)
{
zabbix_log(LOG_LEVEL_WARNING, "cannot ren
ame macros in table \"%s\" row "
"\"%s:%s\" field \"%s\":
value is too long",
table, pkey, row[0], fiel
d->field_name);
continue;
}
value_esc = DBdyn_escape_string(value);
if (old_offset == sql_offset) if (old_offset == sql_offset)
zbx_snprintf_alloc(&sql, &sql_alloc, &sql _offset, "update %s set ", table); zbx_snprintf_alloc(&sql, &sql_alloc, &sql _offset, "update %s set ", table);
else else
zbx_chrcpy_alloc(&sql, &sql_alloc, &sql_o ffset, ','); zbx_chrcpy_alloc(&sql, &sql_alloc, &sql_o ffset, ',');
field_esc = DBdyn_escape_string(field); zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset,
zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, "%s='%s'", fields[i].field_name,
"%s='%s'", fields[i], field_esc); value_esc);
zbx_free(field_esc);
zbx_free(value_esc);
} }
} }
if (old_offset != sql_offset) if (old_offset != sql_offset)
{ {
zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " where %s=%s;\n", pkey, row[0]); zbx_snprintf_alloc(&sql, &sql_alloc, &sql_offset, " where %s=%s;\n", pkey, row[0]);
if (SUCCEED != (ret = DBexecute_overflowed_sql(&sql, &sql _alloc, &sql_offset))) if (SUCCEED != (ret = DBexecute_overflowed_sql(&sql, &sql _alloc, &sql_offset)))
goto out; goto out;
} }
} }
DBend_multiple_update(&sql, &sql_alloc, &sql_offset); DBend_multiple_update(&sql, &sql_alloc, &sql_offset);
if (16 < sql_offset && ZBX_DB_OK > DBexecute("%s", sql)) if (16 < sql_offset && ZBX_DB_OK > DBexecute("%s", sql))
ret = FAIL; ret = FAIL;
out: out:
zbx_free(field); zbx_free(value);
zbx_free(sql); zbx_free(sql);
return ret; return ret;
} }
 End of changes. 8 change blocks. 
9 lines changed or deleted 28 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)