File: recordset_cdbc_storage.h

package info (click to toggle)
mysql-workbench 6.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 113,932 kB
  • ctags: 87,814
  • sloc: ansic: 955,521; cpp: 427,465; python: 59,728; yacc: 59,129; xml: 54,204; sql: 7,091; objc: 965; makefile: 638; sh: 613; java: 237; perl: 30; ruby: 6; php: 1
file content (81 lines) | stat: -rw-r--r-- 3,472 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* 
 * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; version 2 of the
 * License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#pragma once

#include "wbpublic_public_interface.h"
#include "sqlide/recordset_sql_storage.h"
#include "cppdbc.h"

class WBPUBLICBACKEND_PUBLIC_FUNC Recordset_cdbc_storage : public Recordset_sql_storage
{
public:
  struct FieldInfo {
    std::string catalog;
    std::string schema;
    std::string table;
    std::string field;
    std::string type;
    std::string charset;
    int display_size;
    int precision;
    int scale;
  };
  
  typedef boost::shared_ptr<Recordset_cdbc_storage> Ref;
  static Ref create(bec::GRTManager *grtm) { return Ref(new Recordset_cdbc_storage(grtm)); }
  virtual ~Recordset_cdbc_storage();
protected:
  Recordset_cdbc_storage(bec::GRTManager *grtm);

protected:
  virtual void do_unserialize(Recordset *recordset, sqlite::connection *data_swap_db);
  virtual void do_fetch_blob_value(Recordset *recordset, sqlite::connection *data_swap_db, RowId rowid, ColumnId column, sqlite::variant_t &blob_value);

protected:
  virtual void run_sql_script(const Sql_script &sql_script, bool skip_transaction);

public:
  std::string decorated_sql_query(); // adds limit clause if defined by options

public:
  void setAuxConnectionGetter(boost::function<base::RecMutexLock (sql::Dbc_connection_handler::Ref &, bool)> getConnection) { _getAuxConnection = getConnection; };
  void setUserConnectionGetter(boost::function<base::RecMutexLock (sql::Dbc_connection_handler::Ref &, bool)> getConnection) { _getUserConnection = getConnection; };

  void dbc_resultset(boost::shared_ptr<sql::ResultSet>& value) { _dbc_resultset= value; }
  void dbc_statement(boost::shared_ptr<sql::Statement>& value) { _dbc_statement= value; }
  bool reloadable() const { return _reloadable; }
  void reloadable(bool val) { _reloadable= val; }

  void set_gather_field_info(bool flag) { _gather_field_info = flag; }
  std::vector<FieldInfo> &field_info() { return _field_info; }

private:
  boost::shared_ptr<sql::ResultSet> _dbc_resultset; // for 1-time unserialization
  boost::shared_ptr<sql::Statement> _dbc_statement; // for 1-time unserialization
  boost::function<base::RecMutexLock (sql::Dbc_connection_handler::Ref &, bool)> _getAuxConnection;
  boost::function<base::RecMutexLock (sql::Dbc_connection_handler::Ref &, bool)> _getUserConnection;

  std::vector<FieldInfo> _field_info;
  bool _reloadable; // whether can be reloaded using stored sql query
  bool _gather_field_info;

  size_t determine_pkey_columns(Recordset::Column_names &column_names, Recordset::Column_types &column_types, Recordset::Column_types &real_column_types);
  size_t determine_pkey_columns_alt(Recordset::Column_names &column_names, Recordset::Column_types &column_types, Recordset::Column_types &real_column_types);
};