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

« back to all changes in this revision

Viewing changes to glom/libglom/data_structure/fieldtypes.cc

  • 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:
21
21
#include "fieldtypes.h"
22
22
#include <iostream> //For debug output
23
23
#include <libgda/gda-util.h> // For gda_g_type_to_string
24
 
#include <glom/libglom/connectionpool.h>
 
24
#include <libglom/connectionpool.h>
25
25
 
26
26
namespace Glom
27
27
{
29
29
FieldTypes::FieldTypes(const Glib::RefPtr<Gnome::Gda::Connection>& gda_connection)
30
30
{
31
31
  // These are documented here:
32
 
  // http://www.gnome-db.org/docs/libgda/libgda-provider-class.html#LIBGDA-PROVIDER-GET-SCHEMA
 
32
  // http://library.gnome.org/devel/libgda-4.0/3.99/connection.html#GdaConnectionMetaTypeHead
33
33
  enum GlomGdaDataModelTypesColumns
34
34
  {
35
35
    DATAMODEL_FIELDS_COL_NAME = 0,
36
 
    DATAMODEL_FIELDS_COL_OWNER = 1,
 
36
    DATAMODEL_FIELDS_COL_GTYPE = 1,
37
37
    DATAMODEL_FIELDS_COL_COMMENTS = 2,
38
 
    DATAMODEL_FIELDS_COL_GDATYPE = 3
 
38
    DATAMODEL_FIELDS_COL_SYNONYMS = 3
39
39
  };
40
40
  
41
41
  if(gda_connection && gda_connection->is_opened())
42
42
  {
43
 
    //Read the Types information, so that we can map the string representation of the type (returned by CONNECTION_SCHEMA_FIELDS) to
 
43
    //Read the Types information, so that we can map the string representation of the type (returned by CONNECTION_META_FIELDS) to
44
44
    //the Gda::ValueType used by Glib::RefPtr<Gnome::Gda::Column>.
 
45
    //This first call to update_meta_store() is also necessary for other calls to get_meta_store_data() elsewhere to succeed.
 
46
    Glib::RefPtr<Gnome::Gda::DataModel> data_model_tables;
45
47
#ifdef GLIBMM_EXCEPTIONS_ENABLED
46
 
    Glib::RefPtr<Gnome::Gda::DataModel> data_model_tables = gda_connection->get_schema(Gnome::Gda::CONNECTION_SCHEMA_TYPES);
 
48
    if(true) //Already done in ConnectionPool::connect(): gda_connection->update_meta_store())
 
49
      data_model_tables = gda_connection->get_meta_store_data(Gnome::Gda::CONNECTION_META_TYPES);
47
50
#else
48
51
    std::auto_ptr<Glib::Error> error;
49
 
    Glib::RefPtr<Gnome::Gda::DataModel> data_model_tables = gda_connection->get_schema(Gnome::Gda::CONNECTION_SCHEMA_TYPES, error);
 
52
    if(true) //Already done in ConnectionPool::connect(): gda_connection->update_meta_store(error))
 
53
      data_model_tables = gda_connection->get_meta_store_data(Gnome::Gda::CONNECTION_META_TYPES, error);
 
54
 
50
55
    // Ignore error here, we do not process data_model_tables if it is NULL
51
56
    // anyway
52
57
#endif // GLIBMM_EXCEPTIONS_ENABLED
 
58
 
 
59
    if(!data_model_tables)
 
60
      std::cerr << "FieldTypes::FieldTypes(): Couldn't get datamodel" << std::endl;
 
61
 
53
62
    if(data_model_tables && (data_model_tables->get_n_columns() == 0))
54
63
    {
55
 
      std::cerr << "FieldTypes::FieldTypes(): get_schema(Gnome::Gda::CONNECTION_SCHEMA_TYPES) failed." << std::endl;
 
64
      std::cerr << "FieldTypes::FieldTypes(): get_meta_store_data(Gnome::Gda::CONNECTION_META_TYPES) failed." << std::endl;
56
65
    }
57
66
    else if(data_model_tables)
58
67
    {
59
68
      int rows = data_model_tables->get_n_rows();
 
69
      if(!rows)
 
70
        std::cerr << "FieldTypes::FieldTypes(): no rows from CONNECTION_META_TYPES" << std::endl;
 
71
 
60
72
      for(int i = 0; i < rows; ++i)
61
73
      {
 
74
#ifdef GLIBMM_EXCEPTIONS_ENABLED
62
75
        const Gnome::Gda::Value value_name = data_model_tables->get_value_at(DATAMODEL_FIELDS_COL_NAME, i);
 
76
#else
 
77
        const Gnome::Gda::Value value_name = data_model_tables->get_value_at(DATAMODEL_FIELDS_COL_NAME, i, error);
 
78
#endif
63
79
 
64
80
        //Get the types's string representation:
65
81
        Glib::ustring schema_type_string;
66
82
        if(value_name.get_value_type() == G_TYPE_STRING)
67
83
          schema_type_string = value_name.get_string();
68
 
    
 
84
        
69
85
        if(!schema_type_string.empty())
70
86
        {
71
 
          Gnome::Gda::Value value_gdatype = data_model_tables->get_value_at(DATAMODEL_FIELDS_COL_GDATYPE, i);
72
 
          if(value_gdatype.get_value_type() == G_TYPE_ULONG) // TODO: I think this might change to G_TYPE_GTYPE in a future libgda
 
87
#ifdef GLIBMM_EXCEPTIONS_ENABLED
 
88
          Gnome::Gda::Value value_gdatype = data_model_tables->get_value_at(DATAMODEL_FIELDS_COL_GTYPE, i);
 
89
#else
 
90
          Gnome::Gda::Value value_gdatype = data_model_tables->get_value_at(DATAMODEL_FIELDS_COL_GTYPE, i, error);
 
91
#endif
 
92
          if(value_gdatype.get_value_type() == G_TYPE_STRING)
73
93
          {
74
 
            const GType gdatype = static_cast<GType>(value_gdatype.get_ulong());
 
94
            Glib::ustring type_string = value_gdatype.get_string();
 
95
            const GType gdatype = gda_g_type_from_string(type_string.c_str());
 
96
 
 
97
            //std::cout << "debug: schema_type_string=" << schema_type_string << ", gda type=" << gdatype << "(" << g_type_name(gdatype) << ")" << std::endl;
75
98
 
76
99
            //Save it for later:
77
 
            //std::cout << "debug: schema_type_string=" << schema_type_string << ", gda type=" << gdatype << "(" << g_type_name(gdatype) << ")" << std::endl;
78
 
            
79
100
            m_mapSchemaStringsToGdaTypes[schema_type_string] = gdatype;
80
101
 
81
102
            Glib::ustring gdatypestring = gda_g_type_to_string(gdatype); // TODO: What is this actually used for?
90
111
      }
91
112
    }
92
113
  }
 
114
 
 
115
  m_mapFallbackTypes[GDA_TYPE_BINARY] = GDA_TYPE_BLOB;
 
116
  m_mapFallbackTypes[GDA_TYPE_NUMERIC] = G_TYPE_DOUBLE;
 
117
  m_mapFallbackTypes[GDA_TYPE_TIME] = G_TYPE_STRING;
 
118
  m_mapFallbackTypes[G_TYPE_DATE] = G_TYPE_STRING;
93
119
}
94
120
 
95
121
FieldTypes::~FieldTypes()
98
124
 
99
125
GType FieldTypes::get_gdavalue_for_schema_type_string(const Glib::ustring& schema_type_string) const
100
126
{
 
127
  // Special case varchar, because we also specialized it in
 
128
  // get_string_name_for_gdavaluetype, so that we can properly convert back
 
129
  // and forth between sql typename and gda type.
 
130
  if(schema_type_string == "varchar")
 
131
    return G_TYPE_STRING;
 
132
 
101
133
  type_mapSchemaStringsToGdaTypes::const_iterator iterFind = m_mapSchemaStringsToGdaTypes.find(schema_type_string);
102
134
  if(iterFind == m_mapSchemaStringsToGdaTypes.end())
103
135
    return GDA_TYPE_NULL;
116
148
  type_mapGdaTypesToSchemaStrings::const_iterator iterFind = m_mapGdaTypesToSchemaStrings.find(field_type);
117
149
  if(iterFind == m_mapGdaTypesToSchemaStrings.end())
118
150
  {
119
 
    g_warning("FieldTypes::get_string_name_for_gdavaluetype(): returning unknowntype for field_type=%ld", static_cast<long>(field_type));
 
151
    type_mapFallbackTypes::const_iterator iterFallback = m_mapFallbackTypes.find(field_type);
 
152
    if(iterFallback != m_mapFallbackTypes.end())
 
153
      return get_string_name_for_gdavaluetype(iterFallback->second);
 
154
 
 
155
    g_warning("FieldTypes::get_string_name_for_gdavaluetype(): returning unknowntype for field_type=%ld (%s)", static_cast<long>(field_type), g_type_name(field_type));
120
156
 
121
157
    g_warning("  possible types are: ");
122
158
    for(type_mapGdaTypesToSchemaStrings::const_iterator iter = m_mapGdaTypesToSchemaStrings.begin(); iter != m_mapGdaTypesToSchemaStrings.end(); ++iter)
123
159
    {
124
 
      g_warning("    gdatype=%ld, sqltype=%s", static_cast<long>(iter->first), iter->second.c_str());
 
160
      g_warning("    gdatype=%ld (%s), sqltype=%s", static_cast<long>(iter->first), g_type_name(iter->first), iter->second.c_str());
125
161
    }
126
162
    
127
163
    return "unknowntype";
130
166
    return iterFind->second;
131
167
}
132
168
 
 
169
GType FieldTypes::get_fallback_type_for_gdavaluetype(GType field_type) const
 
170
{
 
171
  type_mapFallbackTypes::const_iterator iter = m_mapFallbackTypes.find(field_type);
 
172
  if(iter == m_mapFallbackTypes.end()) return G_TYPE_NONE;
 
173
  return iter->second;
 
174
}
 
175
 
133
176
} //namespace Glom
134
177
 
135
178