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>
68
68
static sharedptr<SharedConnection> connect_to_server(Gtk::Window* parent_window, std::auto_ptr<ExceptionConnection>& error);
69
69
#endif // GLIBMM_EXCEPTIONS_ENABLED
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
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;
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);
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.
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));
88
/** Execute a SQL non-select command, returning true if it succeeded.
89
* This method handles any Gda exceptions caused by executing the command.
91
static bool query_execute(const Glib::ustring& strQuery,
92
const Glib::RefPtr<Gnome::Gda::Set>& params = Glib::RefPtr<Gnome::Gda::Set>(0));
81
94
static int count_rows_returned_by(const Glib::ustring& sql_query);
96
#ifndef GLOM_ENABLE_CLIENT_ONLY
84
97
bool add_standard_groups();
85
98
bool add_standard_tables() const;
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;
90
103
/// Also saves the table information in the document:
91
104
bool create_table_with_default_fields(const Glib::ustring& table_name);
106
// TODO: Should these functions update the document, so callers don't need
108
bool add_column(const Glib::ustring& table_name, const sharedptr<const Field>& field, Gtk::Window* parent_window) const;
110
bool drop_column(const Glib::ustring& table_name, const Glib::ustring& field_name, Gtk::Window* parent_window) const;
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;
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;
93
116
bool insert_example_data(const Glib::ustring& table_name) const;
118
#endif //GLOM_ENABLE_CLIENT_ONLY
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);
95
124
typedef std::vector< sharedptr<LayoutItem_Field> > type_vecLayoutFields;
96
125
typedef std::vector< sharedptr<const LayoutItem_Field> > type_vecConstLayoutFields;
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);
129
typedef std::list< sharedptr<LayoutItem_Field> > type_list_field_items;
130
typedef std::list< sharedptr<const LayoutItem_Field> > type_list_const_field_items;
101
132
#ifndef GLOM_ENABLE_CLIENT_ONLY
133
/** Allow the user to select a field from the list of fields for the table.
135
sharedptr<LayoutItem_Field> offer_field_list_select_one_field(const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
137
/** Allow the user to select a field from the list of fields for the table,
138
* with @a start_field selected by default.
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);
143
/** Allow the user to select fields from the list of fields for the table.
145
type_list_field_items offer_field_list(const Glib::ustring& table_name, Gtk::Window* transient_for = 0);
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);
111
157
void fill_full_field_details(const Glib::ustring& parent_table_name, sharedptr<LayoutItem_Field>& layout_item);
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;
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);
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.
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.
171
type_vec_fields get_fields_for_table(const Glib::ustring& table_name, bool including_system_fields = false) const;
173
/** Get a single field definition for a table, even if the field is in the datasbase but not yet known in the document.
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.
120
179
sharedptr<Field> get_fields_for_table_one_field(const Glib::ustring& table_name, const Glib::ustring& field_name) const;
122
181
sharedptr<Field> get_field_primary_key_for_table(const Glib::ustring& table_name) const;
304
361
virtual void on_userlevel_changed(AppState::userlevels userlevel);
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;
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.
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);
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.
390
void update_gda_metastore_for_table(const Glib::ustring& table_name) const;
392
static Glib::RefPtr<Gnome::Gda::Connection> get_connection();
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);
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);
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.
402
bool add_user(const Glib::ustring& user, const Glib::ustring& password, const Glib::ustring& group);
404
/** Remove the @a user from the database.
405
* @result true if the removal succeeded.
407
bool remove_user(const Glib::ustring& user);
409
bool remove_user_from_group(const Glib::ustring& user, const Glib::ustring& group);
411
bool set_database_owner_user(const Glib::ustring& user);
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"
419
bool disable_user(const Glib::ustring& user);
335
422
static void handle_error(const Glib::Exception& ex);