int DBtable_exists(const char *table_name)
{
char *table_name_esc;
#ifdef HAVE_POSTGRESQL
char *table_schema_esc;
#endif
DB_RESULT result;
int ret;
table_name_esc = DBdyn_escape_string(table_name);
#if defined(HAVE_IBM_DB2)
/* publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.admin.cmd.doc/doc/r0001967.html */
result = DBselect(
"select 1"
" from syscat.tables"
" where tabschema=user"
" and lower(tabname)='%s'",
table_name_esc);
#elif defined(HAVE_MYSQL)
result = DBselect("show tables like '%s'", table_name_esc);
#elif defined(HAVE_ORACLE)
result = DBselect(
"select 1"
" from tab"
" where tabtype='TABLE'"
" and lower(tname)='%s'",
table_name_esc);
#elif defined(HAVE_POSTGRESQL)
table_schema_esc = DBdyn_escape_string(NULL == CONFIG_DBSCHEMA || '\0' == *CONFIG_DBSCHEMA ?
"public" : CONFIG_DBSCHEMA);
result = DBselect(
"select 1"
" from information_schema.tables"
" where table_name='%s'"
" and table_schema='%s'",
table_name_esc, table_schema_esc);
zbx_free(table_schema_esc);
#elif defined(HAVE_SQLITE3)
result = DBselect(
"select 1"
" from sqlite_master"
" where tbl_name='%s'"
" and type='table'",
table_name_esc);
#endif
zbx_free(table_name_esc);
ret = (NULL == DBfetch(result) ? FAIL : SUCCEED);
DBfree_result(result);
return ret;
}