zabbix-agent2/src/libs/zbxdb/db.c
/******************************************************************************
 *                                                                            *
 * Function: zbx_tsdb_get_version                                             *
 *                                                                            *
 * Purpose: returns TimescaleDB (TSDB) version as integer: MMmmuu             *
 *          M = major version part                                            *
 *          m = minor version part                                            *
 *          u = patch version part                                            *
 *                                                                            *
 * Example: TSDB 1.5.1 version will be returned as 10501                      *
 *                                                                            *
 * Return value: TSDB version or 0 if unknown or the extension not installed  *
 *                                                                            *
 ******************************************************************************/
zbx_tsdb_get_version

Purpose: returns TimescaleDB (TSDB) version as integer: MMmmuu
M = major version part
m = minor version part
u = patch version part

Example: TSDB 1.5.1 version will be returned as 10501

Return value: TSDB version or 0 if unknown or the extension not installed
zbx_tsdb_get_version Purpose : returns TimescaleDB ( TSDB ) version as integer : MMmmuu M = major version part m = minor version part u = patch version part Example : TSDB 1 . 5 . 1 version will be returned as 10501 Return value : TSDB version or 0 if unknown or the extension not installed
int	zbx_tsdb_get_version(void)
{
	int		ver, major, minor, patch;
	DB_RESULT	result;
	DB_ROW		row;
	if (-1 == ZBX_TSDB_VERSION)
	{
		if (90001 > ZBX_PG_SVERSION)
		{
			ver = ZBX_TSDB_VERSION = 0;
			goto out;
		}
		result = zbx_db_select("select extversion from pg_extension where extname = 'timescaledb'");
		if ((DB_RESULT)ZBX_DB_DOWN == result)
		{
			ver = 0;
			goto out;
		}
		if (NULL == result)
		{
			ver = ZBX_TSDB_VERSION = 0;
			goto out;
		}
		if (NULL != (row = zbx_db_fetch(result)) &&
				3 == sscanf((const char*)row[0], "%d.%d.%d", &major, &minor, &patch))
		{
			ver = major * 10000;
			ver += minor * 100;
			ver += patch;
			ZBX_TSDB_VERSION = ver;
		}
		else
			ver = ZBX_TSDB_VERSION = 0;
		DBfree_result(result);
	}
	else
		ver = ZBX_TSDB_VERSION;
out:
	return ver;
}
int zbx_tsdb_get_version ( void ) { int ver , major , minor , patch ; DB_RESULT result ; DB_ROW row ; if ( -1 == ZBX_TSDB_VERSION ) { if ( 90001 > ZBX_PG_SVERSION ) { ver = ZBX_TSDB_VERSION = 0 ; goto out ; } result = zbx_db_select ( " " ) ; if ( ( DB_RESULT ) ZBX_DB_DOWN == result ) { ver = 0 ; goto out ; } if ( NULL == result ) { ver = ZBX_TSDB_VERSION = 0 ; goto out ; } if ( NULL != ( row = zbx_db_fetch ( result ) ) && 3 == sscanf ( ( const char * ) row [ 0 ] , " " , & major , & minor , & patch ) ) { ver = major * 10000 ; ver += minor * 100 ; ver += patch ; ZBX_TSDB_VERSION = ver ; } else ver = ZBX_TSDB_VERSION = 0 ; DBfree_result ( result ) ; } else ver = ZBX_TSDB_VERSION ; out : return ver ; }
Function: zbx_tsdb_get_version                                             
                                                                            
 Purpose: returns TimescaleDB (TSDB) version as integer: MMmmuu             
          M = major version part                                            
          m = minor version part                                            
          u = patch version part                                            
                                                                            
 Example: TSDB 1.5.1 version will be returned as 10501                      
                                                                            
 Return value: TSDB version or 0 if unknown or the extension not installed
Function : zbx_tsdb_get_version Purpose : returns TimescaleDB ( TSDB ) version as integer : MMmmuu M = major version part m = minor version part u = patch version part Example : TSDB 1 . 5 . 1 version will be returned as 10501 Return value : TSDB version or 0 if unknown or the extension not installed
/* catalog pg_extension not available */ /* database down, can re-query in the next call */ /* extension is not installed */