7#ifndef litesql_field_hpp
8#define litesql_field_hpp
26 typedef std::vector< std::pair<std::string, std::string> > Values;
29 FieldType(
const std::string& n,
31 const std::string& tbl,
32 const Values& vals = Values())
33 : _name(n), _type(t), _table(tbl), _values(vals) {}
34 std::string fullName()
const {
return table() +
"." + name(); }
35 std::string name()
const {
return _name; }
36 std::string type()
const {
return _type; }
37 std::string table()
const {
return _table; }
38 std::vector< std::pair<std::string, std::string> > values() {
return _values; }
40 In in(
const std::string& set)
const;
44 Like like(
const std::string& s)
const;
45 bool operator==(
const FieldType & fd)
const {
46 return fd.fullName() == fullName();
48 bool operator!=(
const FieldType & fd)
const {
49 return ! (*
this == fd);
52 std::string _name, _type, _table;
57template <
class From,
class To>
62std::string
store(
const T& value) {
68T load(
const std::string& value) {
69 return convert<const std::string&, T>(value);
78 Field(
const FieldType & f) : field(&f), _modified(
true) {}
79 std::string fullName()
const {
return field->fullName(); }
80 std::string name()
const {
return field->name(); }
81 std::string type()
const {
return field->type(); }
82 std::string table()
const {
return field->table(); }
83 T value()
const {
return _value; }
84 const FieldType & fieldType()
const {
return *field; }
85 bool modified()
const {
return _modified; }
86 void setModified(
bool state) { _modified = state; }
87 const Field & operator=(
const std::string& v) {
92 const Field & operator=(
const T& v) {
98 const Field & operator=(T2 v) {
104 bool operator==(
const T2& v)
const {
108 bool operator!=(
const T2& v)
const {
return !(*
this == v); }
110 operator std::string()
const {
return toString(value()); }
112 operator T()
const {
return value(); }
116class Field<std::string> {
121 Field(
const FieldType & f) : field(&f), _modified(
true) {}
122 std::string fullName()
const {
return field->fullName(); }
123 std::string name()
const {
return field->name(); }
124 std::string type()
const {
return field->type(); }
125 std::string table()
const {
return field->table(); }
126 std::string value()
const {
return _value; }
127 const FieldType & fieldType()
const {
return *field; }
128 bool modified()
const {
return _modified; }
129 void setModified(
bool state) { _modified = state; }
130 const Field & operator=(std::string v) {
135 const Field& operator=(
const char * v) {
141 const Field & operator=(T2 v) {
147 bool operator==(
const T2& v)
const {
151 bool operator!=(
const T2& v)
const {
return !(*
this == v); }
153 operator std::string()
const {
return value(); }
156typedef unsigned char u8_t;
157typedef long long bigint;
161 static const Blob nil;
162 Blob() : m_data(NULL),m_length(0) {};
163 Blob(
const std::string & value) : m_data(NULL),m_length(0)
165 initWithHexString(value);
169 Blob(
const Blob & b) : m_data(NULL)
171 initWithData(b.m_data,b.m_length);
174 Blob(
const void* data,
size_t length) : m_data(NULL), m_length(0)
176 initWithData((u8_t*)data,length);
180 const Blob& operator=(
const Blob& v) {
181 initWithData(v.m_data,v.m_length);
185 std::string toHex()
const ;
186 size_t length()
const {
return m_length; };
187 bool isNull()
const {
return m_data==NULL; };
188 u8_t data(
size_t index)
const {
return m_data[index]; };
189 void data(
const char* pszData);
194 void initWithData(
const u8_t* data,
size_t length);
195 void initWithHexString(
const std::string& hexString);
198std::ostream& operator << (std::ostream& os,
const Blob& blob);
210 Field(
const FieldType & f) : field(&f), _modified(
true) {}
211 std::string fullName()
const {
return field->fullName(); }
212 std::string name()
const {
return field->name(); }
213 std::string type()
const {
return field->type(); }
214 std::string table()
const {
return field->table(); }
215 Blob value()
const {
return _value; }
216 const FieldType & fieldType()
const {
return *field; }
217 bool modified()
const {
return _modified; }
218 void setModified(
bool state) { _modified = state; }
219 const Field & operator=(
const Blob& v) {
245 operator std::string()
const {
return _value.toHex(); }
250 return a + std::string(f);
254 return std::string(f) + a;
257std::ostream & operator << (std::ostream & os,
const litesql::Field<T> & f) {
258 return os << f.value();
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:20
holds field value
Definition field.hpp:73
in operator
Definition expr.hpp:184
like operator
Definition expr.hpp:177
a class that helps creating SELECT-SQL statements.
Definition selectquery.hpp:18
std::string store(const T &value)
store function
Definition field.hpp:62
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:18