Fledge
An open source edge computing platform for industrial users
sql_buffer.h
1 #ifndef _SQL_BUFFER_H
2 #define _SQL_BUFFER_H
3 /*
4  * Fledge storage service.
5  *
6  * Copyright (c) 2017 OSisoft, LLC
7  *
8  * Released under the Apache 2.0 Licence
9  *
10  * Author: Mark Riddoch
11  */
12 
13 #include <string>
14 #include <list>
15 
16 #define BUFFER_CHUNK 1024
17 
22 class SQLBuffer {
23  class Buffer {
24  public:
25  Buffer();
26  Buffer(unsigned int);
27  ~Buffer();
28  char *detach();
29  char *data;
30  unsigned int offset;
31  unsigned int length;
32  bool attached;
33  };
34 
35  public:
36  SQLBuffer();
37  ~SQLBuffer();
38 
39  bool isEmpty() { return buffers.empty() || (buffers.size() == 1 && buffers.front()->offset == 0); }
40  void append(const char);
41  void append(const char *);
42  void append(const int);
43  void append(const unsigned int);
44  void append(const long);
45  void append(const unsigned long);
46  void append(const double);
47  void append(const std::string&);
48  void quote(const std::string&);
49  const char *coalesce();
50  void clear();
51 
52  private:
53  std::list<Buffer *> buffers;
54 };
55 
56 #endif
void append(const char)
Append a character to a buffer.
Definition: sql_buffer.cpp:57
void clear()
Clear all the buffers from the SQLBuffer and allow it to be reused.
Definition: sql_buffer.cpp:42
void quote(const std::string &)
Quote and append a string to a buffer.
Definition: sql_buffer.cpp:241
Buffer class designed to hold SQL statement that can as required but have minimal copy semantics...
Definition: sql_buffer.h:22
const char * coalesce()
Create a coalesced buffer from the buffer chain.
Definition: sql_buffer.cpp:275
SQLBuffer()
Buffer class designed to hold SQL statement that can as required but have minimal copy semantics...
Definition: sql_buffer.cpp:23
~SQLBuffer()
SQLBuffer destructor.
Definition: sql_buffer.cpp:31