Actions
Support #1749
closedHow i can change int id to uuid id and set defailt id ?
Start date:
03/13/2013
Due date:
% Done:
0%
Estimated time:
Description
Hello !
We need chenge id from int value to uuid.
If used this code in my program, program reads data, but if I try write, I get an error because it does not set id to the default.
Pleas tell me, how I can set default id using postgres default set ?
I can`t go without these changes :(
template<>struct dbo_traits<db::OrdersHeader> : public dbo_default_traits
{
typedef std::string IdType;
static IdType invalidId() { return std::string(); }
static const char *surrogateIdField(){return 0;}
//static const char *surrogateIdField(){return "ref";} if uncomment it, i got an error:"Wt: fatal error: bad lexical cast: source type value could not be interpreted as target"
};
class OrdersHeader
{
public:
OrdersHeader();
public:
*std::string ref;*
dbo::ptr<User> author;
dbo::collection< dbo::ptr<OrderRecords> > orderRecords;
template<class Action>
void persist(Action& a)
{
*Wt::Dbo::id(a, ref ,"ref");*
dbo::belongsTo(a, author, "author");
dbo::hasMany(a, orderRecords, dbo::ManyToOne, "orders_header");
};
};
Updated by Евгений Илюшин over 11 years ago
Hello !
now, i do it like this:
{
dbo::Transaction transaction(session_);
std::string ref = session_.query<std::string>("select (md5(((nextval('refcounter_seq'::regclass))::text || now())))::uuid");
OrdersHeader *order = new OrdersHeader();
order->ref = ref;
order->author = user();
order->orderDate = WDateTime::currentDateTime();
m_CurrentOrder = session_.add(order);
transaction.commit();
}
but, is no good method.
By the way,
i tray set this member "order->orderDate = WDateTime::currentDateTime();" without init and set default value, using sql, but it set emty date. Think, you need add to dbo members flags, to set members without init, for transmit null value to sql server. That think ?
Updated by Koen Deforche about 11 years ago
- Status changed from New to Closed
Actions