glom r1900 - in trunk: . glom glom/libglom/data_structure
- From: murrayc svn gnome org
- To: svn-commits-list gnome org
- Subject: glom r1900 - in trunk: . glom glom/libglom/data_structure
- Date: Mon, 16 Feb 2009 14:18:59 +0000 (UTC)
Author: murrayc
Date: Mon Feb 16 14:18:58 2009
New Revision: 1900
URL: http://svn.gnome.org/viewvc/glom?rev=1900&view=rev
Log:
2009-02-10 Murray Cumming <murrayc murrayc com>
* glom/libglom/data_structure/field.[h|cc]: Renamed from_sql() to
from_file_format(), without the sql_format parameter, to make it
clearer. Added to_file_format(), which currently just calls sql()
with the postgres format.
* glom/data_structure/glomconversions.cc: Removed unused
unescape_binary_data_sqlite().
* glom/base_db.cc: insert_example_data():
* glom/dialog_import_csv.cc: field_data_func():
* glom/dialog_import_csv_progress.cc: on_idle_import(): Adapt.
* glom/frame_glom.cc: export_data_to_string(): Use to_file_format()
instead of sql() to make it clearer.
Modified:
trunk/ChangeLog
trunk/glom/base_db.cc
trunk/glom/dialog_import_csv.cc
trunk/glom/dialog_import_csv_progress.cc
trunk/glom/frame_glom.cc
trunk/glom/libglom/data_structure/field.cc
trunk/glom/libglom/data_structure/field.h
trunk/glom/libglom/data_structure/glomconversions.cc
trunk/glom/libglom/data_structure/glomconversions.h
Modified: trunk/glom/base_db.cc
==============================================================================
--- trunk/glom/base_db.cc (original)
+++ trunk/glom/base_db.cc Mon Feb 16 14:18:58 2009
@@ -1570,7 +1570,7 @@
strNames += vec_fields[i]->get_name();
bool success = false;
- const Gnome::Gda::Value value = vec_fields[i]->from_sql(vec_values[i], Field::SQL_FORMAT_POSTGRES, success);
+ const Gnome::Gda::Value value = vec_fields[i]->from_file_format(vec_values[i], success);
if(!success)
{
std::cerr << "Base_DB::insert_example_data: could not convert example data" << std::endl;
Modified: trunk/glom/dialog_import_csv.cc
==============================================================================
--- trunk/glom/dialog_import_csv.cc (original)
+++ trunk/glom/dialog_import_csv.cc Mon Feb 16 14:18:58 2009
@@ -910,7 +910,7 @@
if(field->get_glom_type() != Field::TYPE_IMAGE)
{
/* Exported data is always stored in postgres format */
- Gnome::Gda::Value value = field->from_sql(orig_text, Field::SQL_FORMAT_POSTGRES, success);
+ const Gnome::Gda::Value value = field->from_file_format(orig_text, success);
if(!success)
text = _("<Import Failure>");
Modified: trunk/glom/dialog_import_csv_progress.cc
==============================================================================
--- trunk/glom/dialog_import_csv_progress.cc (original)
+++ trunk/glom/dialog_import_csv_progress.cc Mon Feb 16 14:18:58 2009
@@ -148,7 +148,7 @@
// we export it this way.
// TODO: Document what that format is.
bool success = false;
- Gnome::Gda::Value value = field->from_sql(m_data_source->get_data(m_current_row, i), Field::SQL_FORMAT_POSTGRES, success);
+ Gnome::Gda::Value value = field->from_file_format(m_data_source->get_data(m_current_row, i), success);
if(success)
{
Modified: trunk/glom/frame_glom.cc
==============================================================================
--- trunk/glom/frame_glom.cc (original)
+++ trunk/glom/frame_glom.cc Mon Feb 16 14:18:58 2009
@@ -618,7 +618,7 @@
row_string += ",";
//Output data in canonical SQL format, ignoring the user's locale, and ignoring the layout formatting:
- row_string += layout_item->get_full_field_details()->sql(value, Field::SQL_FORMAT_POSTGRES);
+ row_string += layout_item->get_full_field_details()->to_file_format(value);
//if(layout_item->m_field.get_glom_type() == Field::TYPE_IMAGE) //This is too much data.
//{
@@ -670,7 +670,7 @@
row_string += ",";
//Output data in canonical SQL format, ignoring the user's locale, and ignoring the layout formatting:
- row_string += layout_item->get_full_field_details()->sql(value, Field::SQL_FORMAT_POSTGRES);
+ row_string += layout_item->get_full_field_details()->to_file_format(value);
if(layout_item->get_glom_type() == Field::TYPE_IMAGE) //This is too much data.
{
Modified: trunk/glom/libglom/data_structure/field.cc
==============================================================================
--- trunk/glom/libglom/data_structure/field.cc (original)
+++ trunk/glom/libglom/data_structure/field.cc Mon Feb 16 14:18:58 2009
@@ -420,13 +420,14 @@
{
if(value.get_value_type() == GDA_TYPE_BINARY)
{
- long buffer_length;
+ long buffer_length = 0;
const guchar* buffer = value.get_binary(buffer_length);
if(buffer && buffer_length > 0)
{
if(format == SQL_FORMAT_POSTGRES)
{
//Get the escaped text that represents the binary data:
+ //TODO: Use gda_binary_from_string() instead?
const std::string escaped_binary_data = Conversions::escape_binary_data_postgres((guint8*)buffer, buffer_length);
//Now escape that text (to convert \ to \\, for instance):
//The E prefix indicates ""escape" string constants, which are an extension to the SQL standard"
@@ -436,6 +437,7 @@
}
else
{
+ //TODO: Is this used for anything?
const std::string escaped_binary_data = Conversions::escape_binary_data_sqlite((guint8*)buffer, buffer_length);
str = "x'" + escaped_binary_data + "'";
}
@@ -467,7 +469,12 @@
return sql(value, format);
}
-Gnome::Gda::Value Field::from_sql(const Glib::ustring& str, sql_format format, bool& success) const
+Glib::ustring Field::to_file_format(const Gnome::Gda::Value& value) const
+{
+ return sql(value, Field::SQL_FORMAT_POSTGRES);
+}
+
+Gnome::Gda::Value Field::from_file_format(const Glib::ustring& str, bool& success) const
{
success = true;
switch(m_glom_type)
@@ -479,8 +486,10 @@
case TYPE_DATE:
case TYPE_TIME:
{
- if(str == "NULL") return Gnome::Gda::Value();
- Glib::ustring unescaped = glom_unescape_text(str);
+ if(str == "NULL")
+ return Gnome::Gda::Value();
+
+ const Glib::ustring unescaped = glom_unescape_text(str);
NumericFormat format_ignored; //Because we use ISO format.
return Conversions::parse_value(m_glom_type, unescaped, format_ignored, success, true);
@@ -495,7 +504,8 @@
{
if(str.lowercase() == "true")
return Gnome::Gda::Value(true);
- return Gnome::Gda::Value(false);
+ else
+ return Gnome::Gda::Value(false);
}
case TYPE_IMAGE:
{
@@ -508,9 +518,8 @@
const std::string& raw = str.raw();
Glib::ustring unescaped;
- switch(format)
+
{
- case SQL_FORMAT_POSTGRES:
if(raw.length() >= 10 &&
raw.compare(0, 2, "E'") == 0 && raw.compare(raw.length() - 8, 8, "'::bytea") == 0)
{
@@ -528,7 +537,8 @@
if(!unescaped.empty())
{
- gsize length;
+ gsize length = 0;
+ //TODO: Use gda_binary_to_string() instead?
guint8* binary_data = Conversions::unescape_binary_data_postgres(unescaped, length);
if(binary_data)
{
@@ -541,27 +551,6 @@
success = false;
return Gnome::Gda::Value();
- case SQL_FORMAT_SQLITE:
- if(raw.length() >= 3 &&
- (raw.compare(0, 2, "x'") == 0 || raw.compare(0, 2, "X'")) &&
- raw.compare(raw.length() - 1, 1, "'") == 0)
- {
- gsize length;
- guint8* binary_data = Conversions::unescape_binary_data_sqlite(raw.substr(2, raw.length()), length);
- if(binary_data)
- {
- Gnome::Gda::Value value;
- value.set(binary_data, length);
- g_free(binary_data);
- return value;
- }
- }
-
- success = false;
- return Gnome::Gda::Value();
- default:
- g_assert_not_reached();
- break;
}
}
default:
Modified: trunk/glom/libglom/data_structure/field.h
==============================================================================
--- trunk/glom/libglom/data_structure/field.h (original)
+++ trunk/glom/libglom/data_structure/field.h Mon Feb 16 14:18:58 2009
@@ -174,9 +174,15 @@
*/
Glib::ustring sql(const Gnome::Gda::Value& value) const;
- /** Unescape the value again.
+ /** Escape the value so that it can be used in a file, for instance for
+ * a default value or for example data.
+ * Uses the sql_format of the current connectionpool backend.
*/
- Gnome::Gda::Value from_sql(const Glib::ustring& str, sql_format format, bool& success) const;
+ Glib::ustring to_file_format(const Gnome::Gda::Value& value) const;
+
+ /** Unescape the value again. See to_file_format()
+ */
+ Gnome::Gda::Value from_file_format(const Glib::ustring& str, bool& success) const;
/** Escape the value so that it can be used in a SQL command for a find.
*/
Modified: trunk/glom/libglom/data_structure/glomconversions.cc
==============================================================================
--- trunk/glom/libglom/data_structure/glomconversions.cc (original)
+++ trunk/glom/libglom/data_structure/glomconversions.cc Mon Feb 16 14:18:58 2009
@@ -434,7 +434,7 @@
if(locale == std::locale("") /* The user's current locale */)
{
- //Converts from the user's current locale to utf8. I would prefer a generic conversion from any locale,
+ // Converts from the user's current locale to utf8. I would prefer a generic conversion from any locale,
// but there is no such function, and it's hard to do because I don't know how to get the encoding name from the std::locale()
#ifdef GLIBMM_EXCEPTIONS_ENABLED
text = Glib::locale_to_utf8(text);
@@ -444,6 +444,7 @@
#endif
}
+ //std::cout << "DEBUG: Conversions::get_text_for_gda_value(): number=" << number << ", text=" << text << std::endl;
return text; //Do something like Glib::locale_to_utf(), but with the specified locale instead of the current locale.
}
else if(glom_type == Field::TYPE_TEXT)
@@ -457,6 +458,7 @@
std::string result;
long buffer_length;
const guchar* buffer = value.get_binary(buffer_length);
+ //std::cout << "DEBUG: get_text_for_gda_value(): Calling Conversions::escape_binary_data_postgres(). This should probably not happen. murrayc." << std::endl;
if(buffer && buffer_length > 0)
result = Conversions::escape_binary_data_postgres((guint8*)buffer, buffer_length);
@@ -615,6 +617,7 @@
Gnome::Gda::Value result;
size_t buffer_binary_length = 0;
+ //std::cout << "DEBUG: parse_value(): Calling Conversions::unescape_binary_data_postgres(). This should probably not happen. murrayc." << std::endl;
guchar* buffer_binary = Conversions::unescape_binary_data_postgres(text, buffer_binary_length); //freed by us later.
if(buffer_binary)
{
@@ -1169,24 +1172,6 @@
return Glom_PQunescapeBytea((const guchar*)escaped_binary_data.c_str(), &length);
}
-guint8* Conversions::unescape_binary_data_sqlite(const Glib::ustring& escaped_binary_data, size_t& length)
-{
- g_assert(escaped_binary_data.bytes() % 2 == 0);
-
- length = escaped_binary_data.bytes()/2;
- const char* in_data = escaped_binary_data.c_str();
- // Use malloc here, since unescape_binary_data_postgres also uses malloc
- // in Glom_PQunescapeBytea and we want the API to stay consistent.
- guint8* out_data = static_cast<guint8*>(malloc(length));
- if(!out_data) { length = 0; return NULL; }
-
- // The sqlite format is two characters representing a byte in hexadecimal
- // notation.
- for(unsigned int i = 0; i < length; ++i)
- out_data[i] = chartohex(in_data[2*i] << 4) | chartohex(in_data[2*i+1]);
- return out_data;
-}
-
Gnome::Gda::Value Conversions::convert_value(const Gnome::Gda::Value& value, Field::glom_field_type target_glom_type)
{
const GType gvalue_type = value.get_value_type();
Modified: trunk/glom/libglom/data_structure/glomconversions.h
==============================================================================
--- trunk/glom/libglom/data_structure/glomconversions.h (original)
+++ trunk/glom/libglom/data_structure/glomconversions.h Mon Feb 16 14:18:58 2009
@@ -80,11 +80,13 @@
Gnome::Gda::Value get_example_value(Field::glom_field_type field_type);
+ //TODO: Use gda_binary_from_string() instead?
///Get a string representing binary data, for SQL
Glib::ustring escape_binary_data_postgres(guint8* buffer, size_t buffer_size);
Glib::ustring escape_binary_data_sqlite(guint8* buffer, size_t buffer_size);
+
+ //TODO: Use gda_binary_to_string() instead?
guint8* unescape_binary_data_postgres(const Glib::ustring& escaped_binary_data, size_t& length);
- guint8* unescape_binary_data_sqlite(const Glib::ustring& escaped_binary_data, size_t& length);
Gnome::Gda::Value convert_value(const Gnome::Gda::Value& value, Field::glom_field_type target_glom_type);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]