--- misc/mysql_splitter/splitter.cpp 2011/04/10 21:15:14 1283 +++ misc/mysql_splitter/splitter.cpp 2011/05/11 19:19:07 1460 @@ -18,10 +18,10 @@ string remove_comments(string in) { bool isComment = false; ostringstream out; - for (int i=0; i words; words = boost::split(words, input, boost::is_any_of(" ") ); string last = words.back(); - - boost::erase_all(last, ";"); boost::trim(last); - return last; } @@ -90,7 +89,7 @@ cout << "No file named " << inputfile << endl; return 1; } - + ifstream in( inputfile.c_str() ); ofstream out; @@ -100,23 +99,28 @@ if (!in.is_open() ) { cout << "Could not open " << argv[1] << endl; return 2; - } + } + + time_t start = time(NULL); + + const char* SEARCH = "CREATE DATABASE"; + const int SEARCHLEN = strlen(SEARCH); while ( in.good() ) { in.getline(linebuf, BUFSIZE); - string line(linebuf); - //if (line.substr(0, 15) == "CREATE DATABASE" ) { - if ( boost::starts_with(line, "CREATE DATABASE") ) { + //if ( boost::starts_with(line, "CREATE DATABASE") ) { + if (strncmp(linebuf,SEARCH, SEARCHLEN) == 0) { + string line(linebuf); if (out.is_open() ) { out.close(); } boost::trim(line); - string dbname = getLastWord(line); + string dbname = get_db_name(line); cout << ">" << dbname << endl; @@ -144,16 +148,20 @@ if (out.is_open() ) { - out << line << endl; + out << linebuf << endl; } else { - header << line << endl; //collect preamble for later use + header << linebuf << endl; //collect preamble for later use } } if(out.is_open()) - out.close(); + out.close(); + + time_t end = time(NULL); + + cout << "Elapsed " << (end-start) << " seconds" << endl; in.close();