Project

General

Profile

Using std::int16 as primary/surrogate key with Models and tableview

Added by Gavin Blakeman over 4 years ago

Hi

I have a database table that uses a 16bit int as the primary key. I have specialised IdType and invalidID() for the table class. I could use longer (standard) key sizes, but was looking to reduce load on the database server by reducing size on the joins. (Using MySql)

namespace Wt
{
  namespace Dbo
  {
    template<>
    struct dbo_traits<tbl_equipmentClass> : public dbo_default_traits
    {
      typedef std::int16_t IdType;
      static std::int16_t invalidId() { return std::int16_t(); }
      static const char *versionField() { return 0; }
    };
  } // namespace Dbo
} // namespace Wt

class tbl_equipmentClass
  {
  private:
  protected:
  public:
    std::string equipmentClass;
    bool removed;

    template<class Action>
    void persist(Action &a)
    {
      Wt::Dbo::field(a, equipmentClass, "EquipmentClass");
      Wt::Dbo::field(a, removed, "Removed");
    }

When I use this class with a Wt::Dbo::Query model and a tableview, the ID field renders as 0 and the remainder of the information is not visible. (I have included as a screenshot.)

Is this a limitation of the tableview/Query model combo, or is this an error on my side?

Happy to provide further information if required.

Thanks in advance


Replies (1)

RE: Using std::int16 as primary/surrogate key with Models and tableview - Added by Gavin Blakeman over 4 years ago

I meant to add that if I change the primary key back to an INT (32 bit in MySQL), then the error resolved. (IE delete the IdType and invalidID() specialisation of dbo_default_traits)

    (1-1/1)