Support for array data type

17 views
Skip to first unread message

Sergiy Zuban

unread,
Feb 15, 2013, 6:22:24 PM2/15/13
to dbix-da...@googlegroups.com
Hello Laurent,

Some DBMS (like PostgreSQL) supports arrays and SQL::Abstract itself support them via array_datatypes => 1 option. See http://search.cpan.org/~frew/SQL-Abstract-1.73/lib/SQL/Abstract.pm#Inserting_and_Updating_Arrays
But DBIx::DataModel pre-validates data passed to update() and insert() methods and ignores arrays.

DBIx::DataModel::ConnectedSource:237-248
  $to_set->apply_column_handler('to_DB');

  # remove references to foreign objects
  # leave refs to SCALAR or REF because they are used by SQLA for verbatim SQL
  my @sub_refs = grep {my $reftype = reftype($to_set->{$_}) || '';
                       $reftype eq 'HASH' || $reftype eq 'ARRAY'}
                 grep {$_ ne '__schema'} keys %$to_set;
  if (@sub_refs) {
    carp "data passed to update() contained nested references : ",
      CORE::join ", ", @sub_refs;
    delete @{$to_set}{@sub_refs};
  }

Technically its quite simple to make $reftype eq 'ARRAY' check conditional on $schema->sql_abstract->{array_datatypes}
As another possible solution is to avoid extra validation if there are user defined to_DB/from_DB. This is probably not so safe, but more flexible to let users to pass everything they want to SQL::Abstract.
BTW, I was able to pass array to -where using the following syntax:

column => { '=' => \['?', \@array ] }

Please let me know if you have any plans to add support for arrays in the nearest future. Also I can try to make the changes myself and send you a patch for review. 

laurent dami

unread,
Feb 18, 2013, 10:09:54 PM2/18/13
to dbix-da...@googlegroups.com
Le 16.02.2013 00:22, Sergiy Zuban a �crit :
>
> Technically its quite simple to make $reftype eq 'ARRAY' check
> conditional on $schema->sql_abstract->{array_datatypes}
Hi Sergiy,

Thanks for the suggestion, I made the change.
Please pull from https://github.com/damil/DBIx-DataModel and tell me if
everything is OK for a release.

Cheers, Laurent D.

Sergiy Zuban

unread,
Feb 19, 2013, 12:35:00 PM2/19/13
to dbix-da...@googlegroups.com
Hi Laurent,

everything works as expected. Thank you for so quick reaction.

--
Sergiy Zuban

Reply all
Reply to author
Forward
0 new messages