コード例 #1
0
ファイル: Call.cpp プロジェクト: raschupkin/TranslateNet
int Call::DBwrite(Connection *sqlCon)
{
	if (!sqlCon || !id)
		return -1;
	PreparedStatement *pstmt = sqlCon->prepareStatement(
			"UPDATE calls SET phone=(?), client=(?), translator=(?), client_country=(?), translator_country=(?), lang=(?), price=(?), start_time=(?), accounted=(?), cost=(?), error=(?) WHERE id=(?)");
	pstmt->setInt(2, client);
	pstmt->setInt(3, translator);
	pstmt->setInt(1, false);
	pstmt->setString(4, COUNTRY_UNKNOWN);
	pstmt->setString(5, COUNTRY_UNKNOWN);
	pstmt->setString(6, translateLang.c_str());
	pstmt->setInt(7, price);
	char *time = asctime(localtime(&start_time));
	if (start_time)
		pstmt->setDateTime(8, time);
	else
		pstmt->setNull(8, 0);
	pstmt->setInt(9, accounted);
	pstmt->setInt(10, cost);
	pstmt->setInt(11, getState() == ERROR);
	pstmt->setInt(12, id);

	int ret;
	try {
		ret = pstmt->executeUpdate();
	} catch (SQLException &ex) {
		log(LOG_ERROR, "[%s] MySQL error(%d): %s", __func__, ex.getErrorCode(), ex.what());
		delete pstmt;
		return 0;
	}
	delete pstmt;
	return ret == 1;
}
コード例 #2
0
ファイル: Call.cpp プロジェクト: raschupkin/TranslateNet
int PhoneCall::DBwrite(Connection *sqlCon)
{
	if (!sqlCon || !id)
		return -1;
	PreparedStatement *pstmt = sqlCon->prepareStatement(
			"UPDATE calls SET phone=(?), client=(?), translator=(?), client_country=(?), translator_country=(?), lang=(?), price=(?), start_time=(?), accounted=(?), cost=(?), error=(?), request_time=(?), confirm_time=(?), accepted=(?) WHERE id=(?)");
	pstmt->setInt(1, true);
	pstmt->setInt(2, client);
	pstmt->setInt(3, translator);
	pstmt->setString(4, ((PhoneCall *)this)->getClientCountry().c_str());
	pstmt->setString(5, ((PhoneCall *)this)->getTranslatorCountry().c_str());
	pstmt->setString(6, translateLang.c_str());
	pstmt->setInt(7, price);
	char time[512];
	strftime(time, 512, SQLTIME_FMT, localtime(&start_time));
	if (start_time)
		pstmt->setDateTime(8, time);
	else
		pstmt->setNull(8, 0);
	pstmt->setInt(9, getAccountedTime());
	pstmt->setInt(10, cost);
	pstmt->setInt(11, getState() == ERROR);
	strftime(time, 512, SQLTIME_FMT, localtime(&request_time));
	if (request_time)
		pstmt->setString(12, time);
	else
		pstmt->setNull(12, 0);
	strftime(time, 512, SQLTIME_FMT, localtime(&confirm_time));
	if (confirm_time)
		pstmt->setDateTime(13, time);
	else
		pstmt->setNull(13, 0);
	pstmt->setBoolean(14, accepted);
	pstmt->setInt(15, id);
	int ret;
	try {
		ret = pstmt->executeUpdate();
	} catch (SQLException &ex) {
		log(LOG_ERROR, "[%s] MySQL error(%d): %s", __func__, ex.getErrorCode(), ex.what());
		delete pstmt;
		return 0;
	}
	delete pstmt;
	return ret == 1;
}