~ubuntu-branches/ubuntu/precise/glom/precise-updates

« back to all changes in this revision

Viewing changes to glom/base_db.h

  • Committer: Bazaar Package Importer
  • Author(s): Chris Coulson
  • Date: 2009-10-09 16:50:36 UTC
  • mfrom: (1.1.42 upstream)
  • Revision ID: james.westby@ubuntu.com-20091009165036-orinvwmohk838xxl
Tags: 1.12.2-0ubuntu1
* New upstream version:
  - FFE LP: #391664
* debian/control:
  - Bump python-gnome2-extras-dev build-dep to >= 2.25.3.
  - Bump libgdamm3.0-dev build-dep to libgdamm4.0-dev >= 3.99.14.
  - Change libgda3-dev build-dep to libgda-4.0-dev.
  - Change libgda3-postgres dependency to libgda-4.0-postgres.
  - Bump libgtkmm-2.4-dev build-dep to >= 2.14.
  - Add build-dep on libgconfmm-2.6-dev.
  - Bump libgoocanvasmm-dev build-dep to >= 0.14.0.
  - Remove build-dep on libbakery-2.6-dev.
  - Bump postgresql-8.3 dependency to postgresql-8.4.
  - Change scrollkeeper build-dep to rarian-compat.
  - Rename libglom{0,-dev} -> libglom-1.12-{0,dev}. Upstream include
    APIVER in the library name now.
* debian/rules:
  - Update --with-postgres-utils configure flag to point to the new
    path.
  - Drop deprecated --disable-scrollkeeper configure flag.
  - Update DEB_SHLIBDEPS_INCLUDE with new libglom-1.12-0 package name.
  - Don't include /usr/share/cdbs/1/rules/simple-patchsys.mk - there
    are currently no patches.
* debian/libglom-1.12-0.install:
  - Updated for new version.
* debian/libglom-1.12-dev.install:
  - Install pc and header files.
* debian/glom-doc.install:
  - Updated for new version.
* debian/glom.install:
  - Updated for new version.
