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"
|
2018-02-18 07:15:43 +01:00
|
|
|
|
#include "Pgsql_oids.h"
|
2018-11-08 21:50:49 +01:00
|
|
|
|
#include <optional>
|
2017-02-13 19:51:19 +01:00
|
|
|
|
|
|
|
|
|
|
namespace Pgsql {
|
|
|
|
|
|
|
2018-04-08 09:02:22 +02:00
|
|
|
|
class Params;
|
|
|
|
|
|
|
|
|
|
|
|
class Param {
|
|
|
|
|
|
public:
|
|
|
|
|
|
Param(Params ¶ms, int index)
|
|
|
|
|
|
: params(params)
|
|
|
|
|
|
, index(index)
|
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
int getIndex() const { return index; }
|
|
|
|
|
|
private:
|
|
|
|
|
|
Params ¶ms;
|
|
|
|
|
|
int index;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2017-02-13 19:51:19 +01:00
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-08 09:02:22 +02:00
|
|
|
|
Param add(const QString &s, Oid oid=varchar_oid);
|
|
|
|
|
|
Param add(const char *data, Oid oid=varchar_oid);
|
2018-11-08 21:50:49 +01:00
|
|
|
|
Param add(std::optional<std::string> s, Oid oid=varchar_oid)
|
2018-02-18 07:15:43 +01:00
|
|
|
|
{
|
2018-04-08 09:02:22 +02:00
|
|
|
|
return add(s ? s->c_str() : nullptr, oid);
|
2018-02-18 07:15:43 +01:00
|
|
|
|
}
|
2022-01-22 16:22:29 +01:00
|
|
|
|
|
|
|
|
|
|
void addParams(const Params ¶ms);
|
2018-02-05 21:42:54 +01:00
|
|
|
|
//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(); }
|
2021-03-06 13:15:17 +01:00
|
|
|
|
int size() const { return static_cast<int>(m_paramTypes.size()); }
|
2017-02-19 11:12:43 +01:00
|
|
|
|
|
|
|
|
|
|
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 */
|
2022-01-22 16:22:29 +01:00
|
|
|
|
void appendValues(const t_paramValues &r);
|
2017-02-13 19:51:19 +01:00
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
*/
|
2018-09-09 18:52:32 +02:00
|
|
|
|
Param addText(const char *data, Oid oid=varchar_oid);
|
2017-02-13 19:51:19 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace Pgsql
|
|
|
|
|
|
|
|
|
|
|
|
#endif // PGSQL_PARAMS_H
|