Feature #12167 ยป wt_dbo_postFieldString.patch
| src/Wt/Dbo/DbAction_impl.h | ||
|---|---|---|
|
foreignKeyTable_, foreignKeyName_,
|
||
|
flags | FieldFlags::ForeignKey, fkConstraints_));
|
||
|
else
|
||
|
// Normal field
|
||
|
mapping_.fields.push_back
|
||
|
(FieldInfo(field.name(), &typeid(V), field.sqlType(session_), flags));
|
||
|
{
|
||
|
if(field.hasPostFieldString())
|
||
|
{
|
||
|
mapping_.fields.push_back
|
||
|
(FieldInfo(field.name(), &typeid(V), field.sqlType(session_), flags, field.sqlPostFieldStringValue()));
|
||
|
|
||
|
}else
|
||
|
// Normal field
|
||
|
mapping_.fields.push_back
|
||
|
(FieldInfo(field.name(), &typeid(V), field.sqlType(session_), flags));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
template<class C>
|
||
| src/Wt/Dbo/Field.h | ||
|---|---|---|
|
AuxId = 0x1
|
||
|
};
|
||
|
|
||
|
FieldRef(V& value, const std::string& name, int size, int flags = 0);
|
||
|
explicit FieldRef(V& value, const std::string& name, int size, int flags = 0);
|
||
|
explicit FieldRef(const std::string& postFieldString, V& value, const std::string& name, int size, int flags = 0);
|
||
|
|
||
|
const std::string& name() const;
|
||
|
int size() const;
|
||
| ... | ... | |
|
const V& value() const { return value_; }
|
||
|
void setValue(const V& value) const { value_ = value; }
|
||
|
|
||
|
bool hasPostFieldString() const { return hasPostFieldString_; }
|
||
|
const std::string& sqlPostFieldStringValue() const { return sqlPostFieldStringValue_; }
|
||
|
|
||
|
void bindValue(SqlStatement *statement, int column) const;
|
||
|
void setValue(Session& session, SqlStatement *statement, int column) const;
|
||
|
|
||
| ... | ... | |
|
std::string name_;
|
||
|
int size_;
|
||
|
int flags_;
|
||
|
bool hasPostFieldString_ = false;
|
||
|
std::string sqlPostFieldStringValue_ = {};
|
||
|
};
|
||
|
|
||
|
/*! \brief Type of an SQL relation.
|
||
| ... | ... | |
|
template <class Action, typename V>
|
||
|
void field(Action& action, V& value, const std::string& name, int size = -1);
|
||
|
|
||
|
/**
|
||
|
* @brief Maps a database object field with a postFieldString.
|
||
|
*
|
||
|
* This function binds the field \p value to the database field \p name
|
||
|
* with post string value \p postFieldStringValue
|
||
|
*
|
||
|
* \attention \p postFieldStringValue needs to be escaped as required per backend:
|
||
|
* content of \p postFieldStringValue will be added *as is* after field definition
|
||
|
*
|
||
|
* Primary use was the addition of a default value.
|
||
|
* But recently came across other things that might be interesting to put after the field
|
||
|
*
|
||
|
* \code
|
||
|
* // Adding post field string
|
||
|
* Wt::Dbo::field(" DEFAULT \'escaped String\'", a, stringValue, "name"); // DEFAULT 'escaped String'
|
||
|
* Wt::Dbo::field(" DEFAULT unescaped String", a, stringValue, "name"); // DEFAULT unescaped String // ERROR!
|
||
|
* Wt::Dbo::field(" DEFAULT -1", a, numValue, "number"); // DEFAULT -1
|
||
|
* \endcode
|
||
|
*
|
||
|
* The optional \p size may be used as a hint for the needed
|
||
|
* storage. It is only useful for <i>std::string</i> or
|
||
|
* <i>Wt::WString</i> fields, and causes the schema to use a
|
||
|
* <tt>varchar(</tt><i><tt>size</tt></i><tt>)</tt> for storing the
|
||
|
* field instead of an unlimited length string type.
|
||
|
*
|
||
|
* \ingroup dbo
|
||
|
*/
|
||
|
template <class Action, typename V>
|
||
|
void field(const std::string& postFieldStringValue, Action& action, V& value, const std::string& name, int size = -1);
|
||
|
|
||
|
/*
|
||
|
* This is synonym for belongsTo(), and used by id(). We should overload
|
||
|
* this method also to allow foreign key constraints.
|
||
| src/Wt/Dbo/Field_impl.h | ||
|---|---|---|
|
flags_(flags)
|
||
|
{ }
|
||
|
|
||
|
/// @brief Overload for field with postFieldString Definition
|
||
|
/// @param postFieldString the Value as String that should come after sql field definition
|
||
|
/// Primarily used for DEFAULT Values. Need to include DEFAULT in the string
|
||
|
template <typename V>
|
||
|
FieldRef<V>::FieldRef(const std::string& postFieldString, V& value, const std::string& name, int size, int flags)
|
||
|
: value_(value),
|
||
|
name_(name),
|
||
|
size_(size),
|
||
|
flags_(flags),
|
||
|
sqlPostFieldStringValue_(postFieldString),
|
||
|
hasPostFieldString_(true)
|
||
|
{ }
|
||
|
|
||
|
template <typename V>
|
||
|
const std::string& FieldRef<V>::name() const
|
||
|
{
|
||
| ... | ... | |
|
action.act(FieldRef<V>(value, name, size));
|
||
|
}
|
||
|
|
||
|
template <class A, typename V>
|
||
|
void field(const std::string& postFieldString, A& action, V& value, const std::string& name, int size)
|
||
|
{
|
||
|
action.act(FieldRef<V>(postFieldString, value, name, size));
|
||
|
}
|
||
|
|
||
|
template <class A, class C>
|
||
|
void field(A& action, ptr<C>& value, const std::string& name, int)
|
||
|
{
|
||
| src/Wt/Dbo/Session.C | ||
|---|---|---|
|
|
||
|
sql << " \"" << field.name() << "\" " << sqlType;
|
||
|
|
||
|
if(field.hasPostFieldString())
|
||
|
{
|
||
|
sql << field.sqlPostFieldString();
|
||
|
}
|
||
|
|
||
|
firstField = false;
|
||
|
|
||
|
if (field.isNaturalIdField()) {
|
||
| src/Wt/Dbo/SqlTraits.C | ||
|---|---|---|
|
flags_(flags)
|
||
|
{ }
|
||
|
|
||
|
FieldInfo::FieldInfo(const std::string& name,
|
||
|
const std::type_info *type,
|
||
|
const std::string& sqlType,
|
||
|
int flags,
|
||
|
const std::string& postFieldString)
|
||
|
: name_(name),
|
||
|
sqlType_(sqlType),
|
||
|
type_(type),
|
||
|
flags_(flags),
|
||
|
sqlPostFieldString_(postFieldString),
|
||
|
hasPostFieldString_(true)
|
||
|
{ }
|
||
|
|
||
|
FieldInfo::FieldInfo(const std::string& name, const std::type_info *type,
|
||
|
const std::string& sqlType,
|
||
|
const std::string& foreignKeyTable,
|
||
| src/Wt/Dbo/SqlTraits.h | ||
|---|---|---|
|
FieldInfo(const std::string& name, const std::type_info *type,
|
||
|
const std::string& sqlType, int flags);
|
||
|
|
||
|
/*! \brief Creates a field description.
|
||
|
*/
|
||
|
FieldInfo(const std::string& name, const std::type_info *type,
|
||
|
const std::string& sqlType, int flags, const std::string& postFieldString);
|
||
|
|
||
|
/*! \brief Creates a field description.
|
||
|
*/
|
||
|
FieldInfo(const std::string& name, const std::type_info *type,
|
||
| ... | ... | |
|
*/
|
||
|
const std::string& sqlType() const { return sqlType_; }
|
||
|
|
||
|
/*! \brief Returns the postFieldString that is added after the field.
|
||
|
*/
|
||
|
const std::string& sqlPostFieldString() const { return sqlPostFieldString_; }
|
||
|
|
||
|
/*! \brief Returns whether there is a postFieldString.
|
||
|
*/
|
||
|
const bool hasPostFieldString() const { return hasPostFieldString_; }
|
||
|
|
||
|
/*! \brief Returns the field qualifier.
|
||
|
*/
|
||
|
const std::string& qualifier() const { return qualifier_; }
|
||
| ... | ... | |
|
std::string sql() const;
|
||
|
|
||
|
private:
|
||
|
std::string name_, sqlType_, qualifier_;
|
||
|
std::string name_, sqlType_, qualifier_, sqlPostFieldString_ = "";
|
||
|
std::string foreignKeyName_, foreignKeyTable_;
|
||
|
const std::type_info *type_;
|
||
|
int flags_;
|
||
|
int fkConstraints_;
|
||
|
bool hasPostFieldString_ = false;
|
||
|
};
|
||
|
|
||
|
/*! \class query_result_traits Wt/Dbo/SqlTraits.h Wt/Dbo/SqlTraits.h
|
||