libdballe  7.7
sql/attrv6.h
1 /*
2  * db/sql/attrv6 - v6 implementation of attr table
3  *
4  * Copyright (C) 2005--2015 ARPA-SIM <urpsim@smr.arpa.emr.it>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Author: Enrico Zini <enrico@enricozini.com>
20  */
21 
22 #ifndef DBALLE_DB_SQL_ATTRV6_H
23 #define DBALLE_DB_SQL_ATTRV6_H
24 
25 #include <dballe/db/sql/datav6.h>
26 #include <wreport/var.h>
27 #include <functional>
28 #include <vector>
29 #include <memory>
30 #include <cstdio>
31 
32 namespace dballe {
33 struct Record;
34 
35 namespace db {
36 namespace sql {
37 struct AttributeList;
38 
39 namespace bulk {
40 struct InsertAttrsV6;
41 }
42 
46 struct AttrV6
47 {
48 public:
49  enum UpdateMode {
50  UPDATE,
51  IGNORE,
52  ERROR,
53  };
54 
55  virtual ~AttrV6();
56 
58  void insert_attributes(Transaction& t, int id_data, const wreport::Var& var, UpdateMode update_mode=UPDATE);
59 
61  virtual void insert(Transaction& t, sql::bulk::InsertAttrsV6& vars, UpdateMode update_mode=UPDATE) = 0;
62 
71  virtual void read(int id_data, std::function<void(std::unique_ptr<wreport::Var>)> dest) = 0;
72 
76  virtual void dump(FILE* out) = 0;
77 };
78 
79 namespace bulk {
80 
85 struct AttrV6 : public Item
86 {
87  int id_data;
88  const wreport::Var* attr;
89 
90  AttrV6(const wreport::Var* attr, int id_data=-1)
91  : id_data(id_data), attr(attr)
92  {
93  }
94  bool operator<(const AttrV6& v) const
95  {
96  if (int d = id_data - v.id_data) return d < 0;
97  return attr->code() < v.attr->code();
98  }
99 
100  void dump(FILE* out) const;
101 };
102 
103 struct InsertAttrsV6 : public std::vector<AttrV6>
104 {
105  void add(const wreport::Var* attr, int id_data)
106  {
107  emplace_back(attr, id_data);
108  }
109 
110  // Add all attributes of the given variable
111  void add_all(const wreport::Var& var, int id_data);
112 
113  void dump(FILE* out) const;
114 };
115 
121 {
122  InsertAttrsV6& attrs;
123  InsertAttrsV6::iterator iter;
124  bool do_insert = false;
125  bool do_update = false;
126 
128 
129  bool annotate(int id_data, wreport::Varcode code, const char* value);
130  void annotate_end();
131 
132  void dump(FILE* out) const;
133 };
134 
135 }
136 
137 
138 }
139 }
140 }
141 
142 #endif
143 
Definition: sql/attrv6.h:103
Precompiled queries to manipulate the attr table.
Definition: sql/attrv6.h:46
Copyright (C) 2008–2010 ARPA-SIM urpsim@smr.arpa.emr.it
Definition: cmdline.h:17
Attribute table management used by the db module.
Definition: sql/datav6.h:81
Helper class for annotating InsertV6 variables with the current status of the database.
Definition: sql/attrv6.h:120
A RAII transaction interface.
Definition: sql.h:134
Workflow information about an attribute variable listed for bulk insert/update.
Definition: sql/attrv6.h:85