7 #ifndef litesql_field_hpp
8 #define litesql_field_hpp
14 #include "litesql/commontypes.h"
27 typedef std::vector< std::pair<std::string, std::string> > Values;
32 const std::string& tbl,
33 const Values& vals = Values())
34 : _name(n), _table(tbl), _type(t), _values(vals) {}
35 std::string fullName()
const {
return table() +
"." + name(); }
36 std::string name()
const {
return _name; }
37 AT_field_type type()
const {
return _type; }
38 std::string table()
const {
return _table; }
39 std::vector< std::pair<std::string, std::string> > values() {
return _values; }
41 In in(
const std::string& set)
const;
45 Like like(
const std::string& s)
const;
46 bool operator==(
const FieldType & fd)
const {
47 return fd.fullName() == fullName();
49 bool operator!=(
const FieldType & fd)
const {
50 return ! (*
this == fd);
53 std::string _name, _table;
59 template <
class From,
class To>
64 std::string
store(
const T& value) {
70 T load(
const std::string& value) {
71 return convert<const std::string&, T>(value);
81 std::string fullName()
const {
return field->fullName(); }
82 std::string name()
const {
return field->name(); }
83 AT_field_type type()
const {
return field->type(); }
84 std::string table()
const {
return field->table(); }
85 T value()
const {
return _value; }
86 const FieldType & fieldType()
const {
return *field; }
87 bool modified()
const {
return _modified; }
88 void setModified(
bool state) { _modified = state; }
89 const Field & operator=(
const std::string& v) {
90 _value = convert<const std::string&, T>(v);
94 const Field & operator=(
const T& v) {
100 const Field & operator=(T2 v) {
102 _value = litesql::convert<T2, T>(v);
106 bool operator==(
const T2& v)
const {
110 bool operator!=(
const T2& v)
const {
return !(*
this == v); }
112 operator std::string()
const {
return toString(value()); }
114 operator T()
const {
return value(); }
124 std::string fullName()
const {
return field->fullName(); }
125 std::string name()
const {
return field->name(); }
126 AT_field_type type()
const {
return field->type(); }
127 std::string table()
const {
return field->table(); }
128 std::string value()
const {
return _value; }
129 const FieldType & fieldType()
const {
return *field; }
130 bool modified()
const {
return _modified; }
131 void setModified(
bool state) { _modified = state; }
132 const Field & operator=(
const std::string& v) {
137 const Field& operator=(
const char * v) {
143 const Field & operator=(T2 v) {
145 _value = litesql::convert<T2, std::string>(v);
149 bool operator==(
const T2& v)
const {
153 bool operator!=(
const T2& v)
const {
return !(*
this == v); }
155 operator std::string()
const {
return value(); }
158 typedef unsigned char u8_t;
159 typedef long long bigint;
163 Blob() : m_data(NULL),m_length(0) {};
164 Blob(
const std::string & value) : m_data(NULL),m_length(0)
166 initWithHexString(value);
172 initWithData(b.m_data,b.m_length);
175 Blob(
const void* data,
size_t length=0) : m_data(NULL), m_length(0)
177 initWithData((u8_t*)data,length);
181 const Blob& operator=(
const Blob& v) {
182 initWithData(v.m_data,v.m_length);
186 static std::string toHex(
const u8_t* data,
size_t length);
187 std::string toHex()
const ;
188 size_t length()
const {
return m_length; };
189 bool isNull()
const {
return m_data==NULL; };
190 u8_t data(
size_t index)
const {
return m_data[index]; };
191 void data(
const char* pszData);
192 void getData(u8_t* pData,
size_t &length,
size_t offset=0);
198 void initWithData(
const u8_t* data,
size_t length);
199 void initWithHexString(
const std::string& hexString);
202 std::ostream& operator << (std::ostream& os,
const Blob& blob);
204 Blob convert<const std::string&, Blob>(
const std::string& value);
206 std::string convert<const Blob&, std::string>(
const Blob& value);
215 std::string fullName()
const {
return field->fullName(); }
216 std::string name()
const {
return field->name(); }
218 std::string table()
const {
return field->table(); }
219 Blob value()
const {
return _value; }
220 const FieldType & fieldType()
const {
return *field; }
221 bool modified()
const {
return _modified; }
222 void setModified(
bool state) { _modified = state; }
249 operator std::string()
const {
return _value.toHex(); }
254 return a + std::string(f);
258 return std::string(f) + a;
262 return os << f.value();
Definition: field.hpp:161
In in(const std::string &set) const
syntactic sugar to Expr-API, Object::field_.in(set)
Like like(const std::string &s) const
syntactic sugar to Expr-API, Object::field_.like(s)
Definition: field.cpp:25
holds field value
Definition: field.hpp:75
in operator
Definition: expr.hpp:185
like operator
Definition: expr.hpp:178
a class that helps creating SELECT-SQL statements.
Definition: selectquery.hpp:20
std::string store(const T &value)
store function
Definition: field.hpp:64
To convert(From value)
convert function
std::string toString(T a)
returns string representation of passed parameter if it can be written to ostringstream
Definition: string.hpp:20