* Fix debian/watch.
* Dropped obsolete 10-distro-install-postgres-change.patch.
* Built against latest libgoocanvasmm (LP: #428445).
* Also closes LP: #230007, LP: #393229, LP: #393231, LP: #394507,
  LP: #394887, LP: #394894, LP: #397409, LP: #381563.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
#include <gtkmm.h>
27
27
 
28
 
#include <glom/libglom/document/document_glom.h>
29
 
#include <glom/libglom/connectionpool.h>
30
 
#include <glom/libglom/appstate.h>
31
 
#include <glom/libglom/data_structure/foundset.h>
32
 
#include <glom/libglom/data_structure/privileges.h>
33
 
#include <glom/libglom/data_structure/system_prefs.h>
34
 
#include <glom/libglom/utils.h>
35
 
#include <glom/libglom/calcinprogress.h>
36
 
#include "bakery/View/View.h"
37
 
#include <bakery/Utilities/BusyCursor.h>
 
28
#include <libglom/document/view.h>
 
29
#include <libglom/connectionpool.h>
 
30
#include <libglom/appstate.h>
 
31
#include <libglom/data_structure/foundset.h>
 
32
#include <libglom/data_structure/privileges.h>
 
33
#include <libglom/data_structure/system_prefs.h>
 
34
#include <libglom/utils.h>
 
35
#include <libglom/calcinprogress.h>
 
36
#include <libglom/document/bakery/view/view.h>
 
37
#include <glom/bakery/busy_cursor.h>
38
38
 
39
39
namespace Glom
40
40
{
68
68
  static sharedptr<SharedConnection> connect_to_server(Gtk::Window* parent_window, std::auto_ptr<ExceptionConnection>& error);
69
69
#endif // GLIBMM_EXCEPTIONS_ENABLED
70
70
 
71
 
  virtual void set_document(Document_Glom* pDocument); //View override
 
71
  virtual void set_document(Document* pDocument); //View override
72
72
  virtual void load_from_document(); //View override
73
73
 
74
 
  typedef std::vector< sharedptr<Field> > type_vecFields;
 
74
  typedef std::vector< sharedptr<Field> > type_vec_fields;
 
75
  typedef std::vector< sharedptr<const Field> > type_vec_const_fields;
75
76
 
76
 
  static type_vecFields get_fields_for_table_from_database(const Glib::ustring& table_name, bool including_system_fields = false);
 
77
  static type_vec_fields get_fields_for_table_from_database(const Glib::ustring& table_name, bool including_system_fields = false);
77
78
  static bool get_field_exists_in_database(const Glib::ustring& table_name, const Glib::ustring& field_name);
78
79
 
79
80
 
80
 
  static Glib::RefPtr<Gnome::Gda::DataModel> query_execute(const Glib::ustring& strQuery, Gtk::Window* parent_window = 0);
 
81
  /** Execute a SQL Select command, returning the result.
 
82
   * This method handles any Gda exceptions caused by executing the command.
 
83
   */
 
84
  static Glib::RefPtr<Gnome::Gda::DataModel> query_execute_select(const Glib::ustring& strQuery, 
 
85
                                                                  const Glib::RefPtr<Gnome::Gda::Set>& params = Glib::RefPtr<Gnome::Gda::Set>(0));
 
86
 
 
87
 
 
88
  /** Execute a SQL non-select command, returning true if it succeeded.
 
89
   * This method handles any Gda exceptions caused by executing the command.
 
90
   */
 
91
  static bool query_execute(const Glib::ustring& strQuery,
 
92
                            const Glib::RefPtr<Gnome::Gda::Set>& params = Glib::RefPtr<Gnome::Gda::Set>(0));
 
93
 
81
94
  static int count_rows_returned_by(const Glib::ustring& sql_query);
82
95
 
83
 
 
 
96
#ifndef GLOM_ENABLE_CLIENT_ONLY
84
97
  bool add_standard_groups();
85
98
  bool add_standard_tables() const;
86
99
 
87
 
  bool create_table(const sharedptr<const TableInfo>& table_info, const Document_Glom::type_vecFields& fields) const;
88
 
  bool create_table_add_missing_fields(const sharedptr<const TableInfo>& table_info, const Document_Glom::type_vecFields& fields) const;
 
100
  bool create_table(const sharedptr<const TableInfo>& table_info, const Document::type_vec_fields& fields) const;
 
101
  bool create_table_add_missing_fields(const sharedptr<const TableInfo>& table_info, const Document::type_vec_fields& fields) const;
89
102
 
90
103
  /// Also saves the table information in the document:
91
104
  bool create_table_with_default_fields(const Glib::ustring& table_name);
92
105
 
 
106
  // TODO: Should these functions update the document, so callers don't need
 
107
  // to do it?
 
108
  bool add_column(const Glib::ustring& table_name, const sharedptr<const Field>& field, Gtk::Window* parent_window) const;
 
109
 
 
110
  bool drop_column(const Glib::ustring& table_name, const Glib::ustring& field_name, Gtk::Window* parent_window) const;
 
111
 
 
112
  sharedptr<Field> change_column(const Glib::ustring& table_name, const sharedptr<const Field>& field_old, const sharedptr<const Field>& field, Gtk::Window* parent_window) const;
 
113
 
 
114
  bool change_columns(const Glib::ustring& table_name, const type_vec_const_fields& old_fields, type_vec_fields& fields, Gtk::Window* parent_window) const;
 
115
 
93
116
  bool insert_example_data(const Glib::ustring& table_name) const;
94
117
 
 
118
#endif //GLOM_ENABLE_CLIENT_ONLY
 
119
 
 
120
  //TODO: This is not a very good place for this function.
 
121
  /// Get the active layout platform for the document, or get a suitable default.
 
122
  static Glib::ustring get_active_layout_platform(Document* document);
 
123
 
95
124
  typedef std::vector< sharedptr<LayoutItem_Field> > type_vecLayoutFields;
96
125
  typedef std::vector< sharedptr<const LayoutItem_Field> > type_vecConstLayoutFields;
97
126
 
98
127
protected:
99
 
  sharedptr<LayoutItem_Field> offer_field_list(const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
100
 
  sharedptr<LayoutItem_Field> offer_field_list(const sharedptr<const LayoutItem_Field>& start_field, const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
 
128
 
 
129
  typedef std::list< sharedptr<LayoutItem_Field> > type_list_field_items;
 
130
  typedef std::list< sharedptr<const LayoutItem_Field> > type_list_const_field_items;
 
131
 
101
132
#ifndef GLOM_ENABLE_CLIENT_ONLY
 
133
  /** Allow the user to select a field from the list of fields for the table.
 
134
   */
 
135
  sharedptr<LayoutItem_Field> offer_field_list_select_one_field(const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
 
136
  
 
137
  /** Allow the user to select a field from the list of fields for the table, 
 
138
   * with @a start_field selected by default.
 
139
   */
 
140
  sharedptr<LayoutItem_Field> offer_field_list_select_one_field(const sharedptr<const LayoutItem_Field>& start_field, const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
 
141
  
 
142
  
 
143
  /** Allow the user to select fields from the list of fields for the table.
 
144
   */
 
145
  type_list_field_items offer_field_list(const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
 
146
  
 
147
 
102
148
  sharedptr<LayoutItem_Field> offer_field_formatting(const sharedptr<const LayoutItem_Field>& start_field, const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
103
149
  sharedptr<LayoutItem_Text> offer_textobject(const sharedptr<LayoutItem_Text>& start_textobject, Gtk::Window* transient_for = 0, bool show_title = true);
104
150
  sharedptr<LayoutItem_Image> offer_imageobject(const sharedptr<LayoutItem_Image>& start_imageobject, Gtk::Window* transient_for = 0, bool show_title = true);
110
156
 
111
157
  void fill_full_field_details(const Glib::ustring& parent_table_name, sharedptr<LayoutItem_Field>& layout_item);
112
158
 
113
 
  typedef std::vector<Glib::ustring> type_vecStrings;
114
 
  type_vecStrings get_table_names_from_database(bool ignore_system_tables = false) const;
 
159
  typedef std::vector<Glib::ustring> type_vec_strings;
 
160
  type_vec_strings get_table_names_from_database(bool ignore_system_tables = false) const;
115
161
 
116
162
  bool get_table_exists_in_database(const Glib::ustring& table_name) const;
117
163
  bool get_relationship_exists(const Glib::ustring& table_name, const Glib::ustring& relationship_name);
118
164
 
119
 
  type_vecFields get_fields_for_table(const Glib::ustring& table_name, bool including_system_fields = false) const;
 
165
  /** Get all the fields for a table, including any from the datasbase that are not yet known in the document.
 
166
   *
 
167
   * @param table_name The name of the table whose fields should be listed.
 
168
   * @param including_system_fields Whether extra non-user-visible fields should be included in the list.
 
169
   * @result A list of fields.
 
170
   */
 
171
  type_vec_fields get_fields_for_table(const Glib::ustring& table_name, bool including_system_fields = false) const;
 
172
 
 
173
  /** Get a single field definition for a table, even if the field is in the datasbase but not yet known in the document.
 
174
   *
 
175
   * @param table_name The name of the table whose fields should be listed.
 
176
   * @param field_name The name of the field for which to get the definition.
 
177
   * @result The field definition.
 
178
   */
120
179
  sharedptr<Field> get_fields_for_table_one_field(const Glib::ustring& table_name, const Glib::ustring& field_name) const;
121
180
 
122
181
  sharedptr<Field> get_field_primary_key_for_table(const Glib::ustring& table_name) const;
140
199
    {
141
200
    }
142
201
 
143
 
    FieldInRecord(const sharedptr<const LayoutItem_Field>& layout_item, const Glib::ustring& parent_table_name, const sharedptr<const Field>& parent_key, const Gnome::Gda::Value& key_value, const Document_Glom& document)
 
202
    FieldInRecord(const sharedptr<const LayoutItem_Field>& layout_item, const Glib::ustring& parent_table_name, const sharedptr<const Field>& parent_key, const Gnome::Gda::Value& key_value, const Document& document)
144
203
    : m_key_value(key_value)
145
204
    {
146
205
      m_field = layout_item->get_full_field_details();
199
258
      m_key = parent_key;
200
259
    }
201
260
 
202
 
    FieldInRecord get_fieldinrecord(const Document_Glom& document) const
 
261
    FieldInRecord get_fieldinrecord(const Document& document) const
203
262
    {
204
263
      return FieldInRecord(m_field, m_table_name, m_key, m_key_value, document);
205
264
    }
223
282
 
224
283
  typedef std::map<Glib::ustring, CalcInProgress> type_field_calcs;
225
284
 
226
 
  typedef std::list< sharedptr<LayoutItem_Field> > type_list_field_items;
227
 
  typedef std::list< sharedptr<const LayoutItem_Field> > type_list_const_field_items;
228
285
 
229
286
  /** Get the fields whose values should be recalculated when @a field_name changes.
230
287
   */
303
360
 
304
361
  virtual void on_userlevel_changed(AppState::userlevels userlevel);
305
362
 
306
 
  type_vecLayoutFields get_table_fields_to_show_for_sequence(const Glib::ustring& table_name, const Document_Glom::type_list_layout_groups& mapGroupSequence) const;
307
 
  void get_table_fields_to_show_for_sequence_add_group(const Glib::ustring& table_name, const Privileges& table_privs, const type_vecFields& all_db_fields, const sharedptr<LayoutGroup>& group, type_vecLayoutFields& vecFields) const;
 
363
  type_vecLayoutFields get_table_fields_to_show_for_sequence(const Glib::ustring& table_name, const Document::type_list_layout_groups& mapGroupSequence) const;
 
364
  void get_table_fields_to_show_for_sequence_add_group(const Glib::ustring& table_name, const Privileges& table_privs, const type_vec_fields& all_db_fields, const sharedptr<LayoutGroup>& group, type_vecLayoutFields& vecFields) const;
308
365
 
309
366
  /** Get the relationship into which the row button should navigate,
310
367
   * or the relationship itself, if the navigation_main output parameter is set to true after calling this method.
325
382
   */
326
383
  void set_found_set_where_clause_for_portal(FoundSet& found_set, const sharedptr<LayoutItem_Portal>& portal, const Gnome::Gda::Value& foreign_key_value);
327
384
 
 
385
  /** Update GDA's information about the table structure, such as the 
 
386
   * field list and their types.
 
387
   * Call this whenever changing the table structure, for instance with an ALTER query.
 
388
   * This may take a few seconds to return.
 
389
   */
 
390
  void update_gda_metastore_for_table(const Glib::ustring& table_name) const;
 
391
  
 
392
  static Glib::RefPtr<Gnome::Gda::Connection> get_connection();
328
393
 
329
 
  static bool get_field_primary_key_index_for_fields(const type_vecFields& fields, guint& field_column);
 
394
  static bool get_field_primary_key_index_for_fields(const type_vec_fields& fields, guint& field_column);
330
395
  static bool get_field_primary_key_index_for_fields(const type_vecLayoutFields& fields, guint& field_column);
331
396
 
332
 
  static type_vecStrings util_vecStrings_from_Fields(const type_vecFields& fields);
 
397
  static type_vec_strings util_vecStrings_from_Fields(const type_vec_fields& fields);
 
398
 
 
399
  /** Add a @a user to the database, with the specified @a password, in the specified @a group.
 
400
   * @result true if the addition succeeded.
 
401
   */
 
402
  bool add_user(const Glib::ustring& user, const Glib::ustring& password, const Glib::ustring& group);
 
403
 
 
404
  /** Remove the @a user from the database.
 
405
   * @result true if the removal succeeded.
 
406
   */
 
407
  bool remove_user(const Glib::ustring& user);
 
408
 
 
409
  bool remove_user_from_group(const Glib::ustring& user, const Glib::ustring& group);
 
410
 
 
411
  bool set_database_owner_user(const Glib::ustring& user);
 
412
 
 
413
  /** Revoke any login rights from the user and remove it from any groups.
 
414
   * This is a workaround for these problems:
 
415
   * 1. We can only specify a superuser _user_, not a role, to initdb (because it needs a password, but groups have no password),
 
416
   *    so that user is then the owner of various objects.
 
417
   * 2. Even when changing the owner of these objects we still get this error "cannot drop role glom_default_developer_user because it is required by the database system"
 
418
   */
 
419
  bool disable_user(const Glib::ustring& user);
333
420
 
334
421
 
335
422
  static void handle_error(const Glib::Exception& ex);