/** * Creates a new ipfixDbReader. Do not forget to call @c startipfixDbReader() to begin reading from Database * @return handle to use when calling @c destroyipfixDbRreader() */ IpfixDbReader::IpfixDbReader(const string& hostname, const string& dbname, const string& username, const string& password, unsigned port, uint16_t observationDomainId, bool timeshift, bool fullspeed) : timeshift(timeshift), fullspeed(fullspeed), thread(readFromDB) { srcId.reset(new IpfixRecord::SourceID); srcId->observationDomainId = observationDomainId; srcId->exporterAddress.len = 0; srcId->exporterPort = 0; srcId->receiverPort = 0; srcId->protocol = 0; srcId->fileDescriptor = 0; if (connectToDb(hostname, dbname, username, password, port)) { THROWEXCEPTION("IpfixDbReader creation failed"); } /** get tables of the database*/ if(getTables() != 0) { msg(MSG_ERROR,"IpfixDbReader: Error in function getTables"); THROWEXCEPTION("IpfixDbReader creation failed"); } if(fullspeed && timeshift) msg(MSG_DIALOG, "IpfixDbReader: timeshift configured, but disabled in fullspeed mode"); }
int main(int argc, char* argv[]){ char ch; int next_option; const char *const short_options = "abvh:u:p:d:t:P:"; do{ next_option = getopt_long( argc, argv, short_options, long_options,NULL ); switch( next_option ) { case 'v': printUsage(); break; case 'h': host = optarg; break; case 'u': user = optarg; break; case 'p': pwd = optarg; break; case 't': table = optarg; break; case 'd': db = optarg; break; case 'P': package = optarg; break; case 'a': printUsage(); break; case 'b': hasAnotation = 1; break; case -1: break; default: break; } }while(next_option != -1); fixArgv(); getConection(host,user,pwd,db,3306); int len; char** tables = getTables(&len); int i =0; for(;i< len;i++){ work(tables[i],hasAnotation); } return 0; return 0; }
int main(int argc, char *argv[]) /* Check args and call reviewIndexes. */ { if (argc != 2) usage(); database = argv[1]; tableList = getTables(); addRowcount(); slSort(&tableList, tableCmp); reviewIndexes(); return 0; }
bool reloadTables() { bool success = true; Logger::notice(LogFacility::Script) << "Loading data and scripts ..." << Log::end; for (auto &table : getTables()) { success = success && table->reloadBuffer(); if (!success) { break; } } return success; }
void SelectStatement::addTable(const wxString& name, const wxString& joinType, const wxString& joinList) { if (joinType == "CARTESIAN") { std::vector<wxString> s; getTables(s); if (s.empty()) add(name + " ", posFromM + 5); // 5 = strlen("FROM "); else add(name + ", ", posFromM + 5); // 5 = strlen("FROM "); } else { add(joinType + " " + name + " ON " + joinList + " ", posFromEndM); } }
void NaiveCount::recompute() { // Reset the counter mCount = 0; // Get fresh iterators. std::vector<TrieIterator::Ptr> iters; for (const auto &kvp : getTables()) { const auto &tbl = std::get<1>(kvp); iters.emplace_back(tbl->scan()); } // Build a Join query from them. TrieIterator::Ptr query(new LeapFrogTrieJoin(getWidth(), move(iters))); // Count them TrieIterator::countingScan(query, mCount, getWidth()); #ifdef DEBUG std::cout << "|J| = " << mCount << std::endl; #endif }
void activateTables() { for (auto &table : getTables()) { table->activateBuffer(); } }
void reloadScripts() { for (auto &table : getTables()) { table->reloadScripts(); } }
/** * Creates a new ipfixDbReader. Do not forget to call @c startipfixDbReader() to begin reading from Database * @return handle to use when calling @c destroyipfixDbRreader() */ IpfixDbReader* createIpfixDbReader(const char* hostName, const char* dbName, const char* userName, const char* password, unsigned int port, uint16_t observationDomainId) { IpfixDbReader* ipfixDbReader = (IpfixDbReader*)malloc(sizeof(IpfixDbReader)); if (!ipfixDbReader) { msg(MSG_ERROR, "Could not allocate IpfixDbReader"); goto out0; } if (pthread_mutex_init(&ipfixDbReader->mutex, NULL)) { msg(MSG_FATAL, "Could not init mutex"); goto out1; } if (pthread_mutex_lock(&ipfixDbReader->mutex)) { msg(MSG_FATAL, "Could not lock mutex"); goto out1; } DbReader* dbReader = (DbReader*)malloc(sizeof(DbReader)); if (!ipfixDbReader) { msg(MSG_ERROR, "Could not allocate DbReader"); goto out1; } DbData* dbData = (DbData*)malloc(sizeof(DbData)); if (!dbData) { msg(MSG_ERROR, "Could not allocate dbData"); goto out2; } ipfixDbReader->dbReader = dbReader; dbReader->dbData = dbData; if (connectToDb(ipfixDbReader, hostName, dbName, userName, password, port, observationDomainId)) { goto out3; } msg(MSG_DEBUG,"Connected to database"); /** use database with db_name**/ if(mysql_select_db(ipfixDbReader->conn, ipfixDbReader->dbName) !=0) { msg(MSG_FATAL,"Database %s not selectable", ipfixDbReader->dbName); goto out3; } else { msg(MSG_DEBUG,"Database %s selected", ipfixDbReader->dbName); } /** get tableNames of the database*/ if(getTables(ipfixDbReader) != 0) { msg(MSG_ERROR,"Error in function getTables"); goto out3; } /**initialize columns**/ dbData->colCount = 0; if (pthread_create(&ipfixDbReader->thread, 0, readFromDB, ipfixDbReader)) { msg(MSG_FATAL, "Could not create dbRead thread"); goto out3; } return ipfixDbReader; out3: free(dbData); out2: free(dbReader); out1: free(ipfixDbReader); out0: return NULL; }