1 /*
2 * Copyright (C) 2010 Emweb bv, Herent, Belgium.
3 *
4 * See the LICENSE file for terms of use.
5 */
6
7 #include "Wt/Dbo/SqlTraits.h"
8
9 #include <boost/algorithm/string/find.hpp>
10
11 namespace Wt {
12 namespace Dbo {
13 namespace Impl {
14
ifind_last_as(const std::string & name)15 std::string::const_iterator ifind_last_as(const std::string &name)
16 {
17 return boost::ifind_last(name, " as ").end();
18 }
19
20 }
21
FieldInfo(const std::string & name,const std::type_info * type,const std::string & sqlType,int flags)22 FieldInfo::FieldInfo(const std::string& name,
23 const std::type_info *type,
24 const std::string& sqlType,
25 int flags)
26 : name_(name),
27 sqlType_(sqlType),
28 type_(type),
29 flags_(flags)
30 { }
31
FieldInfo(const std::string & name,const std::type_info * type,const std::string & sqlType,const std::string & foreignKeyTable,const std::string & foreignKeyName,int flags,int fkConstraints)32 FieldInfo::FieldInfo(const std::string& name, const std::type_info *type,
33 const std::string& sqlType,
34 const std::string& foreignKeyTable,
35 const std::string& foreignKeyName,
36 int flags, int fkConstraints)
37 : name_(name),
38 sqlType_(sqlType),
39 foreignKeyName_(foreignKeyName),
40 foreignKeyTable_(foreignKeyTable),
41 type_(type),
42 flags_(flags),
43 fkConstraints_(fkConstraints)
44 { }
45
46
setQualifier(const std::string & qualifier,bool firstDboField)47 void FieldInfo::setQualifier(const std::string& qualifier, bool firstDboField)
48 {
49 qualifier_ = qualifier;
50 if (firstDboField)
51 flags_ |= FirstDboField;
52 }
53
sql()54 std::string FieldInfo::sql() const
55 {
56 std::string result;
57
58 if (!qualifier_.empty())
59 result = qualifier_ + '.';
60
61 if (needsQuotes())
62 result += '"' + name() + '"';
63 else
64 result += name();
65
66 return result;
67 }
68
69 }
70 }
71