Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cf-agent/cf_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void CfCloseDB(CfdbConn *cfdb)

/*****************************************************************************/

void CfVoidQueryDB(CfdbConn *cfdb, char *query)
void CfVoidQueryDB(CfdbConn *cfdb, const char *query)
{
if (!cfdb->connected)
{
Expand All @@ -398,7 +398,7 @@ void CfVoidQueryDB(CfdbConn *cfdb, char *query)

/*****************************************************************************/

void CfNewQueryDB(CfdbConn *cfdb, char *query)
void CfNewQueryDB(CfdbConn *cfdb, const char *query)
{
cfdb->result = false;
cfdb->row = 0;
Expand Down
4 changes: 2 additions & 2 deletions cf-agent/cf_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ typedef struct

void CfConnectDB(CfdbConn *cfdb, DatabaseType dbtype, char *remotehost, char *dbuser, char *passwd, char *db);
void CfCloseDB(CfdbConn *cfdb);
void CfVoidQueryDB(CfdbConn *cfdb, char *query);
void CfNewQueryDB(CfdbConn *cfdb, char *query);
void CfVoidQueryDB(CfdbConn *cfdb, const char *query);
void CfNewQueryDB(CfdbConn *cfdb, const char *query);
char **CfFetchRow(CfdbConn *cfdb);
char *CfFetchColumn(CfdbConn *cfdb, int col);
void CfDeleteQuery(CfdbConn *cfdb);
Expand Down
50 changes: 26 additions & 24 deletions cf-agent/verify_databases.c
Original file line number Diff line number Diff line change
Expand Up @@ -743,48 +743,50 @@ static int TableExists(CfdbConn *cfdb, char *name)

static bool CreateTableColumns(CfdbConn *cfdb, char *table, Rlist *columns)
{
char entry[CF_MAXVARSIZE], query[CF_BUFSIZE];
int i, *size_table, *done;
char **name_table, **type_table;
int no_of_cols = RlistLen(columns);

Log(LOG_LEVEL_ERR, "Trying to create table '%s'", table);
Log(LOG_LEVEL_VERBOSE, "Trying to create table '%s'", table);

if (!NewSQLColumns(table, columns, &name_table, &type_table, &size_table, &done))
{
return false;
}

if (no_of_cols > 0)
if (no_of_cols <= 0)
{
snprintf(query, CF_BUFSIZE - 1, "create table %s(", table);

for (i = 0; i < no_of_cols; i++)
{
Log(LOG_LEVEL_VERBOSE, "Forming column template %s %s %d", name_table[i], type_table[i],
size_table[i]);;
Log(LOG_LEVEL_ERR, "Attempted to create table '%s' without any columns", table);
return false;
}

if (size_table[i] > 0)
{
snprintf(entry, CF_MAXVARSIZE - 1, "%s %s(%d)", name_table[i], type_table[i], size_table[i]);
}
else
{
snprintf(entry, CF_MAXVARSIZE - 1, "%s %s", name_table[i], type_table[i]);
}
Buffer *query = BufferNew();
BufferPrintf(query, "create table %s(", table);

strcat(query, entry);
for (i = 0; i < no_of_cols; i++)
{
Log(LOG_LEVEL_VERBOSE, "Forming column template %s %s %d", name_table[i], type_table[i],
size_table[i]);;

if (i < no_of_cols - 1)
{
strcat(query, ",");
}
if (size_table[i] > 0)
{
BufferAppendF(query, "%s %s(%d)", name_table[i], type_table[i], size_table[i]);
}
else
{
BufferAppendF(query, "%s %s", name_table[i], type_table[i]);
}

strcat(query, ")");
if (i < no_of_cols - 1)
{
BufferAppendChar(query, ',');
}
}

CfVoidQueryDB(cfdb, query);
BufferAppendChar(query, ')');

CfVoidQueryDB(cfdb, BufferData(query));
BufferDestroy(query);
DeleteSQLColumns(name_table, type_table, size_table, done, no_of_cols);
return true;
}
Expand Down
Loading