[odb-users] unique constrain has no effect
Panayiotis Georgiou
ps.georgiou at gmail.com
Wed May 29 09:58:59 EDT 2019
Hi odb-users,
I am using ODB 2.4.0 for sqlite on windows.
I am trying to declare one of the columns in my table with the "UNIQUE"
constrain. I have tried several forms of the #pragma suggested in the
manual but they do not seem to work, so I must be doing something wrong.
As you can see from the code below, my persistent classes derive from an
abstract base class (OdbRecord, declared with #pragma db object abstract ).
Derived classes are then declared using #pragma db object polymorphic
pointer(std::shared_ptr). The column which I would like to declare as
unique is OdbRecord::m_Label. The commented code below shows my attempts in
declaring this variable as unique.
Any suggestions on how to fix this would be appreciated.
Thanks for your help,
Panos.
=======================
#pragma db object abstract
class OdbRecord
{
public:
virtual ~OdbRecord() = 0;
virtual std::string toString() const = 0;
void printRecord(std::ostream& out) const { out << toString(); };
int getId() const { return m_Id; };
void setId(const int id) { m_Id = id; };
std::string getLabel() const { return m_Label; };
void setLabel(const std::string& label) { m_Label = label; };
protected:
friend class odb::access;
OdbRecord() {};
#pragma db id
int m_Id = -1;
//----> // #pragma db type("TEXT") unique
//----> // #pragma db unique
std::string m_Label;
//----> // #pragma db index type("UNIQUE") member(m_Label)
//----> // #pragma db index unique member(m_Label)
};
inline OdbRecord::~OdbRecord() {}
=======================
More information about the odb-users
mailing list