Ejemplo n.º 1
0
	bool insert(const word_ptr& word)
	{
		bool exsits = false;
		word->date = now_to_wstring();
		//word->date = word->date.substr(0, word->date.find_first_of(L' '));

		std::wstringstream ss;
		ss << L"select id from wordbook where word='" << double_quotes(word->word) << L"'";
		Statement query(*db_, utf8::w2a(ss.str()));
		if (query.executeStep()) {
			auto id = query.getColumn(0).getInt64();
			ss.str(L""); ss.clear();
			ss << L"delete from wordbook where id=" << id;
			db_->exec(utf8::w2a(ss.str()));
			exsits = true;
		}

		ss.str(L""); ss.clear();
		ss << L"insert into wordbook values(NULL,'" << double_quotes(word->word) << L"','" << word->date << L"')";
		db_->exec(utf8::w2a(ss.str()));
		word->id = db_->getLastInsertRowid() & 0xFFFFFFFF;

		if (!exsits) {
			count_++;
		}

		return !exsits;
	}
Ejemplo n.º 2
0
std::string Route::csv_line()
{	/* return csv line to insert into a table */
	// note: alt_route_names does not need to be in the db since
	// list preprocessing uses alt or canonical and no longer cares
	std::string line = "'" + system->systemname + "','" + region->code + "','" + route + "','" + banner
			 + "','" + abbrev + "','" + double_quotes(city) + "','" + root + "','";
	char mstr[51];
	sprintf(mstr, "%.15g", mileage);
	if (!strchr(mstr, '.')) strcat(mstr, ".0"); // add single trailing zero to ints for compatibility with Python
	line += mstr;
	line += "','" + std::to_string(rootOrder) + "'";
	return line;
}