void interpret ( int argc, char* argv[] ) { init_with_options (argc, argv); //test_rec_write("test"); char token[30]; while (!feof(in_s)) { fscanf (in_s, "%s", token); put_msg (DEBUG, "current token is \"%s\".\n", token); if (strcmp(token, t_quit) == 0) { quit(); break;} if (token[0] == '#') { skip_line (); continue; } if (strcmp(token, t_help) == 0) { show_help_info (); continue; } if (strcmp(token, t_database) == 0) { set_database(); continue; } if (strcmp(token, t_show) == 0) { show_database(); continue; } if (strcmp(token, t_print) == 0) { print_str(); continue; } if (strcmp(token, t_create) == 0) { create_tbl(); continue; } if (strcmp(token, t_drop) == 0) { drop_tbl(); continue; } if (strcmp(token, t_insert) == 0) { insert_row(); continue; } if (strcmp(token, t_select) == 0) { select_rows(); continue; } syntax_error (token); } }
bool latency::save_latency(void *payload) { int index = 0; int latency = 0; ostringstream ss_col; ostringstream ss_val; ostringstream tablename; if((m_data = (TENSION_DATA *)payload) == NULL) return false; tablename << m_xtablename << "_" << m_data->hostname; m_data->pings = 1; do { latency = ((TENSION_DATA *)m_data)->records[index].latency; if(latency > 0) { ss_val << ", " << (int)latency; ss_col << ", Ping" << m_data->pings; m_data->pings++; if(m_data->pings > 5) break; } index++; } while(index < (TENSION_COUNT_MAX-1)); if(m_data->pings < m_min_count) m_data->alarm = true; int lostpercent = ((((m_data->pings-1)*1.0)/(m_data->count*1.0)) * 100.0); m_stream.str(""); m_stream << "INSERT INTO " << tablename.str() // with table per device << " (EpochTime, DeviceID, LossPercent" << ss_col.str() << ") " << "VALUES (" << " " << (unsigned long)m_data->epochtime << ", " << m_data->deviceid << ", " << lostpercent << ss_val.str() << " )"; //save_file(); if(connection(m_xhost, m_xusername, m_xpassword, m_xdbname) == false) return false; if(insert((char *)m_stream.str().c_str()) == true) return true; // so if 1st insert fails create table for future use create_tbl(tablename.str()); // TODO: if fail save data to file close(); return false; }
void ping_store::rpc_run() { const char* path = global::get_instance().get_path(); dbpath_.format("%s/ping_store_%ld.db", path, time(NULL)); acl::db_sqlite db(dbpath_.c_str()); if (db.open() == false) logger_error("open db: %s failed", dbpath_.c_str()); else if (create_tbl(db) == false) logger_error("create table failed for %s", dbpath_.c_str()); else { logger("open db(%s) ok", dbpath_.c_str()); insert_tbl(db); } }
record::record(){ //QString createsql = "CREATE TABLE IF NOT EXISTS Filelist(Name text,Path text);"; //connect_db(); create_tbl(); }