Basic support for update in Crud implementation, error reporting and transfering data to modified set is still missing.
This commit is contained in:
parent
3fb32f1200
commit
d626c19e14
15 changed files with 530 additions and 83 deletions
|
|
@ -31,13 +31,16 @@ Params::Params(Params&& rhs)
|
|||
, m_paramValues(std::move(rhs.m_paramValues))
|
||||
, m_paramLengths(std::move(rhs.m_paramLengths))
|
||||
, m_paramFormats(std::move(rhs.m_paramFormats))
|
||||
{}
|
||||
{
|
||||
rhs.m_paramValues.clear(); // just in case it was copied instead of moved
|
||||
}
|
||||
|
||||
Params& Params::operator=(Params&& rhs)
|
||||
{
|
||||
if (&rhs != this) {
|
||||
m_paramTypes = std::move(rhs.m_paramTypes);
|
||||
m_paramValues = std::move(rhs.m_paramValues);
|
||||
rhs.m_paramValues.clear(); // just in case it was copied instead of moved
|
||||
m_paramLengths = std::move(rhs.m_paramLengths);
|
||||
m_paramFormats = std::move(rhs.m_paramFormats);
|
||||
}
|
||||
|
|
@ -67,14 +70,31 @@ void Params::add(const QString &s, Oid oid)
|
|||
addText(p, oid);
|
||||
}
|
||||
|
||||
void Params::addBinary(const char *data, int length, Oid oid)
|
||||
void Params::add(const char *data, Oid oid)
|
||||
{
|
||||
char * p = nullptr;
|
||||
int len = 0;
|
||||
if (data) {
|
||||
len = std::strlen(data);
|
||||
p = new char[len+1];
|
||||
std::memcpy(p, data, len);
|
||||
p[len] = 0;
|
||||
}
|
||||
|
||||
m_paramTypes.push_back(oid);
|
||||
m_paramValues.push_back(data);
|
||||
m_paramLengths.push_back(length);
|
||||
m_paramFormats.push_back(1);
|
||||
m_paramValues.push_back(p);
|
||||
m_paramLengths.push_back(len);
|
||||
m_paramFormats.push_back(0);
|
||||
}
|
||||
|
||||
//void Params::addBinary(const char *data, int length, Oid oid)
|
||||
//{
|
||||
// m_paramTypes.push_back(oid);
|
||||
// m_paramValues.push_back(data);
|
||||
// m_paramLengths.push_back(length);
|
||||
// m_paramFormats.push_back(1);
|
||||
//}
|
||||
|
||||
void Params::clear()
|
||||
{
|
||||
m_paramTypes.clear();
|
||||
|
|
@ -89,9 +109,14 @@ void Params::copyValues(const t_paramValues &r)
|
|||
const int n = m_paramTypes.size();
|
||||
m_paramValues.reserve(n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
const int len = m_paramLengths[i];
|
||||
char * p = new char[len];
|
||||
std::memcpy(p, r[i], len);
|
||||
m_paramValues.push_back(p);
|
||||
if (r[i]) {
|
||||
const int len = m_paramLengths[i];
|
||||
char * p = new char[len+1];
|
||||
std::memcpy(p, r[i], len+1);
|
||||
m_paramValues.push_back(p);
|
||||
}
|
||||
else {
|
||||
m_paramValues.push_back(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,13 +18,9 @@ namespace Pgsql {
|
|||
~Params();
|
||||
|
||||
|
||||
/** \brief Add a parameter to the list.
|
||||
*
|
||||
* The class takes ownership of data and will try to delete[] it.
|
||||
*/
|
||||
void addText(const char *data, Oid oid=VARCHAROID);
|
||||
void add(const QString &s, Oid oid=VARCHAROID);
|
||||
void addBinary(const char *data, int length, Oid oid);
|
||||
void add(const char *data, Oid oid=VARCHAROID);
|
||||
//void addBinary(const char *data, int length, Oid oid);
|
||||
void clear();
|
||||
|
||||
bool empty() const { return m_paramTypes.empty(); }
|
||||
|
|
@ -51,6 +47,12 @@ namespace Pgsql {
|
|||
t_paramValues m_paramValues;
|
||||
std::vector<int> m_paramLengths; ///< postgresql ignores lengths for text parameters but we will it anyway for efficient copying
|
||||
std::vector<int> m_paramFormats;
|
||||
|
||||
/** \brief Add a parameter to the list.
|
||||
*
|
||||
* The class takes ownership of data and will try to delete[] it.
|
||||
*/
|
||||
void addText(const char *data, Oid oid=VARCHAROID);
|
||||
};
|
||||
|
||||
} // end namespace Pgsql
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue