Fix Oracle _dbh_execute_for_fetch warning suppression
[dbsrgits/DBIx-Class.git] / lib / DBIx / Class / Storage / DBI / Oracle / Generic.pm
1 package DBIx::Class::Storage::DBI::Oracle::Generic;
2
3 use strict;
4 use warnings;
5 use base qw/DBIx::Class::Storage::DBI/;
6 use mro 'c3';
7 use DBIx::Class::Carp;
8 use Scope::Guard ();
9 use Context::Preserve 'preserve_context';
10 use DBIx::Class::_Util qw( modver_gt_or_eq modver_gt_or_eq_and_lt dbic_internal_try );
11 use namespace::clean;
12
13 __PACKAGE__->sql_limit_dialect ('RowNum');
14 __PACKAGE__->sql_quote_char ('"');
15 __PACKAGE__->sql_maker_class('DBIx::Class::SQLMaker::Oracle');
16 __PACKAGE__->datetime_parser_type('DateTime::Format::Oracle');
17
18 sub __cache_queries_with_max_lob_parts { 2 }
19
20 =head1 NAME
21
22 DBIx::Class::Storage::DBI::Oracle::Generic - Oracle Support for DBIx::Class
23
24 =head1 SYNOPSIS
25
26   # In your result (table) classes
27   use base 'DBIx::Class::Core';
28   __PACKAGE__->add_columns({ id => { sequence => 'mysequence', auto_nextval => 1 } });
29   __PACKAGE__->set_primary_key('id');
30
31   # Somewhere in your Code
32   # add some data to a table with a hierarchical relationship
33   $schema->resultset('Person')->create ({
34         firstname => 'foo',
35         lastname => 'bar',
36         children => [
37             {
38                 firstname => 'child1',
39                 lastname => 'bar',
40                 children => [
41                     {
42                         firstname => 'grandchild',
43                         lastname => 'bar',
44                     }
45                 ],
46             },
47             {
48                 firstname => 'child2',
49                 lastname => 'bar',
50             },
51         ],
52     });
53
54   # select from the hierarchical relationship
55   my $rs = $schema->resultset('Person')->search({},
56     {
57       'start_with' => { 'firstname' => 'foo', 'lastname' => 'bar' },
58       'connect_by' => { 'parentid' => { '-prior' => { -ident => 'personid' } },
59       'order_siblings_by' => { -asc => 'name' },
60     };
61   );
62
63   # this will select the whole tree starting from person "foo bar", creating
64   # following query:
65   # SELECT
66   #     me.persionid me.firstname, me.lastname, me.parentid
67   # FROM
68   #     person me
69   # START WITH
70   #     firstname = 'foo' and lastname = 'bar'
71   # CONNECT BY
72   #     parentid = prior personid
73   # ORDER SIBLINGS BY
74   #     firstname ASC
75
76 =head1 DESCRIPTION
77
78 This class implements base Oracle support. The subclass
79 L<DBIx::Class::Storage::DBI::Oracle::WhereJoins> is for C<(+)> joins in Oracle
80 versions before 9.0.
81
82 =head1 METHODS
83
84 =cut
85
86 sub _determine_supports_insert_returning {
87   my $self = shift;
88
89 # TODO find out which version supports the RETURNING syntax
90 # 8i has it and earlier docs are a 404 on oracle.com
91
92   return 1
93     if $self->_server_info->{normalized_dbms_version} >= 8.001;
94
95   return 0;
96 }
97
98 __PACKAGE__->_use_insert_returning_bound (1);
99
100 sub deployment_statements {
101   my $self = shift;;
102   my ($schema, $type, $version, $dir, $sqltargs, @rest) = @_;
103
104   $sqltargs ||= {};
105
106   if (
107     ! exists $sqltargs->{producer_args}{oracle_version}
108       and
109     my $dver = $self->_server_info->{dbms_version}
110   ) {
111     $sqltargs->{producer_args}{oracle_version} = $dver;
112   }
113
114   $self->next::method($schema, $type, $version, $dir, $sqltargs, @rest);
115 }
116
117 sub _dbh_last_insert_id {
118   my ($self, $dbh, $source, @columns) = @_;
119   my @ids = ();
120   foreach my $col (@columns) {
121     my $seq = ($source->column_info($col)->{sequence} ||= $self->get_autoinc_seq($source,$col));
122     my $id = $self->_sequence_fetch( 'CURRVAL', $seq );
123     push @ids, $id;
124   }
125   return @ids;
126 }
127
128 sub _dbh_get_autoinc_seq {
129   my ($self, $dbh, $source, $col) = @_;
130
131   my $sql_maker = $self->sql_maker;
132   my ($ql, $qr) = map { $_ ? (quotemeta $_) : '' } $sql_maker->_quote_chars;
133
134   my $source_name;
135   if ( ref $source->name eq 'SCALAR' ) {
136     $source_name = ${$source->name};
137
138     # the ALL_TRIGGERS match further on is case sensitive - thus uppercase
139     # stuff unless it is already quoted
140     $source_name = uc ($source_name) if $source_name !~ /\"/;
141   }
142   else {
143     $source_name = $source->name;
144     $source_name = uc($source_name) unless $ql;
145   }
146
147   # trigger_body is a LONG
148   local $dbh->{LongReadLen} = 64 * 1024 if ($dbh->{LongReadLen} < 64 * 1024);
149
150   # disable default bindtype
151   local $sql_maker->{bindtype} = 'normal';
152
153   # look up the correct sequence automatically
154   my ( $schema, $table ) = $source_name =~ /( (?:${ql})? \w+ (?:${qr})? ) \. ( (?:${ql})? \w+ (?:${qr})? )/x;
155
156   # if no explicit schema was requested - use the default schema (which in the case of Oracle is the db user)
157   $schema ||= \'= USER';
158
159   my ($sql, @bind) = $sql_maker->select (
160     'ALL_TRIGGERS',
161     [qw/TRIGGER_BODY TABLE_OWNER TRIGGER_NAME/],
162     {
163       OWNER => $schema,
164       TABLE_NAME => $table || $source_name,
165       TRIGGERING_EVENT => { -like => '%INSERT%' },  # this will also catch insert_or_update
166       TRIGGER_TYPE => { -like => '%BEFORE%' },      # we care only about 'before' triggers
167       STATUS => 'ENABLED',
168      },
169   );
170
171   # to find all the triggers that mention the column in question a simple
172   # regex grep since the trigger_body above is a LONG and hence not searchable
173   # via -like
174   my @triggers = ( map
175     { my %inf; @inf{qw/body schema name/} = @$_; \%inf }
176     ( grep
177       { $_->[0] =~ /\:new\.${ql}${col}${qr} | \:new\.$col/xi }
178       @{ $dbh->selectall_arrayref( $sql, {}, @bind ) }
179     )
180   );
181
182   # extract all sequence names mentioned in each trigger, throw away
183   # triggers without apparent sequences
184   @triggers = map {
185     my @seqs = $_->{body} =~ / ( [\.\w\"\-]+ ) \. nextval /xig;
186     @seqs
187       ? { %$_, sequences => \@seqs }
188       : ()
189     ;
190   } @triggers;
191
192   my $chosen_trigger;
193
194   # if only one trigger matched things are easy
195   if (@triggers == 1) {
196
197     if ( @{$triggers[0]{sequences}} == 1 ) {
198       $chosen_trigger = $triggers[0];
199     }
200     else {
201       $self->throw_exception( sprintf (
202         "Unable to introspect trigger '%s' for column '%s.%s' (references multiple sequences). "
203       . "You need to specify the correct 'sequence' explicitly in '%s's column_info.",
204         $triggers[0]{name},
205         $source_name,
206         $col,
207         $col,
208       ) );
209     }
210   }
211   # got more than one matching trigger - see if we can narrow it down
212   elsif (@triggers > 1) {
213
214     my @candidates = grep
215       { $_->{body} =~ / into \s+ \:new\.$col /xi }
216       @triggers
217     ;
218
219     if (@candidates == 1 && @{$candidates[0]{sequences}} == 1) {
220       $chosen_trigger = $candidates[0];
221     }
222     else {
223       $self->throw_exception( sprintf (
224         "Unable to reliably select a BEFORE INSERT trigger for column '%s.%s' (possibilities: %s). "
225       . "You need to specify the correct 'sequence' explicitly in '%s's column_info.",
226         $source_name,
227         $col,
228         ( join ', ', map { "'$_->{name}'" } @triggers ),
229         $col,
230       ) );
231     }
232   }
233
234   if ($chosen_trigger) {
235     my $seq_name = $chosen_trigger->{sequences}[0];
236
237     $seq_name = "$chosen_trigger->{schema}.$seq_name"
238       unless $seq_name =~ /\./;
239
240     return \$seq_name if $seq_name =~ /\"/; # may already be quoted in-trigger
241     return $seq_name;
242   }
243
244   $self->throw_exception( sprintf (
245     "No suitable BEFORE INSERT triggers found for column '%s.%s'. "
246   . "You need to specify the correct 'sequence' explicitly in '%s's column_info.",
247     $source_name,
248     $col,
249     $col,
250   ));
251 }
252
253 sub _sequence_fetch {
254   my ( $self, $type, $seq ) = @_;
255
256   # use the maker to leverage quoting settings
257   my $sth = $self->_dbh->prepare_cached(
258     $self->sql_maker->select('DUAL', [ ref $seq ? \"$$seq.$type" : "$seq.$type" ] )
259   );
260   $sth->execute;
261   my ($id) = $sth->fetchrow_array;
262   $sth->finish;
263   return $id;
264 }
265
266 sub _ping {
267   my $self = shift;
268
269   my $dbh = $self->_dbh or return 0;
270
271   local $dbh->{RaiseError} = 1;
272   local $dbh->{PrintError} = 0;
273
274   ( dbic_internal_try {
275     $dbh->do('select 1 from dual');
276     1;
277   })
278     ? 1
279     : 0
280   ;
281 }
282
283 sub _dbh_execute {
284   #my ($self, $dbh, $sql, $bind, $bind_attrs) = @_;
285   my ($self, $sql, $bind) = @_[0,2,3];
286
287   # Turn off sth caching for multi-part LOBs. See _prep_for_execute below
288   local $self->{disable_sth_caching} = 1 if grep {
289     ($_->[0]{_ora_lob_autosplit_part}||0)
290       >
291     (__cache_queries_with_max_lob_parts - 1)
292   } @$bind;
293
294   my $next = $self->next::can;
295
296   # if we are already in a txn we can't retry anything
297   return shift->$next(@_)
298     if $self->transaction_depth;
299
300   # cheat the blockrunner we are just about to create
301   # we do want to rerun things regardless of outer state
302   local $self->{_in_do_block};
303
304   return DBIx::Class::Storage::BlockRunner->new(
305     storage => $self,
306     wrap_txn => 0,
307     retry_handler => sub {
308       # ORA-01003: no statement parsed (someone changed the table somehow,
309       # invalidating your cursor.)
310       if (
311         $_[0]->failed_attempt_count == 1
312           and
313         $_[0]->last_exception =~ /ORA-01003/
314           and
315         my $dbh = $_[0]->storage->_dbh
316       ) {
317         delete $dbh->{CachedKids}{$sql};
318         return 1;
319       }
320       else {
321         return 0;
322       }
323     },
324   )->run( $next, @_ );
325 }
326
327 sub _dbh_execute_for_fetch {
328   #my ($self, $source, $sth, $proto_bind, $cols, $data) = @_;
329
330   # Older DBD::Oracle warns loudly on partial execute_for_fetch failures
331   # before https://metacpan.org/source/PYTHIAN/DBD-Oracle-1.28/Changes#L7-9
332   local $_[2]->{PrintWarn} = 0
333     unless modver_gt_or_eq( 'DBD::Oracle', '1.28' );
334
335   shift->next::method(@_);
336 }
337
338 =head2 get_autoinc_seq
339
340 Returns the sequence name for an autoincrement column
341
342 =cut
343
344 sub get_autoinc_seq {
345   my ($self, $source, $col) = @_;
346
347   $self->dbh_do('_dbh_get_autoinc_seq', $source, $col);
348 }
349
350 =head2 datetime_parser_type
351
352 This sets the proper DateTime::Format module for use with
353 L<DBIx::Class::InflateColumn::DateTime>.
354
355 =head2 connect_call_datetime_setup
356
357 Used as:
358
359     on_connect_call => 'datetime_setup'
360
361 In L<connect_info|DBIx::Class::Storage::DBI/connect_info> to set the session nls
362 date, and timestamp values for use with L<DBIx::Class::InflateColumn::DateTime>
363 and the necessary environment variables for L<DateTime::Format::Oracle>, which
364 is used by it.
365
366 Maximum allowable precision is used, unless the environment variables have
367 already been set.
368
369 These are the defaults used:
370
371   $ENV{NLS_DATE_FORMAT}         ||= 'YYYY-MM-DD HH24:MI:SS';
372   $ENV{NLS_TIMESTAMP_FORMAT}    ||= 'YYYY-MM-DD HH24:MI:SS.FF';
373   $ENV{NLS_TIMESTAMP_TZ_FORMAT} ||= 'YYYY-MM-DD HH24:MI:SS.FF TZHTZM';
374
375 To get more than second precision with L<DBIx::Class::InflateColumn::DateTime>
376 for your timestamps, use something like this:
377
378   use Time::HiRes 'time';
379   my $ts = DateTime->from_epoch(epoch => time);
380
381 =cut
382
383 sub connect_call_datetime_setup {
384   my $self = shift;
385
386   my $date_format = $ENV{NLS_DATE_FORMAT} ||= 'YYYY-MM-DD HH24:MI:SS';
387   my $timestamp_format = $ENV{NLS_TIMESTAMP_FORMAT} ||=
388     'YYYY-MM-DD HH24:MI:SS.FF';
389   my $timestamp_tz_format = $ENV{NLS_TIMESTAMP_TZ_FORMAT} ||=
390     'YYYY-MM-DD HH24:MI:SS.FF TZHTZM';
391
392   $self->_do_query(
393     "alter session set nls_date_format = '$date_format'"
394   );
395   $self->_do_query(
396     "alter session set nls_timestamp_format = '$timestamp_format'"
397   );
398   $self->_do_query(
399     "alter session set nls_timestamp_tz_format='$timestamp_tz_format'"
400   );
401 }
402
403 ### Note originally by Ron "Quinn" Straight <quinnfazigu@gmail.org>
404 ### http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits/DBIx-Class.git;a=commitdiff;h=5db2758de644d53e07cd3e05f0e9037bf40116fc
405 #
406 # Handle LOB types in Oracle.  Under a certain size (4k?), you can get away
407 # with the driver assuming your input is the deprecated LONG type if you
408 # encode it as a hex string.  That ain't gonna fly at larger values, where
409 # you'll discover you have to do what this does.
410 #
411 # This method had to be overridden because we need to set ora_field to the
412 # actual column, and that isn't passed to the call (provided by Storage) to
413 # bind_attribute_by_data_type.
414 #
415 # According to L<DBD::Oracle>, the ora_field isn't always necessary, but
416 # adding it doesn't hurt, and will save your bacon if you're modifying a
417 # table with more than one LOB column.
418 #
419 sub _dbi_attrs_for_bind {
420   my ($self, $ident, $bind) = @_;
421
422   my $attrs = $self->next::method($ident, $bind);
423
424   # Push the column name into all bind attrs, make sure to *NOT* write into
425   # the existing $attrs->[$idx]{..} hashref, as it is cached by the call to
426   # next::method above.
427   # FIXME - this code will go away when the LobWriter refactor lands
428   $attrs->[$_]
429     and
430   keys %{ $attrs->[$_] }
431     and
432   $bind->[$_][0]{dbic_colname}
433     and
434   $attrs->[$_] = { %{$attrs->[$_]}, ora_field => $bind->[$_][0]{dbic_colname} }
435     for 0 .. $#$attrs;
436
437   $attrs;
438 }
439
440 sub bind_attribute_by_data_type {
441   my ($self, $dt) = @_;
442
443   if ($self->_is_lob_type($dt)) {
444
445     # no earlier - no later
446     $self->throw_exception(
447       "BLOB/CLOB support in DBD::Oracle == 1.23 is broken, use an earlier or later "
448     . "version (https://rt.cpan.org/Public/Bug/Display.html?id=46016)"
449     ) if modver_gt_or_eq_and_lt( 'DBD::Oracle', '1.23', '1.24' );
450
451     return {
452       ora_type => $self->_is_text_lob_type($dt)
453         ? DBD::Oracle::ORA_CLOB()
454         : DBD::Oracle::ORA_BLOB()
455     };
456   }
457   else {
458     return undef;
459   }
460 }
461
462 # Handle blob columns in WHERE.
463 #
464 # For equality comparisons:
465 #
466 # We split data intended for comparing to a LOB into 2000 character chunks and
467 # compare them using dbms_lob.substr on the LOB column.
468 #
469 # We turn off DBD::Oracle LOB binds for these partial LOB comparisons by passing
470 # dbd_attrs => undef, because these are regular varchar2 comparisons and
471 # otherwise the query will fail.
472 #
473 # Since the most common comparison size is likely to be under 4000 characters
474 # (TEXT comparisons previously deployed to other RDBMSes) we disable
475 # prepare_cached for queries with more than two part comparisons to a LOB
476 # column. This is done in _dbh_execute (above) which was previously overridden
477 # to gracefully recover from an Oracle error. This is to be careful to not
478 # exhaust your application's open cursor limit.
479 #
480 # See:
481 # http://itcareershift.com/blog1/2011/02/21/oracle-max-number-of-open-cursors-complete-reference-for-the-new-oracle-dba/
482 # on the open_cursor limit.
483 #
484 # For everything else:
485 #
486 # We assume that everything that is not a LOB comparison, will most likely be a
487 # LIKE query or some sort of function invocation. This may prove to be a naive
488 # assumption in the future, but for now it should cover the two most likely
489 # things users would want to do with a BLOB or CLOB, an equality test or a LIKE
490 # query (on a CLOB.)
491 #
492 # For these expressions, the bind must NOT have the attributes of a LOB bind for
493 # DBD::Oracle, otherwise the query will fail. This is done by passing
494 # dbd_attrs => undef.
495
496 sub _prep_for_execute {
497   my $self = shift;
498   my ($op) = @_;
499
500   return $self->next::method(@_)
501     if $op eq 'insert';
502
503   my ($sql, $bind) = $self->next::method(@_);
504
505   my $lob_bind_indices = { map {
506     (
507       $bind->[$_][0]{sqlt_datatype}
508         and
509       $self->_is_lob_type($bind->[$_][0]{sqlt_datatype})
510     ) ? ( $_ => 1 ) : ()
511   } ( 0 .. $#$bind ) };
512
513   return ($sql, $bind) unless %$lob_bind_indices;
514
515   my ($final_sql, @final_binds);
516   if ($op eq 'update') {
517     $self->throw_exception('Update with complex WHERE clauses involving BLOB columns currently not supported')
518       if $sql =~ /\bWHERE\b .+ \bWHERE\b/xs;
519
520     my $where_sql;
521     ($final_sql, $where_sql) = $sql =~ /^ (.+?) ( \bWHERE\b .+) /xs;
522
523     if (my $set_bind_count = $final_sql =~ y/?//) {
524
525       delete $lob_bind_indices->{$_} for (0 .. ($set_bind_count - 1));
526
527       # bail if only the update part contains blobs
528       return ($sql, $bind) unless %$lob_bind_indices;
529
530       @final_binds = splice @$bind, 0, $set_bind_count;
531       $lob_bind_indices = { map
532         { $_ - $set_bind_count => $lob_bind_indices->{$_} }
533         keys %$lob_bind_indices
534       };
535     }
536
537     # if we got that far - assume the where SQL is all we got
538     # (the first part is already shoved into $final_sql)
539     $sql = $where_sql;
540   }
541   elsif ($op ne 'select' and $op ne 'delete') {
542     $self->throw_exception("Unsupported \$op: $op");
543   }
544
545   my @sql_parts = split /\?/, $sql;
546
547   my $col_equality_re = qr/ (?<=\s) ([\w."]+) (\s*=\s*) $/x;
548
549   for my $b_idx (0 .. $#$bind) {
550     my $bound = $bind->[$b_idx];
551
552     if (
553       $lob_bind_indices->{$b_idx}
554         and
555       my ($col, $eq) = $sql_parts[0] =~ $col_equality_re
556     ) {
557       my $data = $bound->[1];
558
559       $data = "$data" if ref $data;
560
561       my @parts = unpack '(a2000)*', $data;
562
563       my @sql_frag;
564
565       for my $idx (0..$#parts) {
566         push @sql_frag, sprintf (
567           'UTL_RAW.CAST_TO_VARCHAR2(RAWTOHEX(DBMS_LOB.SUBSTR(%s, 2000, %d))) = ?',
568           $col, ($idx*2000 + 1),
569         );
570       }
571
572       my $sql_frag = '( ' . (join ' AND ', @sql_frag) . ' )';
573
574       $sql_parts[0] =~ s/$col_equality_re/$sql_frag/;
575
576       $final_sql .= shift @sql_parts;
577
578       for my $idx (0..$#parts) {
579         push @final_binds, [
580           {
581             %{ $bound->[0] },
582             _ora_lob_autosplit_part => $idx,
583             dbd_attrs => undef,
584           },
585           $parts[$idx]
586         ];
587       }
588     }
589     else {
590       $final_sql .= shift(@sql_parts) . '?';
591       push @final_binds, $lob_bind_indices->{$b_idx}
592         ? [
593           {
594             %{ $bound->[0] },
595             dbd_attrs => undef,
596           },
597           $bound->[1],
598         ] : $bound
599       ;
600     }
601   }
602
603   if (@sql_parts > 1) {
604     carp "There are more placeholders than binds, this should not happen!";
605     @sql_parts = join ('?', @sql_parts);
606   }
607
608   $final_sql .= $sql_parts[0];
609
610   return ($final_sql, \@final_binds);
611 }
612
613 # Savepoints stuff.
614
615 sub _exec_svp_begin {
616   my ($self, $name) = @_;
617   $self->_dbh->do("SAVEPOINT $name");
618 }
619
620 # Oracle automatically releases a savepoint when you start another one with the
621 # same name.
622 sub _exec_svp_release { 1 }
623
624 sub _exec_svp_rollback {
625   my ($self, $name) = @_;
626   $self->_dbh->do("ROLLBACK TO SAVEPOINT $name")
627 }
628
629 =head2 relname_to_table_alias
630
631 L<DBIx::Class> uses L<DBIx::Class::Relationship> names as table aliases in
632 queries.
633
634 Unfortunately, Oracle doesn't support identifiers over 30 chars in length, so
635 the L<DBIx::Class::Relationship> name is shortened and appended with half of an
636 MD5 hash.
637
638 See L<DBIx::Class::Storage::DBI/relname_to_table_alias>.
639
640 =cut
641
642 sub relname_to_table_alias {
643   my $self = shift;
644   my ($relname, $join_count) = @_;
645
646   my $alias = $self->next::method(@_);
647
648   # we need to shorten here in addition to the shortening in SQLA itself,
649   # since the final relnames are crucial for the join optimizer
650   return $self->sql_maker->_shorten_identifier($alias);
651 }
652
653 =head2 with_deferred_fk_checks
654
655 Runs a coderef between:
656
657   alter session set constraints = deferred
658   ...
659   alter session set constraints = immediate
660
661 to defer foreign key checks.
662
663 Constraints must be declared C<DEFERRABLE> for this to work.
664
665 =cut
666
667 sub with_deferred_fk_checks {
668   my ($self, $sub) = @_;
669
670   my $txn_scope_guard = $self->txn_scope_guard;
671
672   $self->_do_query('alter session set constraints = deferred');
673
674   my $sg = Scope::Guard->new(sub {
675     $self->_do_query('alter session set constraints = immediate');
676   });
677
678   return
679     preserve_context { $sub->() } after => sub { $txn_scope_guard->commit };
680 }
681
682 =head1 ATTRIBUTES
683
684 Following additional attributes can be used in resultsets.
685
686 =head2 connect_by or connect_by_nocycle
687
688 =over 4
689
690 =item Value: \%connect_by
691
692 =back
693
694 A hashref of conditions used to specify the relationship between parent rows
695 and child rows of the hierarchy.
696
697
698   connect_by => { parentid => 'prior personid' }
699
700   # adds a connect by statement to the query:
701   # SELECT
702   #     me.persionid me.firstname, me.lastname, me.parentid
703   # FROM
704   #     person me
705   # CONNECT BY
706   #     parentid = prior persionid
707
708
709   connect_by_nocycle => { parentid => 'prior personid' }
710
711   # adds a connect by statement to the query:
712   # SELECT
713   #     me.persionid me.firstname, me.lastname, me.parentid
714   # FROM
715   #     person me
716   # CONNECT BY NOCYCLE
717   #     parentid = prior persionid
718
719
720 =head2 start_with
721
722 =over 4
723
724 =item Value: \%condition
725
726 =back
727
728 A hashref of conditions which specify the root row(s) of the hierarchy.
729
730 It uses the same syntax as L<DBIx::Class::ResultSet/search>
731
732   start_with => { firstname => 'Foo', lastname => 'Bar' }
733
734   # SELECT
735   #     me.persionid me.firstname, me.lastname, me.parentid
736   # FROM
737   #     person me
738   # START WITH
739   #     firstname = 'foo' and lastname = 'bar'
740   # CONNECT BY
741   #     parentid = prior persionid
742
743 =head2 order_siblings_by
744
745 =over 4
746
747 =item Value: ($order_siblings_by | \@order_siblings_by)
748
749 =back
750
751 Which column(s) to order the siblings by.
752
753 It uses the same syntax as L<DBIx::Class::ResultSet/order_by>
754
755   'order_siblings_by' => 'firstname ASC'
756
757   # SELECT
758   #     me.persionid me.firstname, me.lastname, me.parentid
759   # FROM
760   #     person me
761   # CONNECT BY
762   #     parentid = prior persionid
763   # ORDER SIBLINGS BY
764   #     firstname ASC
765
766 =head1 FURTHER QUESTIONS?
767
768 Check the list of L<additional DBIC resources|DBIx::Class/GETTING HELP/SUPPORT>.
769
770 =head1 COPYRIGHT AND LICENSE
771
772 This module is free software L<copyright|DBIx::Class/COPYRIGHT AND LICENSE>
773 by the L<DBIx::Class (DBIC) authors|DBIx::Class/AUTHORS>. You can
774 redistribute it and/or modify it under the same terms as the
775 L<DBIx::Class library|DBIx::Class/COPYRIGHT AND LICENSE>.
776
777 =cut
778
779 1;
780 # vim:sts=2 sw=2: