Hi All,

I'm having lots of fun playing with the data module. One thing that strikes me is the need to support non-standard database field-types that are not supported by schemaAPI by default. I see Data playing a big role in hooking Drupal up to external databases, and not all external database implement the same field types that Drupal does. Data support for field types such as datetime, time, enum, geometry etc. would go a long-way towards making Drupal interoperability with external data-sources a breeze. Luckily schemaAPI has the functionality to extend it's field-type mappings:

$schemea['myfield] = array(
  'type' => 'abstracted_field_type',
  'mysql_type' => 'MAGIC_TYPE',
  'pgsql_type' => 'whatever',
);

I know that there is already talk here http://drupal.org/node/623974 of refactoring data_get_field_definitions. In my mind, it would make sense to hook the new data_get_field_definitions (or whatever replaces it) up to the "Create new table" UI (data_ui_create_form_submit in data_ui_admin.inc). In my mind this would be a perfect place to implement support for non-standard field types.

My particular interest in all this is managing geospatial data in Drupal. I've managed to hack things around a bit using variations on this:

$schemea['myfield] = array(
  'type' => 'geometry',
  'mysql_type' => 'geometry',
  'pgsql_type' => 'GEOMETRY',
);

This will allow you to store spatial geometry data in the database that can then be queried by the geo module and mapped by the openlayers module. Hacking things in seems to be working OK.

I'm also working on a module called Spatial Import to parse shapefiles and imports them into drupal using either Data or table-wizard. (It implements the Parser ctools plugin you guys created). I'm attaching it here if you are curious. I will be releasing it as a project when I have it cleaned up a little more.

Comments

alex_b’s picture

First off: I would be ready to include geospatial support in Data just like big text support.

Then:

Wouldn't non-default field types 'just work' by adding a hook for data_get_field_definitions() like proposed in #623974: Big text support?

You see how _data_ui_field_form() invokes data_get_field_definitions() indirectly and then later, on form submission, data_build_schema() uses indirectly data_get_field_definitions() again for building a full field spec?

I know, however, that this portion of Data is not ideal. The usage of the short handles defined in data_get_field_definitions() is half hearted and does not scale to the number of potential combinations of configurations.

I think what needs to be done is this:

- Definition of legal configurations of field specs built on: http://drupal.org/node/159605
- Use these definitions to validate the user input on create/edit forms (expose a type drop down, a size drop down, a unique check, a default text field, validate on submission and provide feedback to user).

I have not fully thought through this. Especially the use of fields as indexes and primary keys have some additional implications that I am not sure how to define in such a set of legal conifgurations.

phayes’s picture

StatusFileSize
new7.79 KB
new882 bytes

Attached is a patch that adds support (somewhat) for spatial data.

Basically you are correct, we need to define it in data_get_field_definitions, but we also need to add the same info into data_build_field_definition to help it along.

This allows us to create data tables with geometry, and add geometry fields to feed imports. So it let's us create the actual table. However, when we try and go import any spatial data, drupal_write_record fails because there is no 'geometry' type defined in db_type_placeholder. I think this limitation in drupal_write_record is fundamental. Likely, the only thing to do is to implement some sort of CRUD that doesn't use drupal_write_record, drupal_update_record etc.

Attached is also an update of my spatial_table module. It's coming along - you can now import shapefiles to WKT that can be mapped in views using openlayers. Depending on the status here, i'll likely release it without geometry support first (wkt only), then update it when this issue is sorted.

alex_b’s picture

Status: Active » Fixed

#2 is committed. Thanks.

Opened #636622: Refactor data_get_field_definitions() for the larger discussion on how to deal with data_get_field_definitions() / data_build_field_definition(). Input and patches welcome :)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.