50 lines
1.1 KiB
C
50 lines
1.1 KiB
C
|
|
#ifndef PGSQL_PARAMS_H
|
|||
|
|
#define PGSQL_PARAMS_H
|
|||
|
|
|
|||
|
|
#include <vector>
|
|||
|
|
#include <QString>
|
|||
|
|
#include <pgsql/libpq-fe.h>
|
|||
|
|
#include "Pgsql_declare.h"
|
|||
|
|
|
|||
|
|
namespace Pgsql {
|
|||
|
|
|
|||
|
|
class Params {
|
|||
|
|
public:
|
|||
|
|
Params();
|
|||
|
|
Params(const Params& rhs);
|
|||
|
|
Params& operator=(const Params& rhs);
|
|||
|
|
Params(const Params&& rhs);
|
|||
|
|
~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=oid_varchar);
|
|||
|
|
void add(const QString &s, Oid oid=oid_varchar);
|
|||
|
|
void addBinary(const char *data, int length, Oid oid);
|
|||
|
|
void clear();
|
|||
|
|
|
|||
|
|
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;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
} // end namespace Pgsql
|
|||
|
|
|
|||
|
|
#endif // PGSQL_PARAMS_H
|