37 lines
983 B
C++
37 lines
983 B
C++
#include "source_dao.hpp"
|
|
|
|
#include "query_param.hpp"
|
|
#include "string_param.hpp"
|
|
#include "int_param.hpp"
|
|
#include "logger.hpp"
|
|
|
|
#include <boost/foreach.hpp>
|
|
#include <libpq-fe.h>
|
|
|
|
SourceDAO::SourceDAO() {
|
|
}
|
|
|
|
SourceDAO::~SourceDAO() {
|
|
}
|
|
|
|
int SourceDAO::addSource(const int externalId, const std::string & name, const std::string & link) {
|
|
DBconnection connection;
|
|
connection.startTransaction();
|
|
|
|
std::string query = "INSERT INTO source(external_id, name, link) values($1::integer,$2::text,$3::text) RETURNING id";
|
|
std::vector<QueryParam*> params;
|
|
params.push_back(new IntParam(externalId));
|
|
params.push_back(new StringParam(name));
|
|
params.push_back(new StringParam(link));
|
|
|
|
PGresult * result = connection.execute(query, params);
|
|
int newId = connection.getIntValue(result, 0, 0);
|
|
connection.clearResult(result);
|
|
connection.endTransaction();
|
|
BOOST_FOREACH (QueryParam * param, params) {
|
|
delete param;
|
|
}
|
|
|
|
return newId;
|
|
|
|
} |