我正在使用Roland Bock's sqlpp11库进行mysql
查询,并使用Howard Hinnant's date库在我的项目中进行日期操作。
在我的某个更新查询中收到以下错误。
/usr/local/include/sqlpp11/rhs_wrap.h: In instantiation of ‘struct sqlpp::rhs_wrap_t<date::year_month_day, false>’:
/usr/local/include/sqlpp11/assignment.h:63:12: required from ‘struct sqlpp::assignment_t<sqlpp::column_t<changestreet::Goals, changestreet::Goals_::GoalEndDate>, date::year_month_day>’
sqlOperations/sqlppDbConnection.cpp:286:65: required from ‘bool setEmergencyFundGoal(T1, T2, T2, T3, T3) [with T1 = int; T2 = const char*; T3 = double]’
main.cpp:705:113: required from here
/usr/local/include/sqlpp11/rhs_wrap.h:119:43: error: no type named ‘_traits’ in ‘class date::year_month_day’
using _traits = typename Expr::_traits;
这是更新声明
auto efGoal = db_cs.run(update(g).set(g.goalAmount = emergencyFund,
g.goalEndDate = contributionEndDate, // Line number 286
g.goalContributionStartDate = currentDate(),
g.goalContributionEndDate = contributionEndDate,
g.goalInitialContribution = initialContribution,
g.goalMaximumAchievableAmount = emergencyFund,
g.goalCreatedOn = currentDateTime(),
g.goalUpdatedOn = currentDateTime()
).where(g.goalName == goalName
and g.goalType == goalType
and g.usersUserId == userId)
);
这是rhs中使用的值
auto contributionEndDate = lastDateOfMonth(currentDate(), date::months{contributionTenure}) ;
以下是贡献lastDateOfMonth()
功能的定义。
date::year_month_day lastDateOfMonth(date::year_month_day givenDate, date::months monthsNum) {
date::year_month_day newDate = year_month_day{givenDate} + monthsNum;
newDate = newDate.year()/newDate.month()/last;
return newDate;
}
currentDate()
函数
date::year_month_day currentDate() {
auto currentTime = system_clock::now();
auto currentDate = floor<days>(currentTime);
return currentDate;
}
列名goal_end_date
在mysql表结构中的类型为DATE
。
答案 0 :(得分:1)
我需要将mysql数据类型从DATE
更改为DATETIME
,之后system_clock::time_point
类型变量赋值变量就像魅力一样。
它也适用于具有变量赋值类型DATE
的mysql system_clock::day_point
dataype。
P.S:我需要修改返回类型为syste_clock::time_point
的两个给定功能。