예제 #1
0
void ConfigConnector::updateFilterBlack(bool enable) {
	Connection conn = _pool->getConnection();

	PreparedStatement stmt = conn->prepareStatement("UPDATE `config_resource` SET `value` = ? WHERE `cid` = '1'");
	stmt->setBoolean(1, enable);
	stmt->execute();

	_pool->returnConnection(conn);
}
예제 #2
0
파일: cnuodb.cpp 프로젝트: tilinna/go-nuodb
int nuodb_statement_bind(struct nuodb *db, struct nuodb_statement *st,
                         struct nuodb_value parameters[]) {
    PreparedStatement *stmt = reinterpret_cast<PreparedStatement *>(st);
    try {
        int parameterCount = stmt->getParameterMetaData()->getParameterCount();
        for (int i=0; i < parameterCount; ++i) {
            int parameterIndex = i+1;
            switch (parameters[i].vt) {
                case NUODB_TYPE_NULL:
                    stmt->setNull(parameterIndex, NUOSQL_NULL);
                    break;
                case NUODB_TYPE_INT64:
                    stmt->setLong(parameterIndex, parameters[i].i64);
                    break;
                case NUODB_TYPE_FLOAT64: {
                    union {
                        int64_t i64;
                        double float64;
                    } value = { parameters[i].i64 };
                    stmt->setDouble(parameterIndex, value.float64);
                    break;
                }
                case NUODB_TYPE_BOOL:
                    stmt->setBoolean(parameterIndex, !!parameters[i].i64);
                    break;
                case NUODB_TYPE_STRING: {
                    size_t length = parameters[i].i32;
                    const char *s = reinterpret_cast<const char*>(parameters[i].i64);
                    // Extra conversion due to missing length param in the setString API
                    const std::string str(s, length);
                    stmt->setString(parameterIndex, str.c_str());
                    break;
                }
                case NUODB_TYPE_BYTES: {
                    int length = parameters[i].i32;
                    const unsigned char *bytes = reinterpret_cast<const unsigned char*>(parameters[i].i64);
                    stmt->setBytes(parameterIndex, length, bytes);
                    break;
                }
                case NUODB_TYPE_TIME: {
                    int64_t seconds = parameters[i].i64;
                    int32_t nanos = parameters[i].i32;
                    SqlTimestamp ts(seconds, nanos);
                    stmt->setTimestamp(parameterIndex, &ts);
                    break;
                }
            }
        }
        return 0;
    } catch  (SQLException &e) {
        return setError(db, e);
    }
}
예제 #3
0
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;
}