ComSDK
 Указатель Классы Пространства имен Функции Переменные Определения типов Перечисления Элементы перечислений Друзья Группы Страницы
sqltable.h
1 //===========================================================================
2 #ifndef comfrm_SqlTableH
3 #define comfrm_SqlTableH
4 // ============================================================================================ //
5 // Параметры ревизии(версии):
6 // ============================================================================================ //
7 // [prd]Period: 1/2012
8 // [aut]Author: Anton Pershin
9 // [did]DeveloperID: ap
10 // [pid]ProblemID: 00001
11 // [rvs = did.date.pid]Revision: //#ap.31.01.2012.00001
12 // [dsc]Description: SQL table representation
13 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
14 // ============================================================================================ //
15 // [prd]Period: 03/2013
16 // [aut]Author: Соколов Александр
17 // [did]DeveloperID: sa
18 // [pid]ProblemID: 00002
19 // [rvs = did.date.pid]Revision: //#sa.2013-03-10.00002
20 // [dsc]Description: Преобразование в DLL
21 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
22 // ============================================================================================ //
23 // [prd]Period: 04/2013
24 // [aut]Author: Макаренков Вячеслав
25 // [did]DeveloperID: mv
26 // [pid]ProblemID: 00003
27 // [rvs = did.date.pid]Revision: //#mv.2013-04-04.00003
28 // [dsc]Description: Функции по работе с первичными ключами: addAttrToPK, PKCount
29 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
30 // ============================================================================================ //
31 // [prd]Period: 07/2013
32 // [aut]Author: Шевцов Алексей
33 // [did]DeveloperID: ash
34 // [pid]ProblemID: 00004
35 // [rvs = did.date.pid]Revision: //#ash.2013-07-23.00004
36 // [dsc]Description: Добавление новой функции removeEmptyValues() для для удаления пустых значений из сгенерированного запроса
37 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
38 // ============================================================================================ //
39 // [prd]Period: 09/2013
40 // [aut]Author: Шевцов Алексей
41 // [did]DeveloperID: ash
42 // [pid]ProblemID: 00005
43 // [rvs = did.date.pid]Revision: //#ash.2013-09-22.00005
44 // [dsc]Description: Добавление новых функций: getColumnFullName(int pCol) - полное имя столбца (sch.table.attr)
45 // getPKAttrIndexes() - список индексов аттрибутов первичного ключа
46 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
47 // ============================================================================================ //
48 // [prd]Period: 01/2014
49 // [aut]Author: Вячеслав Макаренков
50 // [did]DeveloperID: mv
51 // [pid]ProblemID: 00006
52 // [rvs = did.date.pid]Revision: //#mv.2014-01-13.00006
53 // [dsc]Description: Изменение функции setColumnData() в связи с добавлениями в формат XDBT
54 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
55 // ============================================================================================ //
56 // [prd]Period: 02/2014
57 // [aut]Author: Соколов Александр
58 // [did]DeveloperID: sa
59 // [pid]ProblemID: 00010
60 // [rvs = did.date.pid]Revision: //#sa.2014-02-03.00010
61 // [dsc]Description: Добавил метод findRow, который позволяет осуществлять поиск записи по полностью заданному первичному ключу БЕЗ явного указания имен атрибутов
62 // Строковый входной параметр нового метода должен определить значения всех атрибутов, входящих в PK таблицы в том же порядке как и в DDL определении
63 // таблицы!
64 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
65 // ============================================================================================ //
66 // [prd]Period: 02/2014
67 // [aut]Author: Соколов Александр
68 // [did]DeveloperID: sa
69 // [pid]ProblemID: 00010
70 // [rvs = did.date.pid]Revision: //#sa.2014-02-03.00013
71 // [dsc]Description: Полностью переработал метод checkDBTableSubstsAndAppendSubstsList! Логика выгрузки данных из БД была изменена при генерации документов на основе
72 // использования файла дополнительных параметров.
73 // FirstAuthor=[alsokolo]$sys.users//Первый автор
74 // + FirstAuthor.famnm
75 // + FirstAuthor.dscra
76 // + FirstAuthor.dscra
77 // + ...
78 // SecondAuthor=[vschetinin]$sys.users//Второй автор
79 // + SecondAuthor.dscra
80 // + ...
81 // ASDA=[DLL_FUNC,test_graph_func3]$sys.aipva//Тест
82 // + ASDA.aisid = test_graph_func3
83 // + ASDA.aclsi = DLL_FUNC
84 // + ...
85 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
86 // ============================================================================================ //
87 // [prd]Period: 08/2014
88 // [aut]Author: Макаренков Вячеслав
89 // [did]DeveloperID: mv
90 // [pid]ProblemID: 00012
91 // [rvs = did.date.pid]Revision: //#mv.04.08.2014.00012
92 // [dsc]Description: Добавлена перегрузка функции insertColumn, принимающая на вход доп
93 // параметры из нового xdbt-формата ( работает как setColumnData плюс
94 // добавление нового столбца в таблицу )
95 // [ccm]CodeComment: rvs.{[s]Start | [e]End | []}{[n]New | [o]Old | [d]Develop}
96 
97 //========================================================================
98 // ДОПОЛНИТЕЛЬНЫЕ ПОДКЛЮЧЕНИЯ (Типы и модули, необходимые для .h - файла)
99 //------------------------------------------------------------------------
100 #include "libtools.h"
101 #include "anymap.h"
102 
103 #include <vector>
104 #include <string>
105 #include <map>
106 #include <list>
107 #include <climits>
108 //==================================================================
109 
110 namespace com {
117  namespace sql {
132  class MAC_DLLEXPORT SqlTable
133  {
134  public:
141  {
144  ctForeignKey
145  };
146 
149  {
155  vtInt
156  };
157 
158  struct TableColumn
159  {
160  TableColumn()
161  : mName(""), mDescription(""), mColumnType(ctOrdinary), mValueType(vtUnknown), mMaxLength(INT_MAX)
162  {}
163 
164  std::vector< std::string > mContent; // обязательно должен быть заполненным. Все остальные параметры являются дополнительными
165  std::string mName;
166  std::string mDescription;
167  ColumnType mColumnType;
168  ValueType mValueType;
169  unsigned int mMaxLength;
170 
171  //#mv.2012-07-30.00002.sn
172  std::string m_domain;
173  //#mv.2012-07-30.00002.en
174 
175  };
176 
178  struct ForeignKey
179  {
180  std::string mRefSchema;
181  std::string mRefTable;
182  // colNum refColNum
183  std::map< int,int > mRefCols;
184  };
185 
186  struct Constraints
187  {
188  std::vector<std::string> m_primaryKeys;
189 
190  bool isEmpty() const {return m_primaryKeys.empty();}
191  bool isPKEmpty() const {return m_primaryKeys.empty();}
192  };
193 
194 
195  public:
196  SqlTable();
197  SqlTable(const SqlTable &pSQLTable);
198  ~SqlTable();
199 
201  std::string getTableName() const;
202 
204  std::string getSchemaName() const;
205 
207  std::string getDatabaseDescriptor() const;
208 
210  std::string getTableFullName() const;
211 
213  std::string getTableDescription() const;
214 
216  int getColumnsCount() const;
217 
219  int getRowsCount() const;
220 
222  std::string getContent(int pCol, int pRow) const;
223 
225  std::string getContent(const std::string& pCol, int pRow) const;
226 
228  std::string getColumnName(int pCol) const;
229 
231  std::string getColumnFullName(int pCol) const; //#ash.2013-09-22.00005
232 
234  const std::list<int>& getPKAttrIndexes() const; //#ash.2013-09-22.00005
235 
237  int getColumnIndexByName(const std::string& pColName) const;
238 
240  std::string getColumnDescription(int pCol) const;
241 
243  ColumnType getColumnType(int pCol) const;
244 
246  ValueType getValueType(int pCol) const;
247 
253  const ForeignKey & getForeignKey(int pCol) const;
254 
256  std::list< int > find(const std::map< int, std::string >& pParams) const;
257 
259  void setTableName(const std::string& pTableName);
260 
262  void setSchemaName(const std::string& pSchemaName);
263 
265  void setDatabaseDescriptor(const std::string& dd);
266 
268  void setTableDescription(const std::string& pTableDescr);
269 
271  void setFormat(int pColumnsCount, int pRowsCount, bool pEmpty);
272 
274  void setColumnName(int p_col, const std::string& p_name);
275 
277  void setColumnType(int p_col, ColumnType p_colType);
278 
280  void setValueType(int p_col, ValueType p_valType);
281 
283  bool setColumnData(int p_col, const std::string& p_name, ColumnType p_colType, ValueType p_valType,
284  const std::string& p_domainName = "", int p_maxLen = INT_MAX, const std::string& p_descr = "" ); //#mv.2014-01-13.00006.n
285 
291  bool setContent(int pCol, int pRow, const std::string& pValue);
292 
294  bool setContent(const std::string& p_col, int p_row, const std::string &p_value);
295 
297  bool setContent(int p_row, std::map< int, std::string >& p_values );
298 
300  bool insertRow( const std::map< int, std::string >& pValues );
301 
302  // TODO: нужно оставить только одну функцию
303  // Метод insertColumn должен гарантировать полноценную вставку, с учетом ColumnType
304  // Соотв. метод addAttrToPK не нужен
306  bool insertColumn(const std::string& pName, const std::string& pDescription, const std::string& pDomainName, ColumnType pColumnType, ValueType pValueType, int pMaxLength);
307 
309  void addEmptyRow();
310 
316  int deleteRow( int pRow);
317 
319  std::string makeUpUpdateRequest(int pRow, const std::map< int, std::string >& pChangedValues);
320 
322  std::string makeUpInsertRequest(const std::map< int, std::string >& pValues);
323 
325  std::string makeUpDeleteRequest(int pRow);
326 
328  std::string makeUpSelectRequest(const std::map< int, std::string >& pValues); //#at.2014-10-20.00013n
329  //void removeEmptyValues( std::string& oSQLRequest ); //#sa.2014-08-28.00011.o
330  //void replaceEmptyValuesByNULL( std::string& oSQLRequest ); //#sa.2014-08-28.00011.o
331 
333  int findRow(const std::string& p_colName,const std::string& p_value) const;
334 
336  int findRow(const std::map<std::string,std::string>& p_attrsAndValues) const;
337 
339  int findRow(const std::string& pCommaSeparatedPKValues) const; //#sa.2014-02-03.00010.n
340 
342  std::vector< int > findRows(const std::string& p_colName, const std::string& p_value) const;
343 
345  std::vector< int > findRows(const std::map<std::string, std::string>& p_attrsAndValues) const;
346 
348  bool isEmpty() const;
349 
351  bool addAttrToPK(const std::string& p_attrName);
352 
354  void addForeignKey(int p_col, const std::string& p_refSchema, const std::string& p_refTable, int p_refCol);
355 
357  int getPKCount() const;
358 
360  bool attrExists( const std::string& p_attrName ) const;
361 
363  std::string getColumnDomain( int p_col ) const;
364 
366  int getColumnLength( int p_col ) const;
367 
368  private:
369  void removeEmptyValues( std::string& o_SQLRequest, const std::string& p_empty_string_token); //#sa.2014-08-28.00011.n (to deprecate in next version)
370 
371  private:
372  std::vector< TableColumn > mContentRepresentation;
373  std::vector< ForeignKey > mForeignKeys;
374  std::list< int > mPrimaryKey;
375  std::string mSchemaName;
376  std::string mTableName;
377  std::string mDatabaseDescriptor;
378  std::string mTableDescription;
379  };
380  }
381 }
382 //===========================================================================
383 #endif
384 //===========================================================================
Модель SQL-таблицы
Definition: sqltable.h:132
Строка
Definition: sqltable.h:152
Definition: sqltable.h:186
Часть первичного ключа
Definition: sqltable.h:143
std::map< int, int > mRefCols
Таблица на которую ссылается внешний ключ
Definition: sqltable.h:183
ColumnType
Definition: sqltable.h:140
ValueType
Тип значение колонки
Definition: sqltable.h:148
Вещественное число
Definition: sqltable.h:151
Definition: sqltable.h:158
Время/дата
Definition: sqltable.h:154
Внешний ключ
Definition: sqltable.h:178
Булевский тип
Definition: sqltable.h:153
Неизвестный тип (строка подразумевается)
Definition: sqltable.h:150
Обычная
Definition: sqltable.h:142
std::string mRefTable
Схема, на которую ссылается внешний ключ
Definition: sqltable.h:181