2017-02-13 19:51:19 +01:00
|
|
|
|
#ifndef PGSQL_PARAMS_H
|
|
|
|
|
|
#define PGSQL_PARAMS_H
|
|
|
|
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <QString>
|
2017-08-23 08:10:01 +02:00
|
|
|
|
#include <libpq-fe.h>
|
2017-02-13 19:51:19 +01:00
|
|
|
|
#include "Pgsql_declare.h"
|
|
|
|
|
|
|
|
|
|
|
|
namespace Pgsql {
|
|
|
|
|
|
|
|
|
|
|
|
class Params {
|
|
|
|
|
|
public:
|
|
|
|
|
|
Params();
|
|
|
|
|
|
Params(const Params& rhs);
|
|
|
|
|
|
Params& operator=(const Params& rhs);
|
2017-02-19 11:12:43 +01:00
|
|
|
|
Params(Params&& rhs);
|
|
|
|
|
|
Params& operator=(Params&& rhs);
|
2017-02-13 19:51:19 +01:00
|
|
|
|
~Params();
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-12-09 10:45:13 +01:00
|
|
|
|
void add(const QString &s, Oid oid=VARCHAROID);
|
2018-02-05 21:42:54 +01:00
|
|
|
|
void add(const char *data, Oid oid=VARCHAROID);
|
|
|
|
|
|
//void addBinary(const char *data, int length, Oid oid);
|
2017-02-13 19:51:19 +01:00
|
|
|
|
void clear();
|
|
|
|
|
|
|
2017-02-19 11:12:43 +01:00
|
|
|
|
bool empty() const { return m_paramTypes.empty(); }
|
|
|
|
|
|
int size() const { return m_paramTypes.size(); }
|
|
|
|
|
|
|
|
|
|
|
|
const Oid* types() const { return m_paramTypes.data(); }
|
|
|
|
|
|
const char* const* values() const { return m_paramValues.data(); }
|
|
|
|
|
|
const int* lengths() const { return m_paramLengths.data(); }
|
|
|
|
|
|
const int* formats() const { return m_paramFormats.data(); }
|
|
|
|
|
|
|
2017-02-13 19:51:19 +01:00
|
|
|
|
private:
|
|
|
|
|
|
using t_paramValues = std::vector<const char *>;
|
|
|
|
|
|
|
|
|
|
|
|
void deleteValues()
|
|
|
|
|
|
{
|
|
|
|
|
|
for (auto e : m_paramValues)
|
|
|
|
|
|
delete[] e;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Assumes other lists already have been copied */
|
|
|
|
|
|
void copyValues(const t_paramValues &r);
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<Oid> m_paramTypes;
|
|
|
|
|
|
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;
|
2018-02-05 21:42:54 +01:00
|
|
|
|
|
|
|
|
|
|
/** \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);
|
2017-02-13 19:51:19 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace Pgsql
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PGSQL_PARAMS_H
|