Added delete support to the CRUD system.
This commit is contained in:
parent
36f5153091
commit
8c20bd6a02
8 changed files with 230 additions and 89 deletions
|
|
@ -52,25 +52,26 @@ Params::~Params()
|
|||
deleteValues();
|
||||
}
|
||||
|
||||
void Params::addText(const char *data, Oid oid)
|
||||
Param Params::addText(const char *data, Oid oid)
|
||||
{
|
||||
m_paramTypes.push_back(oid);
|
||||
m_paramValues.push_back(data);
|
||||
m_paramLengths.push_back(data ? strlen(data) + 1 : 0);
|
||||
m_paramFormats.push_back(0);
|
||||
return Param(*this, m_paramValues.size() - 1);
|
||||
}
|
||||
|
||||
void Params::add(const QString &s, Oid oid)
|
||||
Param Params::add(const QString &s, Oid oid)
|
||||
{
|
||||
auto ba = s.toUtf8();
|
||||
const int len = ba.size();
|
||||
char * p = new char[len+1];
|
||||
std::memcpy(p, ba.data(), len);
|
||||
p[len] = 0;
|
||||
addText(p, oid);
|
||||
return addText(p, oid);
|
||||
}
|
||||
|
||||
void Params::add(const char *data, Oid oid)
|
||||
Param Params::add(const char *data, Oid oid)
|
||||
{
|
||||
char * p = nullptr;
|
||||
int len = 0;
|
||||
|
|
@ -80,11 +81,12 @@ void Params::add(const char *data, Oid oid)
|
|||
std::memcpy(p, data, len);
|
||||
p[len] = 0;
|
||||
}
|
||||
return addText(p, oid);
|
||||
|
||||
m_paramTypes.push_back(oid);
|
||||
m_paramValues.push_back(p);
|
||||
m_paramLengths.push_back(len);
|
||||
m_paramFormats.push_back(0);
|
||||
// m_paramTypes.push_back(oid);
|
||||
// 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)
|
||||
|
|
|
|||
|
|
@ -10,6 +10,21 @@
|
|||
|
||||
namespace Pgsql {
|
||||
|
||||
class Params;
|
||||
|
||||
class Param {
|
||||
public:
|
||||
Param(Params ¶ms, int index)
|
||||
: params(params)
|
||||
, index(index)
|
||||
{}
|
||||
|
||||
int getIndex() const { return index; }
|
||||
private:
|
||||
Params ¶ms;
|
||||
int index;
|
||||
};
|
||||
|
||||
class Params {
|
||||
public:
|
||||
Params();
|
||||
|
|
@ -20,11 +35,11 @@ namespace Pgsql {
|
|||
~Params();
|
||||
|
||||
|
||||
void add(const QString &s, Oid oid=varchar_oid);
|
||||
void add(const char *data, Oid oid=varchar_oid);
|
||||
void add(boost::optional<std::string> s, Oid oid=varchar_oid)
|
||||
Param add(const QString &s, Oid oid=varchar_oid);
|
||||
Param add(const char *data, Oid oid=varchar_oid);
|
||||
Param add(boost::optional<std::string> s, Oid oid=varchar_oid)
|
||||
{
|
||||
add(s ? s->c_str() : nullptr, oid);
|
||||
return add(s ? s->c_str() : nullptr, oid);
|
||||
}
|
||||
//void addBinary(const char *data, int length, Oid oid);
|
||||
void clear();
|
||||
|
|
@ -58,7 +73,7 @@ namespace Pgsql {
|
|||
*
|
||||
* The class takes ownership of data and will try to delete[] it.
|
||||
*/
|
||||
void addText(const char *data, Oid oid=VARCHAROID);
|
||||
Param addText(const char *data, Oid oid=VARCHAROID);
|
||||
};
|
||||
|
||||
} // end namespace Pgsql
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue