std::string UpdateSpec::selectquery(const std::string& tablename) const { std::ostringstream out; out << "select " << columnlist() << " from " << tablename << " where id = ?"; std::string query = out.str(); debug(LOG_DEBUG, DEBUG_LOG, 0, "select query: %s", query.c_str()); return query; }
std::string UpdateSpec::insertquery(const std::string& tablename) const { std::ostringstream out; out << "insert into " << tablename << "("; out << columnlist() << ", id) values ("; out << values() << ", ?)"; std::string query = out.str(); debug(LOG_DEBUG, DEBUG_LOG, 0, "insert query: %s", query.c_str()); return query; }
void generate_critpage(FILE *output, char *hfprefix) { RbtIterator hhandle; int color = COL_GREEN; int maxprio = 0; /* Determine background color and max. priority */ for (hhandle = rbtBegin(rbstate); (hhandle != rbtEnd(rbstate)); hhandle = rbtNext(rbstate, hhandle)) { void *k1, *k2; hstatus_t *itm; rbtKeyValue(rbstate, hhandle, &k1, &k2); itm = (hstatus_t *)k2; if (itm->color > color) color = itm->color; if (itm->config->priority > maxprio) maxprio = itm->config->priority; } headfoot(output, hfprefix, "", "header", color); fprintf(output, "<center>\n"); if (color != COL_GREEN) { RbtHandle rbcolumns; int prio; rbcolumns = columnlist(rbstate); fprintf(output, "<TABLE BORDER=0 CELLPADDING=4 SUMMARY=\"Critical status display\">\n"); print_colheaders(output, rbcolumns); for (prio = 1; (prio <= maxprio); prio++) { print_oneprio(output, rbstate, rbcolumns, prio); } fprintf(output, "</TABLE>\n"); rbtDelete(rbcolumns); } else { /* "All Monitored Systems OK */ fprintf(output, "%s", xgetenv("XYMONALLOKTEXT")); } fprintf(output, "</center>\n"); headfoot(output, hfprefix, "", "footer", color); }
void generate_critpage(void * statetree, void * hoptree, FILE *output, char *header, char *footer, int color, int maxprio) { xtreePos_t hhandle; headfoot(output, header, "", "header", pagecolor); /* Use PAGE color here, not the part color */ fprintf(output, "<center>\n"); if (color != COL_GREEN) { void * rbcolumns; int prio; rbcolumns = columnlist(statetree); fprintf(output, "<TABLE BORDER=0 CELLPADDING=4 SUMMARY=\"Critical status display\">\n"); print_colheaders(output, rbcolumns); for (prio = 1; (prio <= maxprio); prio++) { print_oneprio(output, statetree, hoptree, rbcolumns, prio); } fprintf(output, "</TABLE>\n"); xtreeDestroy(rbcolumns); } else { /* "All Monitored Systems OK */ fprintf(output, "%s", xgetenv("XYMONALLOKTEXT")); } if (evcount > 0) { /* Include the eventlog */ evhopfilter = hoptree; do_eventlog(output, evcount, maxage/60, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, ev_included, NULL, NULL, NULL, XYMON_COUNT_NONE, XYMON_S_NONE, NULL); fprintf(output, "<br><br><br>\n"); } fprintf(output, "</center>\n"); headfoot(output, footer, "", "footer", color); }
void SqlCompiler::genInsertValues(const SyntaxNode *n, // n == insert_stmt StatementTable &table) { NodeList columnlist((n->child(1)->childCount() == 0) ? NULL : n->child(1)->child(0)); SyntaxNode *insertwhat = n->child(2); // == VALUES NodeList exprlist(insertwhat->child(0)); Array<InsertColumnExpression> icemap; if(columnlist.size() == 0) { // no columnnames specified. use all columns of tabledefinition if(exprlist.size() != table.getColumnCount()) { syntaxError(insertwhat,SQL_INVALID_EXPRLIST,_T("Invalid number of expressions specified")); return; } for(UINT i = 0; i < table.getColumnCount(); i++) icemap.add(InsertColumnExpression(table,i,exprlist[i])); } else { // columnnames specified if(columnlist.size() != exprlist.size()) { syntaxError(insertwhat,SQL_INVALID_EXPRLIST,_T("Invalid number of expressions specified")); return; } for(UINT i = 0; i < columnlist.size(); i++) { const TCHAR *name = columnlist[i]->name(); int colindex = table.findColumnIndex(name); if(colindex < 0) syntaxError(columnlist[i],SQL_INVALID_COLUMNNAME,_T("Invalid columnname:<%s>"),name); else { bool found = false; for(UINT j = 0; j < icemap.size(); j++) { // check not already spec if(icemap[j].m_colIndex == colindex) { syntaxError(columnlist[i],SQL_COLUMN_ALREADY_DEFINED,_T("Column <%s> already specified"),name); found = true; break; } } if(!found) icemap.add(InsertColumnExpression(table,colindex,exprlist[i])); } } if(columnlist.size() > table.getColumnCount()) syntaxError(insertwhat,SQL_TOO_MANY_COLUMNS,_T("Too many columns specified")); else { if(columnlist.size() < table.getColumnCount()) // check, that unspecified columns have nulls-allowed or defaultvalue for(UINT i = 0; i < table.getColumnCount(); i++) { bool found = false; for(UINT j = 0; j < icemap.size(); j++) { if(icemap[j].m_colIndex == i) { found = true; break; } } if(!found) { // unspecified column SyntaxNode *defaultvalue = fetchDefaultValueNode(table.getColumn(i)); if(defaultvalue == NULL) syntaxError(n->child(0),SQL_NODEFAULT_OR_NULLALLOWED,_T("Column <%s> has no default-value or null-allowed"),table.getColumn(i).m_name.cstr()); else icemap.add(InsertColumnExpression(table,i,defaultvalue)); } } } } if(ok()) { // icemap.size == tableDef.colcount. i.e all columns has an expression int hostvarcounter = 0; for(UINT i = 0; i < icemap.size(); i++) { findHostVarIndex(icemap[i].m_expr,hostvarcounter); } } if(ok()) { for(UINT i = 0; i < icemap.size(); i++) checkExpressionType(icemap[i]); } if(ok()) { m_code.appendIns2(CODETUPINIT,0,table.getColumnCount()); for(UINT i = 0; i < icemap.size(); i++) { bool dummy; genExpression(reduceExpression(icemap[i].m_expr,dummy)); m_code.appendIns2(CODEPOPTUP,0,icemap[i].m_colIndex); } m_code.appendIns0(CODETRBEGIN); m_code.appendIns1(CODEPUSHCONST,m_code.appendConst(table.getSequenceNo())); m_code.appendIns1(CODETUPINSERT,0); m_code.appendIns0(CODETRCOMMIT); } #ifdef TRACECOMP m_code.dump(); #endif // if(ok()) { // FILE *dmp = FOPEN(_T("fisk"),_T("w")); // for(int i = 0; i < icemap.size(); i++) // icemap[i].dump(dmp); // m_code.dump(dmp); // fclose(dmp); // } }