Commit bfebf7fc authored by Armin Burgmeier's avatar Armin Burgmeier Committed by Armin Burgmeier
Browse files

Merged changes from the GLOM_LIBGDA3 branch. Glom now builds against the

2007-05-08  Armin Burgmeier  <armin@openismus.com>

	* several files: Merged changes from the GLOM_LIBGDA3 branch. Glom now
	builds against the new libgda and pygda API. See the ChangeLog in that
	branch for a more detailed view of what has exactly changed.

svn path=/trunk/; revision=1102
parent fc8ec51a
2007-05-08 Armin Burgmeier <armin@openismus.com>
* several files: Merged changes from the GLOM_LIBGDA3 branch. Glom now
builds against the new libgda and pygda API. See the ChangeLog in that
branch for a more detailed view of what has exactly changed.
2007-05-01 Armin Burgmeier <armin@openismus.com>
* glom/application.cc: Do not leak the file chooser dialog in
......
libgda 3.0:
* glom/mode_design/fields/box_db_table_definition.cc:590: There is a Gnome::Gda::TransactionIsolation parameter I have absolutely no clue about. We should either find out what it is supposed to do and/or provide some reasonable default in libgdamm.
* Creating databases (frame_glom.cc, create_database()) sometimes fails due to the source database "template1" already being in use. A two-second-sleep seems to have improved chance that it works, but it is a) still not really reliable and b) a damn hack
......@@ -50,7 +50,7 @@ AC_LANG_CPLUSPLUS
# Checks for libraries
# We need libgnome only for gnome_help_display().:
PKG_CHECK_MODULES(GLOM, bakery-2.4 >= 2.3.18 gtkmm-2.4 >= 2.10 gthread-2.0 gnome-vfsmm-2.6 >= 2.11.1 libgnomecanvasmm-2.6 >= 2.10.0 libxslt >= 1.1.10 pygda-1.2 pygtk-2.0 >= 2.6.0 libgnome-2.0 >= 2.6.0 iso-codes libgdamm-2.0 >= 1.3.7 libgtksourceviewmm-1.0 libgda >= 1.2.4 avahi-glib goocanvas)
PKG_CHECK_MODULES(GLOM, bakery-2.4 >= 2.3.18 gtkmm-2.4 >= 2.10 gthread-2.0 gnome-vfsmm-2.6 >= 2.11.1 libgnomecanvasmm-2.6 >= 2.10.0 libxslt >= 1.1.10 pygda-3.0 pygtk-2.0 >= 2.6.0 libgnome-2.0 >= 2.6.0 iso-codes libgdamm-3.0 libgtksourceviewmm-1.0 libgda-3.0 >= 3.0.0 avahi-glib goocanvas)
GLOM_LIBS+=" --no-undefined"
AC_SUBST(GLOM_CFLAGS)
......
......@@ -193,8 +193,21 @@ Glib::RefPtr<Gnome::Gda::DataModel> Base_DB::query_execute(const Glib::ustring&
std::cout << "Debug: query string could not be converted to std::cout: " << ex.what() << std::endl;
}
}
result = gda_connection->execute_single_command(strQuery);
// TODO: Several functions call query_execute with non-select queries.
// Before libgda-3.0, execute_single_command returned always a datamodel
// on success. In case of a successful non-select command, we therefore
// create an empty datamodel to return, to make clear that the function
// succeeded. Probably, we should introduce another
// query_execute_non_select in the long term.
if(strQuery.compare(0, 6, "SELECT") == 0)
result = gda_connection->execute_select_command(strQuery);
else
{
if(gda_connection->execute_non_select_command(strQuery) != -1)
result = Gnome::Gda::DataModelArray::create(1);
}
if(!result)
{
std::cerr << "Glom Base_DB::query_execute(): Error while executing SQL" << std::endl <<
......@@ -255,7 +268,7 @@ Base_DB::type_vecStrings Base_DB::get_table_names_from_database(bool ignore_syst
//Get the table name:
Glib::ustring table_name;
if(value.get_value_type() == Gnome::Gda::VALUE_TYPE_STRING)
if(G_VALUE_TYPE(value.gobj()) == G_TYPE_STRING)
{
table_name = value.get_string();
......@@ -387,9 +400,10 @@ Base_DB::type_vecFields Base_DB::get_fields_for_table_from_database(const Glib::
{
Glib::RefPtr<Gnome::Gda::Connection> connection = sharedconnection->get_gda_connection();
Gnome::Gda::Parameter param_table_name("name", table_name);
Gnome::Gda::ParameterList param_list;
param_list.add_parameter(param_table_name);
Glib::RefPtr<Gnome::Gda::Parameter> param_table_name = Gnome::Gda::Parameter::create("name", table_name);
//Gnome::Gda::Parameter param_table_name("name", table_name);
Glib::RefPtr<Gnome::Gda::ParameterList> param_list = Gnome::Gda::ParameterList::create();
param_list->add_parameter(param_table_name);
Glib::RefPtr<Gnome::Gda::DataModel> data_model_fields = connection->get_schema(Gnome::Gda::CONNECTION_SCHEMA_FIELDS, param_list);
......@@ -411,22 +425,22 @@ Base_DB::type_vecFields Base_DB::get_fields_for_table_from_database(const Glib::
guint rows_count = data_model_fields->get_n_rows();
while(row < rows_count)
{
Gnome::Gda::FieldAttributes field_info;
Glib::RefPtr<Gnome::Gda::Column> field_info = Gnome::Gda::Column::create();
//Get the field name:
Gnome::Gda::Value value_name = data_model_fields->get_value_at(DATAMODEL_FIELDS_COL_NAME, row);
if(value_name.get_value_type() == Gnome::Gda::VALUE_TYPE_STRING)
if(value_name.get_value_type() == G_TYPE_STRING)
{
if(value_name.get_string().empty())
g_warning("Base_DB::get_fields_for_table_from_database(): value_name is empty.");
field_info.set_name( value_name.get_string() ); //TODO: get_string() is a dodgy choice. murrayc.
field_info->set_name( value_name.get_string() ); //TODO: get_string() is a dodgy choice. murrayc.
}
//Get the field type:
//This is a string representation of the type, so we need to discover the Gnome::Gda::ValueType for it:
//This is a string representation of the type, so we need to discover the GType for it:
Gnome::Gda::Value value_fieldtype = data_model_fields->get_value_at(DATAMODEL_FIELDS_COL_TYPE, row);
if(value_fieldtype.get_value_type() == Gnome::Gda::VALUE_TYPE_STRING)
if(value_fieldtype.get_value_type() == G_TYPE_STRING)
{
Glib::ustring schema_type_string = value_fieldtype.get_string();
if(!schema_type_string.empty())
......@@ -435,8 +449,8 @@ Base_DB::type_vecFields Base_DB::get_fields_for_table_from_database(const Glib::
const FieldTypes* pFieldTypes = connection_pool->get_field_types();
if(pFieldTypes)
{
Gnome::Gda::ValueType gdatype = pFieldTypes->get_gdavalue_for_schema_type_string(schema_type_string);
field_info.set_gdatype(gdatype);
GType gdatype = pFieldTypes->get_gdavalue_for_schema_type_string(schema_type_string);
field_info->set_g_type(gdatype);
}
}
}
......@@ -444,33 +458,33 @@ Base_DB::type_vecFields Base_DB::get_fields_for_table_from_database(const Glib::
//Get the default value:
/* libgda does not return this correctly yet. TODO: check bug http://bugzilla.gnome.org/show_bug.cgi?id=143576
Gnome::Gda::Value value_defaultvalue = data_model_fields->get_value_at(DATAMODEL_FIELDS_COL_DEFAULTVALUE, row);
if(value_defaultvalue.get_value_type() == Gnome::Gda::VALUE_TYPE_STRING)
field_info.set_default_value(value_defaultvalue);
if(value_defaultG_VALUE_TYPE(value.gobj()) == G_TYPE_STRING)
field_info->set_default_value(value_defaultvalue);
*/
//Get whether it can be null:
Gnome::Gda::Value value_notnull = data_model_fields->get_value_at(DATAMODEL_FIELDS_COL_NOTNULL, row);
if(value_notnull.get_value_type() == Gnome::Gda::VALUE_TYPE_BOOLEAN)
field_info.set_allow_null(value_notnull.get_bool());
if(value_notnull.get_value_type() == G_TYPE_BOOLEAN)
field_info->set_allow_null(value_notnull.get_boolean());
//Get whether it is a primary key:
Gnome::Gda::Value value_primarykey = data_model_fields->get_value_at(DATAMODEL_FIELDS_COL_PRIMARYKEY, row);
if(value_primarykey.get_value_type() == Gnome::Gda::VALUE_TYPE_BOOLEAN)
field_info.set_primary_key( value_primarykey.get_bool() );
if(value_primarykey.get_value_type() == G_TYPE_BOOLEAN)
field_info->set_primary_key( value_primarykey.get_boolean() );
//Get whether it is unique
Gnome::Gda::Value value_unique = data_model_fields->get_value_at(DATAMODEL_FIELDS_COL_UNIQUEINDEX, row);
if(value_unique.get_value_type() == Gnome::Gda::VALUE_TYPE_BOOLEAN)
field_info.set_unique_key( value_unique.get_bool() );
else if(field_info.get_primary_key()) //All primaries keys are unique, so force this.
field_info.set_unique_key();
if(value_unique.get_value_type() == G_TYPE_BOOLEAN)
field_info->set_unique_key( value_unique.get_boolean() );
else if(field_info->get_primary_key()) //All primaries keys are unique, so force this.
field_info->set_unique_key();
//Get whether it is autoincrements
/* libgda does not provide this yet.
Gnome::Gda::Value value_autoincrement = data_model_fields->get_value_at(DATAMODEL_FIELDS_COL_AUTOINCREMENT, row);
if(value_autoincrement.get_value_type() == Gnome::Gda::VALUE_TYPE_BOOLEAN)
field_info.set_auto_increment( value_autoincrement.get_bool() );
if(value_autoincrement.get_value_type() == G_TYPE_BOOLEAN)
field_info->set_auto_increment( value_autoincrement.get_bool() );
*/
sharedptr<Field> field(new Field()); //TODO: Get glom-specific information from the document?
......@@ -521,19 +535,19 @@ Base_DB::type_vecFields Base_DB::get_fields_for_table(const Glib::ustring& table
if(iterFindDatabase != fieldsDatabase.end() ) //Ignore fields that don't exist in the database anymore.
{
Gnome::Gda::FieldAttributes field_info_document = field->get_field_info();
Glib::RefPtr<Gnome::Gda::Column> field_info_document = field->get_field_info();
//Update the Field information that _might_ have changed in the database.
Gnome::Gda::FieldAttributes field_info = (*iterFindDatabase)->get_field_info();
Glib::RefPtr<Gnome::Gda::Column> field_info = (*iterFindDatabase)->get_field_info();
//libgda does not tell us whether the field is auto_incremented, so we need to get that from the document.
field_info.set_auto_increment( field_info_document.get_auto_increment() );
field_info->set_auto_increment( field_info_document->get_auto_increment() );
//libgda does not tell us whether the field is auto_incremented, so we need to get that from the document.
field_info.set_primary_key( field_info_document.get_primary_key() );
field_info->set_primary_key( field_info_document->get_primary_key() );
//libgda does yet tell us correct default_value information so we need to get that from the document.
field_info.set_default_value( field_info_document.get_default_value() );
field_info->set_default_value( field_info_document->get_default_value() );
field->set_field_info(field_info);
......@@ -918,8 +932,8 @@ bool Base_DB::create_table_with_default_fields(const Glib::ustring& table_name)
field_primary_key->set_primary_key();
field_primary_key->set_auto_increment();
Gnome::Gda::FieldAttributes field_info = field_primary_key->get_field_info();
field_info.set_allow_null(false);
Glib::RefPtr<Gnome::Gda::Column> field_info = field_primary_key->get_field_info();
field_info->set_allow_null(false);
field_primary_key->set_field_info(field_info);
field_primary_key->set_glom_type(Field::TYPE_NUMERIC);
......@@ -1005,8 +1019,8 @@ bool Base_DB::create_table(const sharedptr<const TableInfo>& table_info, const D
//The field has no gda type, so we set that:
//This usually comes from the database, but that's a bit strange.
Gnome::Gda::FieldAttributes info = field->get_field_info();
info.set_gdatype( Field::get_gda_type_for_glom_type(field->get_glom_type()) );
Glib::RefPtr<Gnome::Gda::Column> info = field->get_field_info();
info->set_g_type( Field::get_gda_type_for_glom_type(field->get_glom_type()) );
field->set_field_info(info); //TODO_Performance
Glib::ustring sql_field_description = "\"" + field->get_name() + "\" " + field->get_sql_type();
......@@ -1029,7 +1043,7 @@ bool Base_DB::create_table(const sharedptr<const TableInfo>& table_info, const D
//Actually create the table
try
{
Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute( "CREATE TABLE \"" + table_info->get_name() + "\" (" + sql_fields + ")" );
Glib::RefPtr<Gnome::Gda::DataModel> data_model = query_execute( "CREATE TABLE \"" + table_info->get_name() + "\" (" + sql_fields + ");" );
if(!data_model)
table_creation_succeeded = false;
else
......@@ -1853,7 +1867,7 @@ Base_DB::type_map_fields Base_DB::get_record_field_values_for_calculation(const
//Never give a NULL-type value to the python calculation for types that don't use them:
//to prevent errors:
if(value.get_value_type() == Gnome::Gda::VALUE_TYPE_NULL)
if(value.is_null())
value = Conversions::get_empty_value(field->get_glom_type());
field_values[field->get_name()] = value;
......
......@@ -106,7 +106,7 @@ Box_DB_Table::type_vecFields Box_DB_Table::get_fields_for_datamodel(const Glib::
int columns = data_model->get_n_columns();
for(int i = 0; i < columns; ++i)
{
Gnome::Gda::FieldAttributes fieldinfo = data_model->describe_column(i);
Glib::RefPtr<Gnome::Gda::Column> fieldinfo = data_model->describe_column(i);
sharedptr<Field> field(new Field());
field->set_field_info(fieldinfo); //TODO: Get glom-specific information from document?
result.push_back( field );
......@@ -116,7 +116,7 @@ Box_DB_Table::type_vecFields Box_DB_Table::get_fields_for_datamodel(const Glib::
}
*/
Glib::ustring Box_DB_Table::postgres_get_field_definition_for_sql(const Gnome::Gda::FieldAttributes& field_info)
Glib::ustring Box_DB_Table::postgres_get_field_definition_for_sql(const Glib::RefPtr<const Gnome::Gda::Column>& field_info)
{
Glib::ustring strResult;
......@@ -124,7 +124,7 @@ Glib::ustring Box_DB_Table::postgres_get_field_definition_for_sql(const Gnome::G
Glib::ustring strType = "unknowntype";
//Postgres has a special "serial" datatype. (MySQL uses a numeric type, and has an extra "AUTO_INCREMENT" command)
if(false) //disabled for now - see generate_next_auto_increment() //field_info.get_auto_increment())
if(false) //disabled for now - see generate_next_auto_increment() //field_info->get_auto_increment())
{
strType = "serial";
}
......@@ -136,7 +136,7 @@ Glib::ustring Box_DB_Table::postgres_get_field_definition_for_sql(const Gnome::G
const FieldTypes* pFieldTypes = pConnectionPool->get_field_types();
if(pFieldTypes)
{
const Gnome::Gda::ValueType fieldType = field_info.get_gdatype();
const GType fieldType = field_info->get_g_type();
strType = pFieldTypes->get_string_name_for_gdavaluetype(fieldType);
}
}
......@@ -188,23 +188,23 @@ Glib::ustring Box_DB_Table::postgres_get_field_definition_for_sql(const Gnome::G
*/
//Unique:
if(field_info.get_unique_key())
if(field_info->get_unique_key())
strResult += " UNIQUE";
/* Posgres needs us to do this separately
//Not Null:
if(!(field_info.get_allow_null()))
if(!(field_info->get_allow_null()))
strResult += " NOT NULL";
*/
//Default:
Gnome::Gda::Value valueDefault = field_info.get_default_value();
Gnome::Gda::Value valueDefault = field_info->get_default_value();
const Glib::ustring& strDefault = valueDefault.to_string();
if(!strDefault.empty() && strDefault != "NULL")
strResult += " DEFAULT " + strDefault; //TODO: Quote/Escape it if necessary.
//Primary Key:
if(field_info.get_primary_key())
if(field_info->get_primary_key())
strResult += " PRIMARY KEY";
return strResult;
......
......@@ -42,7 +42,7 @@ public:
virtual Glib::ustring get_table_name();
//TODO: Put this somewhere more sensible:
typedef std::map<Gnome::Gda::ValueType, Glib::ustring> type_map_valuetypes;
typedef std::map<GType, Glib::ustring> type_map_valuetypes;
protected:
......@@ -57,7 +57,7 @@ protected:
//static type_vecFields get_fields_for_datamodel(const Glib::RefPtr<Gnome::Gda::DataModel>& data_model);
static Glib::ustring postgres_get_field_definition_for_sql(const Gnome::Gda::FieldAttributes& field_info);
static Glib::ustring postgres_get_field_definition_for_sql(const Glib::RefPtr<const Gnome::Gda::Column>& field_info);
Glib::ustring m_table_name;
};
......
......@@ -60,10 +60,7 @@ void Dialog_InvalidData::set_example_data(Field::glom_field_type glom_type)
{
case(Field::TYPE_DATE):
{
Gnome::Gda::Date date = {0, 0, 0};
date.day = 31;
date.month = 1;
date.year = 2005;
Glib::Date date(31, Glib::Date::JANUARY, 2005);
example_text = Conversions::get_text_for_gda_value(glom_type, Gnome::Gda::Value(date));
break;
}
......
......@@ -1062,7 +1062,7 @@ void Frame_Glom::update_table_in_document_from_database()
//Add any new/changed information from the database to the document
//The database should never change without the knowledge of the document anyway, so this should be unnecessary.
//TODO_performance: There are a lot of temporary Field and FieldAttributes instances here, with a lot of string copying.
//TODO_performance: There are a lot of temporary Field and Column instances here, with a lot of string copying.
//For instance, changed field details, or new fields, or removed fields.
typedef Box_DB_Table::type_vecFields type_vecFields;
......@@ -1095,7 +1095,7 @@ void Frame_Glom::update_table_in_document_from_database()
else //if it was found.
{
//Compare the information:
Gnome::Gda::FieldAttributes field_info_db = field_database->get_field_info();
Glib::RefPtr<Gnome::Gda::Column> field_info_db = field_database->get_field_info();
sharedptr<Field> field_document = *iterFindDoc;
if(field_document)
{
......@@ -1104,7 +1104,7 @@ void Frame_Glom::update_table_in_document_from_database()
//The database has different information. We assume that the information in the database is newer.
//Update the field information:
field_info_db.set_auto_increment( field_document->get_auto_increment() ); //libgda does not report it from the database properly.
field_info_db->set_auto_increment( field_document->get_auto_increment() ); //libgda does not report it from the database properly.
(*iterFindDoc)->set_field_info( field_info_db );
document_must_to_be_updated = true;
......@@ -1648,6 +1648,9 @@ bool Frame_Glom::create_database(const Glib::ustring& database_name, const Glib:
}
else
{
// TODO: I don't think this is required anymore since libgda-3.0 because
// we do not need a connection to create a database. armin.
#if 0
//This must now succeed, because we've already tried it once:
sharedptr<SharedConnection> sharedconnection;
try
......@@ -1667,52 +1670,55 @@ bool Frame_Glom::create_database(const Glib::ustring& database_name, const Glib:
return false;
}
#endif
#if 1
// This seems to increase the change that the database creation does not
// fail due to the "source database is still in use" error. armin.
//std::cout << "Going to sleep" << std::endl;
Glib::usleep(500 * 1000);
//std::cout << "Awake" << std::endl;
#endif
if(sharedconnection)
{
Gtk::Window* pWindowApp = get_app_window();
g_assert(pWindowApp);
Gtk::Window* pWindowApp = get_app_window();
g_assert(pWindowApp);
Bakery::BusyCursor busycursor(*pWindowApp);
Bakery::BusyCursor busycursor(*pWindowApp);
//std::cout << "Frame_Glom::create_database(): debug: before calling sharedconnection->get_gda_connection." << std::endl;
try
{
ConnectionPool::get_instance()->create_database(database_name);
}
catch(const Glib::Exception& ex) // libgda does not set error domain
{
//I think a failure here might be caused by installing unstable libgda, which seems to affect stable libgda-1.2.
//Doing a "make install" in libgda-1.2 seems to fix this:
//TODO: Is this still relevant in libgda-3.0?
std::cerr << "Frame_Glom::create_database(): Gnome::Gda::Connection::create_database(" << database_name << ") failed: " << ex.what() << std::endl;
Glib::RefPtr<Gnome::Gda::Connection> connection = sharedconnection->get_gda_connection();
if(connection)
//Tell the user:
Gtk::Dialog* dialog = 0;
try
{
const bool test = connection->create_database(database_name);
if(!test)
{
//TODO: Discover the cause of the error somehow.
//I think a failure here might be caused by installing unstable libgda, which seems to affect stable libgda-1.2.
//Doing a "make install" in libgda-1.2 seems to fix this:
std::cerr << "Frame_Glom::create_database(): Gnome::Gda::Connection::create_database(" << database_name << ") failed." << std::endl;
//Tell the user:
Gtk::Dialog* dialog = 0;
try
{
Glib::RefPtr<Gnome::Glade::Xml> refXml = Gnome::Glade::Xml::create(GLOM_GLADEDIR "glom.glade", "dialog_error_create_database");
refXml->get_widget("dialog_error_create_database", dialog);
dialog->set_transient_for(*pWindowApp);
Glom::Utils::dialog_run_with_help(dialog, "dialog_error_create_database");
delete dialog;
}
catch(const Gnome::Glade::XmlError& ex)
{
std::cerr << ex.what() << std::endl;
}
return false;
}
//if(result)
//{
// std::cout << "Frame_Glom::create_database(): Creation succeeded: database_name=" << database_name << std::endl;
//}
// TODO: Tell the user what has gone wrong (ex.what())
Glib::RefPtr<Gnome::Glade::Xml> refXml = Gnome::Glade::Xml::create(GLOM_GLADEDIR "glom.glade", "dialog_error_create_database");
refXml->get_widget("dialog_error_create_database", dialog);
dialog->set_transient_for(*pWindowApp);
Glom::Utils::dialog_run_with_help(dialog, "dialog_error_create_database");
delete dialog;
}
catch(const Gnome::Glade::XmlError& ex)
{
std::cerr << ex.what() << std::endl;
}
return false;
}
//if(result)
//{
// std::cout << "Frame_Glom::create_database(): Creation succeeded: database_name=" << database_name << std::endl;
//}
}
//Connect to the actual database:
......
......@@ -27,10 +27,10 @@ bool GlomPostgres::postgres_add_column(const Glib::ustring& table_name, const sh
{
sharedptr<Field> field_to_add = glom_sharedptr_clone(field);
Gnome::Gda::FieldAttributes field_info = field_to_add->get_field_info();
if((field_info.get_gdatype() == Gnome::Gda::VALUE_TYPE_UNKNOWN) || (field_info.get_gdatype() == Gnome::Gda::VALUE_TYPE_NULL))
Glib::RefPtr<Gnome::Gda::Column> field_info = field_to_add->get_field_info();
if((field_info->get_g_type() == G_TYPE_NONE) || (field_info->get_g_type() == GDA_TYPE_NULL))
{
field_info.set_gdatype( Field::get_gda_type_for_glom_type(field_to_add->get_glom_type()) );
field_info->set_g_type( Field::get_gda_type_for_glom_type(field_to_add->get_glom_type()) );
field_to_add->set_field_info(field_info);
}
......@@ -49,8 +49,8 @@ bool GlomPostgres::postgres_add_column(const Glib::ustring& table_name, const sh
sharedptr<Field> GlomPostgres::postgres_change_column_extras(const Glib::ustring& table_name, const sharedptr<const Field>& field_old, const sharedptr<const Field>& field, bool set_anyway)
{
//Gnome::Gda::FieldAttributes field_info = field->get_field_info();
//Gnome::Gda::FieldAttributes field_info_old = field_old->get_field_info();
//Glib::RefPtr<Gnome::Gda::Column> field_info = field->get_field_info();
//Glib::RefPtr<Gnome::Gda::Column> field_info_old = field_old->get_field_info();
sharedptr<Field> result = glom_sharedptr_clone(field);
......@@ -166,7 +166,7 @@ sharedptr<Field> GlomPostgres::postgres_change_column_extras(const Glib::ustring
}
/* This should have been dealt with by postgres_change_column_type(), because postgres uses a different ("serial") field type for auto-incrementing fields.
if(field_info.get_auto_increment() != field_info_old.get_auto_increment())
if(field_info->get_auto_increment() != field_info_old.get_auto_increment())
{
}
......
......@@ -234,23 +234,24 @@ sharedptr<SharedConnection> ConnectionPool::connect()
bool try_another_port = true;
while(try_another_port)
{
const Glib::ustring cnc_string_main = "HOST=" + get_host() + ";USER=" + m_user + ";PASSWORD=" + m_password + ";PORT=" + port;
// const Glib::ustring cnc_string_main = "HOST=" + get_host() + ";USER=" + m_user + ";PASSWORD=" + m_password + ";PORT=" + port;
const Glib::ustring cnc_string_main = "HOST=" + get_host() + ";PORT=" + port;
Glib::ustring cnc_string = cnc_string_main;
if(!m_database.empty())
cnc_string += (";DATABASE=" + m_database);
cnc_string += (";DB_NAME=" + m_database);
else
cnc_string += (";DATABASE=" + default_database);
cnc_string += (";DB_NAME=" + default_database);
//std::cout << "debug: connecting: cnc string: " << cnc_string << std::endl;
std::cout << std::endl << "Glom: trying to connect on port=" << port << std::endl;
//*m_refGdaConnection = m_GdaClient->open_connection(m_GdaDataSourceInfo.get_name(), m_GdaDataSourceInfo.get_username(), m_GdaDataSourceInfo.get_password() );
//m_refGdaConnection.clear(); //Make sure any previous connection is really forgotten.
m_refGdaConnection = m_GdaClient->open_connection_from_string("PostgreSQL", cnc_string);
if(m_refGdaConnection)
try
{
m_refGdaConnection = m_GdaClient->open_connection_from_string("PostgreSQL", cnc_string, m_user, m_password);
//g_warning("ConnectionPool: connection opened");
//Remember what port is working:
......@@ -261,7 +262,7 @@ sharedptr<SharedConnection> ConnectionPool::connect()
m_pFieldTypes = new FieldTypes(m_refGdaConnection);
//Enforce ISO formats in the communication:
m_refGdaConnection->execute_single_command("SET DATESTYLE = 'ISO'");
m_refGdaConnection->execute_non_select_command("SET DATESTYLE = 'ISO'");
//Open the database, if one has been specified:
/* This does not seem to work in libgda's postgres provider, so we specify it in the cnc_string instead:
......@@ -271,11 +272,11 @@ sharedptr<SharedConnection> ConnectionPool::connect()
*/
//Get postgres version:
Glib::RefPtr<Gnome::Gda::DataModel> data_model = m_refGdaConnection->execute_single_command("SELECT version()");
Glib::RefPtr<Gnome::Gda::DataModel> data_model = m_refGdaConnection->execute_select_command("SELECT version()");
if(data_model && data_model->get_n_rows() && data_model->get_n_columns())
{
Gnome::Gda::Value value = data_model->get_value_at(0, 0);
if(value.get_value_type() == Gnome::Gda::VALUE_TYPE_STRING)
if(value.get_value_type() == G_TYPE_STRING)
{
const Glib::ustring version_text = value.get_string();
......@@ -295,9 +296,9 @@ sharedptr<SharedConnection> ConnectionPool::connect()
return connect(); //Call this method recursively. This time m_refGdaConnection exists.
}
else
catch(const Gnome::Gda::ConnectionError& ex)
{
std::cout << "ConnectionPool::connect() Attempt to connect to database failed on port=" << port << ", database=" << m_database << std::endl;
std::cout << "ConnectionPool::connect() Attempt to connect to database failed on port=" << port << ", database=" << m_database << ": " << ex.what() << std::endl;
bool bJustDatabaseMissing = false;
if(!m_database.empty())
......@@ -307,21 +308,22 @@ sharedptr<SharedConnection> ConnectionPool::connect()
//If the connection failed while looking for a database,
//then try connecting without the database:
Glib::ustring cnc_string = cnc_string_main;
cnc_string += (";DATABASE=" + default_database);
cnc_string += (";DB_NAME=" + default_database);
//std::cout << "debug2: connecting: cnc string: " << cnc_string << std::endl;
std::cout << "Glom: connecting." << std::endl;
Glib::RefPtr<Gnome::Gda::Connection> gda_connection = m_GdaClient->open_connection_from_string("PostgreSQL", cnc_string);
if(gda_connection) //If we could connect without specifying the database.
{
try
{
//If we could connect without specifying the database.
Glib::RefPtr<Gnome::Gda::Connection> gda_connection = m_GdaClient->open_connection_from_string("PostgreSQL", cnc_string, m_user, m_password);
bJustDatabaseMissing = true;
connection_to_default_database_possible = true;
m_port = port;
}
else
catch(const Gnome::Gda::ConnectionError& ex)
{
std::cerr << " ConnectionPool::connect() connection also failed when not specifying database." << std::endl;
std::cerr << " ConnectionPool::connect() connection also failed when not specifying database: " << ex.what() << std::endl;
}
}
......@@ -378,6 +380,20 @@ void ConnectionPool::set_self_hosted(const std::string& data_uri)
m_self_hosting_data_uri = data_uri;
}
void ConnectionPool::create_database(const Glib::ustring& database_name)
{
if(m_GdaClient)
{
Glib::RefPtr<Gnome::Gda::ServerOperation> op = m_GdaClient->prepare_create_database(database_name, "PostgreSQL");
g_assert(op);
op->set_value_at("/SERVER_CNX_P/HOST", get_host());
op->set_value_at("/SERVER_CNX_P/PORT", m_port);
op->set_value_at("/SERVER_CNX_P/ADM_LOGIN", get_user());
op->set_value_at("/SERVER_CNX_P/ADM_PASSWORD", get_password());
m_GdaClient->perform_create_database(op);
}
}
void ConnectionPool::set_host(const Glib::ustring& value)
{
if(value != m_host)
......@@ -412,6 +428,11 @@ Glib::ustring ConnectionPool::get_host() const
return m_host;
}
/*Glib::ustring ConnectionPool::get_port() const
{
return m_port;
}*/
Glib::ustring ConnectionPool::get_user() const
{
return m_user;
......@@ -462,8 +483,8 @@ bool ConnectionPool::handle_error(bool cerr_only)
{
Glib::RefPtr<Gnome::Gda::Connection> gda_connection = sharedconnection->get_gda_connection();