glom r1564 - in branches/glom-1-6: . glom glom/libglom glom/libglom/data_structure glom/mode_data glom/utility_widgets/db_adddel
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: glom r1564 - in branches/glom-1-6: . glom glom/libglom glom/libglom/data_structure glom/mode_data glom/utility_widgets/db_adddel
- Date: Tue, 15 Apr 2008 12:05:14 +0100 (BST)
Author: murrayc
Date: Tue Apr 15 12:05:14 2008
New Revision: 1564
URL: http://svn.gnome.org/viewvc/glom?rev=1564&view=rev
Log:
2008-04-15 Murray Cumming <murrayc murrayc com>
* glom/libglom/data_structure/glomconversions.cc:
* glom/libglom/data_structure/glomconversions.h:
Added get_double_for_gda_value_numeric().
* glom/base_db.cc: auto_increment_insert_first_if_necessary(),
recalculate_next_auto_increment_value(),
get_next_auto_increment_value():
Return a GdaNumeric Gda::Value, not a string one, and
do the conversion without the locale affecting it.
* glom/utility_widgets/db_adddel/glom_db_treemodel.cc:
fill_values_if_necessary(): Create default values of the correct type.
* glom/libglom/utils.cc:
* glom/libglom/utils.h: Removed decimal_from_string() because it is
no longer used.
This avoids a warning about an incorrect type when adding a row in
the list view, and when adding a related record via a related field,
as seen in bug #526386 (Jani Monoses), though this does not completely
fix the main problem in that bug.
(This change was backported from svn trunk.)
Modified:
branches/glom-1-6/ChangeLog
branches/glom-1-6/glom/base_db.cc
branches/glom-1-6/glom/libglom/data_structure/glomconversions.cc
branches/glom-1-6/glom/libglom/data_structure/glomconversions.h
branches/glom-1-6/glom/libglom/utils.cc
branches/glom-1-6/glom/libglom/utils.h
branches/glom-1-6/glom/mode_data/box_data.cc
branches/glom-1-6/glom/utility_widgets/db_adddel/glom_db_treemodel.cc
Modified: branches/glom-1-6/glom/base_db.cc
==============================================================================
--- branches/glom-1-6/glom/base_db.cc (original)
+++ branches/glom-1-6/glom/base_db.cc Tue Apr 15 12:05:14 2008
@@ -852,9 +852,16 @@
else
{
//Return the value so that a calling function does not need to do a second SELECT.
- value = datamodel->get_value_at(0, 0);
+ const Gnome::Gda::Value actual_value = datamodel->get_value_at(0, 0);
+
+ //But the caller wants a numeric value not a text value
+ //(our system_autoincrements table has it as text, for future flexibility):
+ const std::string actual_value_text = actual_value.get_string();
+ bool success = false;
+ value = Conversions::parse_value(Field::TYPE_NUMERIC, actual_value_text, success, true /* iso_format */);
}
+ //std::cout << "Base_DB::auto_increment_insert_first_if_necessary: returning value of type=" << value.get_value_type() << std::endl;
return value;
}
@@ -869,8 +876,8 @@
if(datamodel && datamodel->get_n_rows() && datamodel->get_n_columns())
{
//Increment it:
- const Gnome::Gda::Value value_max = datamodel->get_value_at(0, 0);
- long num_max = Utils::decimal_from_string(value_max.to_string()); //TODO: Is this sensible? Probably not.
+ const Gnome::Gda::Value value_max = datamodel->get_value_at(0, 0); // A GdaNumeric.
+ double num_max = Conversions::get_double_for_gda_value_numeric(value_max);
++num_max;
//Set it in the glom system table:
@@ -895,8 +902,7 @@
Gnome::Gda::Value Base_DB::get_next_auto_increment_value(const Glib::ustring& table_name, const Glib::ustring& field_name) const
{
const Gnome::Gda::Value result = auto_increment_insert_first_if_necessary(table_name, field_name);
- long num_result = 0;
- num_result = Utils::decimal_from_string(result.to_string()); //TODO: Is this sensible? Probably not.
+ double num_result = Conversions::get_double_for_gda_value_numeric(result);
//Increment the next_value:
Modified: branches/glom-1-6/glom/libglom/data_structure/glomconversions.cc
==============================================================================
--- branches/glom-1-6/glom/libglom/data_structure/glomconversions.cc (original)
+++ branches/glom-1-6/glom/libglom/data_structure/glomconversions.cc Tue Apr 15 12:05:14 2008
@@ -169,6 +169,29 @@
return get_text_for_gda_value(glom_type, value, std::locale("") /* the user's current locale */, numeric_format); //Get the current locale.
}
+double Conversions::get_double_for_gda_value_numeric(const Gnome::Gda::Value& value)
+{
+ if(value.get_value_type() != GDA_TYPE_NUMERIC)
+ {
+ std::cerr << "Conversions::get_double_for_gda_value_numeric(): expected NUMERIC but GdaValue type is: " << g_type_name(value.get_value_type()) << std::endl;
+ return 0;
+ }
+
+ const GdaNumeric* gda_numeric = value.get_numeric();
+ std::string text_in_c_locale;
+ if(gda_numeric && gda_numeric->number) //A char* - I assume that it formatted as per the C locale. murrayc. TODO: Do we need to look at the other fields?
+ text_in_c_locale = gda_numeric->number; //What formatting does this use?
+
+ //Get an actual numeric value, so we can get a locale-specific text representation:
+ std::stringstream the_stream;
+ the_stream.imbue( std::locale::classic() ); //The C locale.
+ the_stream.str(text_in_c_locale); //Avoid using << because Glib::ustring does implicit character conversion with that.
+
+ double number = 0;
+ the_stream >> number;
+ return number;
+}
+
Glib::ustring Conversions::get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value& value, const std::locale& locale, const NumericFormat& numeric_format, bool iso_format)
{
if(value.is_null()) //The type can be null for any of the actual field types.
@@ -286,7 +309,7 @@
}
else
{
- std::cerr << "Conversions::get_text_for_gda_value(): Unexpected glom field type: " << glom_type << std::endl;
+ std::cerr << "Conversions::get_text_for_gda_value(): Unexpected glom field type: " << glom_type << ", gdatype=" << g_type_name(value.get_value_type()) << std::endl;
return value.to_string();
}
}
@@ -323,7 +346,7 @@
Gnome::Gda::Value Conversions::parse_value(Field::glom_field_type glom_type, const Glib::ustring& text, const NumericFormat& numeric_format, bool& success, bool iso_format)
{
- std::locale the_locale = (iso_format ? std::locale::classic() : std::locale("") /* The user's current locale */);
+ const std::locale the_locale = (iso_format ? std::locale::classic() : std::locale("") /* The user's current locale */);
//Put a NULL in the database for empty dates, times, and numerics, because 0 would be an actual value.
//But we use "" for strings, because the distinction between NULL and "" would not be clear to users.
@@ -383,7 +406,7 @@
//Try to parse the inputted number, according to the current locale.
std::stringstream the_stream;
- the_stream.imbue( the_locale ); //Parse it as per the current locale.
+ the_stream.imbue( the_locale ); //Parse it as per the specified locale.
the_stream.str(text_to_parse); //Avoid << because it does implicit character conversion (though that might not be a problem here. Not sure). murrayc
double the_number = 0;
the_stream >> the_number; //TODO: Does this throw any exception if the text is an invalid time?
Modified: branches/glom-1-6/glom/libglom/data_structure/glomconversions.h
==============================================================================
--- branches/glom-1-6/glom/libglom/data_structure/glomconversions.h (original)
+++ branches/glom-1-6/glom/libglom/data_structure/glomconversions.h Tue Apr 15 12:05:14 2008
@@ -37,6 +37,10 @@
Glib::ustring get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value& value, const NumericFormat& numeric_format = NumericFormat());
Glib::ustring get_text_for_gda_value(Field::glom_field_type glom_type, const Gnome::Gda::Value& value, const std::locale& locale, const NumericFormat& numeric_format = NumericFormat(), bool iso_format = false);
+ //This is easier than using the GdaNumeric API,
+ //which normally involves text-to-number parsing.
+ double get_double_for_gda_value_numeric(const Gnome::Gda::Value& value);
+
Glib::ustring format_time(const tm& tm_data);
Glib::ustring format_time(const tm& tm_data, const std::locale& locale, bool iso_format = false);
Glib::ustring format_date(const tm& tm_data);
Modified: branches/glom-1-6/glom/libglom/utils.cc
==============================================================================
--- branches/glom-1-6/glom/libglom/utils.cc (original)
+++ branches/glom-1-6/glom/libglom/utils.cc Tue Apr 15 12:05:14 2008
@@ -583,19 +583,6 @@
return result;
}
-guint Utils::decimal_from_string(const Glib::ustring& str)
-{
- //TODO_Performance:
-
- //Convert it to a numeric type:
- std::stringstream stream;
- stream << str;
- guint id_numeric = 0;
- stream >> id_numeric;
-
- return id_numeric;
-}
-
Glib::ustring Utils::title_from_string(const Glib::ustring& text)
{
Glib::ustring result;
Modified: branches/glom-1-6/glom/libglom/utils.h
==============================================================================
--- branches/glom-1-6/glom/libglom/utils.h (original)
+++ branches/glom-1-6/glom/libglom/utils.h Tue Apr 15 12:05:14 2008
@@ -80,8 +80,10 @@
Glib::ustring create_local_image_uri(const Gnome::Gda::Value& value);
+/** Get a decimal text representation of the number,
+ * in the current locale.
+ */
Glib::ustring string_from_decimal(guint decimal);
-guint decimal_from_string(const Glib::ustring& str);
/** Create an appropriate title for an ID string.
* For instance, date_of_birth would become Date Of Birth.
Modified: branches/glom-1-6/glom/mode_data/box_data.cc
==============================================================================
--- branches/glom-1-6/glom/mode_data/box_data.cc (original)
+++ branches/glom-1-6/glom/mode_data/box_data.cc Tue Apr 15 12:05:14 2008
@@ -451,7 +451,7 @@
//if(value.is_number())
// result = value.get_integer();
//else
- result = decimal_from_string(value.to_string());
+ result = get_double_for_gda_value_numeric(value);
++result;
}
@@ -750,11 +750,14 @@
//Create the related record:
if(key_is_auto_increment)
{
- primary_key_value = generate_next_auto_increment(relationship->get_to_table(), primary_key_field->get_name());
+ primary_key_value = get_next_auto_increment_value(relationship->get_to_table(), primary_key_field->get_name());
//Generate the new key value;
}
+ std::cout << "DEBUG: Box_Data::add_related_record_for_field(): primary_key_field: " << primary_key_field->get_name() << std::endl;
+ std::cout << " DEBUG:primary_key_value type=: " << g_type_name(primary_key_value.get_value_type()) << std::endl;
+
const Glib::ustring strQuery = "INSERT INTO \"" + relationship->get_to_table() + "\" (\"" + primary_key_field->get_name() + "\") VALUES (" + primary_key_field->sql(primary_key_value) + ")";
bool test = query_execute(strQuery, get_app_window());
if(test)
Modified: branches/glom-1-6/glom/utility_widgets/db_adddel/glom_db_treemodel.cc
==============================================================================
--- branches/glom-1-6/glom/utility_widgets/db_adddel/glom_db_treemodel.cc (original)
+++ branches/glom-1-6/glom/utility_widgets/db_adddel/glom_db_treemodel.cc Tue Apr 15 12:05:14 2008
@@ -280,6 +280,20 @@
//It must be the last blank placeholder row.
//m_placeholder = true;
}
+
+ //Create default values, if necessary, of the correct types:
+ //Examine the columns in the returned DataModel:
+ for(guint col = 0; col < model.m_data_model_columns_count; ++col)
+ {
+ if(m_db_values.find(col) == m_db_values.end()) //If there is not already a value in the map for this column.
+ {
+ Glib::RefPtr<Gnome::Gda::Column> column = model.m_gda_datamodel->describe_column(col);
+ Gnome::Gda::Value value;
+ value.init(column->get_g_type());
+ m_db_values[col] = value;
+ }
+ }
+
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]