1 package # Hide from PAUSE
2 DBIx::Class::SQLAHacks;
4 # This module is a subclass of SQL::Abstract::Limit and includes a number
5 # of DBIC-specific workarounds, not yet suitable for inclusion into the
8 use base qw/SQL::Abstract::Limit/;
11 use List::Util 'first';
12 use Sub::Name 'subname';
14 use Carp::Clan qw/^DBIx::Class|^SQL::Abstract|^Try::Tiny/;
17 # reinstall the carp()/croak() functions imported into SQL::Abstract
18 # as Carp and Carp::Clan do not like each other much
19 no warnings qw/redefine/;
21 for my $f (qw/carp croak/) {
23 my $orig = \&{"SQL::Abstract::$f"};
24 *{"SQL::Abstract::$f"} = subname "SQL::Abstract::$f" =>
26 if (Carp::longmess() =~ /DBIx::Class::SQLAHacks::[\w]+ .+? called \s at/x) {
27 __PACKAGE__->can($f)->(@_);
37 # Tries to determine limit dialect.
40 my $self = shift->SUPER::new(@_);
42 # This prevents the caching of $dbh in S::A::L, I believe
43 # If limit_dialect is a ref (like a $dbh), go ahead and replace
44 # it with what it resolves to:
45 $self->{limit_dialect} = $self->_find_syntax($self->{limit_dialect})
46 if ref $self->{limit_dialect};
51 # !!! THIS IS ALSO HORRIFIC !!! /me ashamed
53 # Generates inner/outer select lists for various limit dialects
54 # which result in one or more subqueries (e.g. RNO, Top, RowNum)
55 # Any non-root-table columns need to have their table qualifier
56 # turned into a column alias (otherwise names in subqueries clash
57 # and/or lose their source table)
59 # Returns inner/outer strings of SQL QUOTED selectors with aliases
60 # (to be used in whatever select statement), and an alias index hashref
61 # of QUOTED SEL => QUOTED ALIAS pairs (to maybe be used for string-subst
63 # If an order_by is supplied, the inner select needs to bring out columns
64 # used in implicit (non-selected) orders, and the order condition itself
65 # needs to be realiased to the proper names in the outer query. Thus we
66 # also return a hashref (order doesn't matter) of QUOTED EXTRA-SEL =>
67 # QUOTED ALIAS pairs, which is a list of extra selectors that do *not*
68 # exist in the original select list
70 sub _subqueried_limit_attrs {
71 my ($self, $rs_attrs) = @_;
73 croak 'Limit dialect implementation usable only in the context of DBIC (missing $rs_attrs)'
74 unless ref ($rs_attrs) eq 'HASH';
76 my ($re_sep, $re_alias) = map { quotemeta $_ } (
77 $self->name_sep || '.',
81 # correlate select and as, build selection index
82 my (@sel, $in_sel_index);
83 for my $i (0 .. $#{$rs_attrs->{select}}) {
85 my $s = $rs_attrs->{select}[$i];
86 my $sql_sel = $self->_recurse_fields ($s);
87 my $sql_alias = (ref $s) eq 'HASH' ? $s->{-as} : undef;
92 unquoted_sql => do { local $self->{quote_char}; $self->_recurse_fields ($s) },
98 croak "Select argument $i ($s) without corresponding 'as'"
102 $in_sel_index->{$sql_sel}++;
103 $in_sel_index->{$self->_quote ($sql_alias)}++ if $sql_alias;
105 # record unqualified versions too, so we do not have
106 # to reselect the same column twice (in qualified and
108 if (! ref $s && $sql_sel =~ / $re_sep (.+) $/x) {
109 $in_sel_index->{$1}++;
114 # re-alias and remove any name separators from aliases,
115 # unless we are dealing with the current source alias
116 # (which will transcend the subqueries as it is necessary
117 # for possible further chaining)
118 my (@in_sel, @out_sel, %renamed);
119 for my $node (@sel) {
120 if (first { $_ =~ / (?<! $re_alias ) $re_sep /x } ($node->{as}, $node->{unquoted_sql}) ) {
121 $node->{as} =~ s/ $re_sep /__/xg;
122 my $quoted_as = $self->_quote($node->{as});
123 push @in_sel, sprintf '%s AS %s', $node->{sql}, $quoted_as;
124 push @out_sel, $quoted_as;
125 $renamed{$node->{sql}} = $quoted_as;
128 push @in_sel, $node->{sql};
129 push @out_sel, $self->_quote ($node->{as});
133 # see if the order gives us anything
135 for my $chunk ($self->_order_by_chunks ($rs_attrs->{order_by})) {
137 $chunk = $chunk->[0] if (ref $chunk) eq 'ARRAY';
138 $chunk =~ s/\s+ (?: ASC|DESC ) \s* $//ix;
140 next if $in_sel_index->{$chunk};
142 $extra_order_sel{$chunk} ||= $self->_quote (
143 'ORDER__BY__' . scalar keys %extra_order_sel
148 (map { join (', ', @$_ ) } (
153 keys %extra_order_sel ? \%extra_order_sel : (),
157 # ANSI standard Limit/Offset implementation. DB2 and MSSQL >= 2005 use this
159 my ($self, $sql, $rs_attrs, $rows, $offset ) = @_;
161 # mangle the input sql as we will be replacing the selector
162 $sql =~ s/^ \s* SELECT \s+ .+? \s+ (?= \b FROM \b )//ix
163 or croak "Unrecognizable SELECT: $sql";
165 # get selectors, and scan the order_by (if any)
166 my ($in_sel, $out_sel, $alias_map, $extra_order_sel)
167 = $self->_subqueried_limit_attrs ( $rs_attrs );
169 # make up an order if none exists
170 my $requested_order = (delete $rs_attrs->{order_by}) || $self->_rno_default_order;
171 my $rno_ord = $self->_order_by ($requested_order);
173 # this is the order supplement magic
174 my $mid_sel = $out_sel;
175 if ($extra_order_sel) {
176 for my $extra_col (sort
177 { $extra_order_sel->{$a} cmp $extra_order_sel->{$b} }
178 keys %$extra_order_sel
180 $in_sel .= sprintf (', %s AS %s',
182 $extra_order_sel->{$extra_col},
185 $mid_sel .= ', ' . $extra_order_sel->{$extra_col};
189 # and this is order re-alias magic
190 for ($extra_order_sel, $alias_map) {
191 for my $col (keys %$_) {
192 my $re_col = quotemeta ($col);
193 $rno_ord =~ s/$re_col/$_->{$col}/;
197 # whatever is left of the order_by (only where is processed at this point)
198 my $group_having = $self->_parse_rs_attrs($rs_attrs);
200 my $qalias = $self->_quote ($rs_attrs->{alias});
201 my $idx_name = $self->_quote ('rno__row__index');
203 $sql = sprintf (<<EOS, $offset + 1, $offset + $rows, );
205 SELECT $out_sel FROM (
206 SELECT $mid_sel, ROW_NUMBER() OVER( $rno_ord ) AS $idx_name FROM (
207 SELECT $in_sel ${sql}${group_having}
209 ) $qalias WHERE $idx_name BETWEEN %u AND %u
213 $sql =~ s/\s*\n\s*/ /g; # easier to read in the debugger
217 # some databases are happy with OVER (), some need OVER (ORDER BY (SELECT (1)) )
218 sub _rno_default_order {
222 # Informix specific limit, almost like LIMIT/OFFSET
224 my ($self, $sql, $rs_attrs, $rows, $offset) = @_;
226 $sql =~ s/^ \s* SELECT \s+ //ix
227 or croak "Unrecognizable SELECT: $sql";
229 return sprintf ('SELECT %s%s%s%s',
231 ? sprintf ('SKIP %u ', $offset)
234 sprintf ('FIRST %u ', $rows),
236 $self->_parse_rs_attrs ($rs_attrs),
240 # Firebird specific limit, reverse of _SkipFirst for Informix
242 my ($self, $sql, $rs_attrs, $rows, $offset) = @_;
244 $sql =~ s/^ \s* SELECT \s+ //ix
245 or croak "Unrecognizable SELECT: $sql";
247 return sprintf ('SELECT %s%s%s%s',
248 sprintf ('FIRST %u ', $rows),
250 ? sprintf ('SKIP %u ', $offset)
254 $self->_parse_rs_attrs ($rs_attrs),
260 my ( $self, $sql, $rs_attrs, $rows, $offset ) = @_;
262 # mangle the input sql as we will be replacing the selector
263 $sql =~ s/^ \s* SELECT \s+ .+? \s+ (?= \b FROM \b )//ix
264 or croak "Unrecognizable SELECT: $sql";
266 my ($insel, $outsel) = $self->_subqueried_limit_attrs ($rs_attrs);
268 my $qalias = $self->_quote ($rs_attrs->{alias});
269 my $idx_name = $self->_quote ('rownum__index');
270 my $order_group_having = $self->_parse_rs_attrs($rs_attrs);
272 $sql = sprintf (<<EOS, $offset + 1, $offset + $rows, );
274 SELECT $outsel FROM (
275 SELECT $outsel, ROWNUM $idx_name FROM (
276 SELECT $insel ${sql}${order_group_having}
278 ) $qalias WHERE $idx_name BETWEEN %u AND %u
282 $sql =~ s/\s*\n\s*/ /g; # easier to read in the debugger
286 # Crappy Top based Limit/Offset support. Legacy for MSSQL < 2005
288 my ( $self, $sql, $rs_attrs, $rows, $offset ) = @_;
290 # mangle the input sql as we will be replacing the selector
291 $sql =~ s/^ \s* SELECT \s+ .+? \s+ (?= \b FROM \b )//ix
292 or croak "Unrecognizable SELECT: $sql";
295 my ($in_sel, $out_sel, $alias_map, $extra_order_sel)
296 = $self->_subqueried_limit_attrs ($rs_attrs);
298 my $requested_order = delete $rs_attrs->{order_by};
300 my $order_by_requested = $self->_order_by ($requested_order);
302 # make up an order unless supplied
303 my $inner_order = ($order_by_requested
306 { join ('', $rs_attrs->{alias}, $self->{name_sep}||'.', $_ ) }
307 ( $rs_attrs->{_rsroot_source_handle}->resolve->_pri_cols )
311 my ($order_by_inner, $order_by_reversed);
313 # localise as we already have all the bind values we need
315 local $self->{order_bind};
316 $order_by_inner = $self->_order_by ($inner_order);
319 for my $ch ($self->_order_by_chunks ($inner_order)) {
320 $ch = $ch->[0] if ref $ch eq 'ARRAY';
322 $ch =~ s/\s+ ( ASC|DESC ) \s* $//ix;
323 my $dir = uc ($1||'ASC');
325 push @out_chunks, \join (' ', $ch, $dir eq 'ASC' ? 'DESC' : 'ASC' );
328 $order_by_reversed = $self->_order_by (\@out_chunks);
331 # this is the order supplement magic
332 my $mid_sel = $out_sel;
333 if ($extra_order_sel) {
334 for my $extra_col (sort
335 { $extra_order_sel->{$a} cmp $extra_order_sel->{$b} }
336 keys %$extra_order_sel
338 $in_sel .= sprintf (', %s AS %s',
340 $extra_order_sel->{$extra_col},
343 $mid_sel .= ', ' . $extra_order_sel->{$extra_col};
346 # since whatever order bindvals there are, they will be realiased
347 # and need to show up in front of the entire initial inner subquery
348 # Unshift *from_bind* to make this happen (horrible, horrible, but
349 # we don't have another mechanism yet)
350 unshift @{$self->{from_bind}}, @{$self->{order_bind}};
353 # and this is order re-alias magic
354 for my $map ($extra_order_sel, $alias_map) {
355 for my $col (keys %$map) {
356 my $re_col = quotemeta ($col);
357 $_ =~ s/$re_col/$map->{$col}/
358 for ($order_by_reversed, $order_by_requested);
362 # generate the rest of the sql
363 my $grpby_having = $self->_parse_rs_attrs ($rs_attrs);
365 my $quoted_rs_alias = $self->_quote ($rs_attrs->{alias});
367 $sql = sprintf ('SELECT TOP %u %s %s %s %s',
368 $rows + ($offset||0),
375 $sql = sprintf ('SELECT TOP %u %s FROM ( %s ) %s %s',
383 $sql = sprintf ('SELECT TOP %u %s FROM ( %s ) %s %s',
389 ) if ( ($offset && $order_by_requested) || ($mid_sel ne $out_sel) );
391 $sql =~ s/\s*\n\s*/ /g; # easier to read in the debugger
395 # This for Sybase ASE, to use SET ROWCOUNT when there is no offset, and
396 # GenericSubQ otherwise.
397 sub _RowCountOrGenericSubQ {
399 my ($sql, $rs_attrs, $rows, $offset) = @_;
401 return $self->_GenericSubQ(@_) if $offset;
403 return sprintf <<"EOF", $rows, $sql;
410 # This is the most evil limit "dialect" (more of a hack) for *really*
411 # stupid databases. It works by ordering the set by some unique column,
412 # and calculating amount of rows that have a less-er value (thus
413 # emulating a RowNum-like index). Of course this implies the set can
414 # only be ordered by a single unique columns.
416 my ($self, $sql, $rs_attrs, $rows, $offset) = @_;
418 my $root_rsrc = $rs_attrs->{_rsroot_source_handle}->resolve;
419 my $root_tbl_name = $root_rsrc->name;
421 # mangle the input sql as we will be replacing the selector
422 $sql =~ s/^ \s* SELECT \s+ .+? \s+ (?= \b FROM \b )//ix
423 or croak "Unrecognizable SELECT: $sql";
425 my ($order_by, @rest) = do {
426 local $self->{quote_char};
427 $self->_order_by_chunks ($rs_attrs->{order_by})
437 ( ref $order_by eq 'ARRAY' and @$order_by == 1 )
441 'Generic Subquery Limit does not work on resultsets without an order, or resultsets '
442 . 'with complex order criteria (multicolumn and/or functions). Provide a single, '
443 . 'unique-column order criteria.'
447 ($order_by) = @$order_by if ref $order_by;
449 $order_by =~ s/\s+ ( ASC|DESC ) \s* $//ix;
450 my $direction = lc ($1 || 'asc');
452 my ($unq_sort_col) = $order_by =~ /(?:^|\.)([^\.]+)$/;
454 my $inf = $root_rsrc->storage->_resolve_column_info (
455 $rs_attrs->{from}, [$order_by, $unq_sort_col]
458 my $ord_colinfo = $inf->{$order_by} || croak "Unable to determine source of order-criteria '$order_by'";
460 if ($ord_colinfo->{-result_source}->name ne $root_tbl_name) {
461 croak "Generic Subquery Limit order criteria can be only based on the root-source '"
462 . $root_rsrc->source_name . "' (aliased as '$rs_attrs->{alias}')";
465 # make sure order column is qualified
466 $order_by = "$rs_attrs->{alias}.$order_by"
467 unless $order_by =~ /^$rs_attrs->{alias}\./;
470 my $ucs = { $root_rsrc->unique_constraints };
471 for (values %$ucs ) {
472 if (@$_ == 1 && "$rs_attrs->{alias}.$_->[0]" eq $order_by) {
477 croak "Generic Subquery Limit order criteria column '$order_by' must be unique (no unique constraint found)"
480 my ($in_sel, $out_sel, $alias_map, $extra_order_sel)
481 = $self->_subqueried_limit_attrs ($rs_attrs);
483 my $cmp_op = $direction eq 'desc' ? '>' : '<';
484 my $count_tbl_alias = 'rownum__emulation';
486 my $order_sql = $self->_order_by (delete $rs_attrs->{order_by});
487 my $group_having_sql = $self->_parse_rs_attrs($rs_attrs);
489 # add the order supplement (if any) as this is what will be used for the outer WHERE
490 $in_sel .= ", $_" for keys %{$extra_order_sel||{}};
492 $sql = sprintf (<<EOS,
495 SELECT $in_sel ${sql}${group_having_sql}
497 WHERE ( SELECT COUNT(*) FROM %s %s WHERE %s $cmp_op %s ) %s
500 ( map { $self->_quote ($_) } (
504 "$count_tbl_alias.$unq_sort_col",
508 ? sprintf ('BETWEEN %u AND %u', $offset, $offset + $rows - 1)
509 : sprintf ('< %u', $rows )
513 $sql =~ s/\s*\n\s*/ /g; # easier to read in the debugger
518 # While we're at it, this should make LIMIT queries more efficient,
519 # without digging into things too deeply
521 my ($self, $syntax) = @_;
522 return $self->{_cached_syntax} ||= $self->SUPER::_find_syntax($syntax);
525 # Quotes table names, handles "limit" dialects (e.g. where rownum between x and
528 my ($self, $table, $fields, $where, $rs_attrs, @rest) = @_;
530 if (not ref($table) or ref($table) eq 'SCALAR') {
531 $table = $self->_quote($table);
534 @rest = (-1) unless defined $rest[0];
535 croak "LIMIT 0 Does Not Compute" if $rest[0] == 0;
536 # and anyway, SQL::Abstract::Limit will cause a barf if we don't first
538 my ($sql, @bind) = $self->SUPER::select(
539 $table, $self->_recurse_fields($fields), $where, $rs_attrs, @rest
541 push @{$self->{where_bind}}, @bind;
543 # this *must* be called, otherwise extra binds will remain in the sql-maker
544 my @all_bind = $self->_assemble_binds;
546 return wantarray ? ($sql, @all_bind) : $sql;
549 sub _assemble_binds {
551 return map { @{ (delete $self->{"${_}_bind"}) || [] } } (qw/from where having order/);
554 # Quotes table names, and handles default inserts
558 $table = $self->_quote($table);
560 # SQLA will emit INSERT INTO $table ( ) VALUES ( )
561 # which is sadly understood only by MySQL. Change default behavior here,
562 # until SQLA2 comes with proper dialect support
563 if (! $_[0] or (ref $_[0] eq 'HASH' and !keys %{$_[0]} ) ) {
564 my $sql = "INSERT INTO ${table} DEFAULT VALUES";
566 if (my $ret = ($_[1]||{})->{returning} ) {
567 $sql .= $self->_insert_returning ($ret);
573 $self->SUPER::insert($table, @_);
576 # Just quotes table names.
580 $table = $self->_quote($table);
581 $self->SUPER::update($table, @_);
584 # Just quotes table names.
588 $table = $self->_quote($table);
589 $self->SUPER::delete($table, @_);
594 # my ( $syntax, $sql, $order, $rows, $offset ) = @_;
597 return $_[1] . $self->_parse_rs_attrs($_[2]);
599 return $self->SUPER::_emulate_limit(@_);
603 sub _recurse_fields {
604 my ($self, $fields) = @_;
605 my $ref = ref $fields;
606 return $self->_quote($fields) unless $ref;
607 return $$fields if $ref eq 'SCALAR';
609 if ($ref eq 'ARRAY') {
610 return join(', ', map { $self->_recurse_fields($_) } @$fields);
612 elsif ($ref eq 'HASH') {
613 my %hash = %$fields; # shallow copy
615 my $as = delete $hash{-as}; # if supplied
617 my ($func, $args, @toomany) = %hash;
619 # there should be only one pair
621 croak "Malformed select argument - too many keys in hash: " . join (',', keys %$fields );
624 if (lc ($func) eq 'distinct' && ref $args eq 'ARRAY' && @$args > 1) {
626 'The select => { distinct => ... } syntax is not supported for multiple columns.'
627 .' Instead please use { group_by => [ qw/' . (join ' ', @$args) . '/ ] }'
628 .' or { select => [ qw/' . (join ' ', @$args) . '/ ], distinct => 1 }'
632 my $select = sprintf ('%s( %s )%s',
633 $self->_sqlcase($func),
634 $self->_recurse_fields($args),
636 ? sprintf (' %s %s', $self->_sqlcase('as'), $self->_quote ($as) )
642 # Is the second check absolutely necessary?
643 elsif ( $ref eq 'REF' and ref($$fields) eq 'ARRAY' ) {
644 return $self->_fold_sqlbind( $fields );
647 croak($ref . qq{ unexpected in _recurse_fields()})
652 update => 'FOR UPDATE',
653 shared => 'FOR SHARE',
656 # this used to be a part of _order_by but is broken out for clarity.
657 # What we have been doing forever is hijacking the $order arg of
658 # SQLA::select to pass in arbitrary pieces of data (first the group_by,
659 # then pretty much the entire resultset attr-hash, as more and more
660 # things in the SQLA space need to have mopre info about the $rs they
661 # create SQL for. The alternative would be to keep expanding the
662 # signature of _select with more and more positional parameters, which
663 # is just gross. All hail SQLA2!
664 sub _parse_rs_attrs {
665 my ($self, $arg) = @_;
669 if (my $g = $self->_recurse_fields($arg->{group_by}) ) {
670 $sql .= $self->_sqlcase(' group by ') . $g;
673 if (defined $arg->{having}) {
674 my ($frag, @bind) = $self->_recurse_where($arg->{having});
675 push(@{$self->{having_bind}}, @bind);
676 $sql .= $self->_sqlcase(' having ') . $frag;
679 if (defined $arg->{order_by}) {
680 $sql .= $self->_order_by ($arg->{order_by});
683 if (my $for = $arg->{for}) {
684 $sql .= " $for_syntax->{$for}" if $for_syntax->{$for};
691 my ($self, $arg) = @_;
693 # check that we are not called in legacy mode (order_by as 4th argument)
694 if (ref $arg eq 'HASH' and not grep { $_ =~ /^-(?:desc|asc)/i } keys %$arg ) {
695 return $self->_parse_rs_attrs ($arg);
698 my ($sql, @bind) = $self->SUPER::_order_by ($arg);
699 push @{$self->{order_bind}}, @bind;
704 sub _order_directions {
705 my ($self, $order) = @_;
707 # strip bind values - none of the current _order_directions users support them
708 return $self->SUPER::_order_directions( [ map
709 { ref $_ ? $_->[0] : $_ }
710 $self->_order_by_chunks ($order)
715 my ($self, $from) = @_;
716 if (ref $from eq 'ARRAY') {
717 return $self->_recurse_from(@$from);
718 } elsif (ref $from eq 'HASH') {
719 return $self->_make_as($from);
721 return $from; # would love to quote here but _table ends up getting called
722 # twice during an ->select without a limit clause due to
723 # the way S::A::Limit->select works. should maybe consider
724 # bypassing this and doing S::A::select($self, ...) in
725 # our select method above. meantime, quoting shims have
726 # been added to select/insert/update/delete here
730 sub _generate_join_clause {
731 my ($self, $join_type) = @_;
733 return sprintf ('%s JOIN ',
734 $join_type ? ' ' . uc($join_type) : ''
739 my ($self, $from, @join) = @_;
741 push(@sqlf, $self->_make_as($from));
742 foreach my $j (@join) {
746 # check whether a join type exists
747 my $to_jt = ref($to) eq 'ARRAY' ? $to->[0] : $to;
749 if (ref($to_jt) eq 'HASH' and defined($to_jt->{-join_type})) {
750 $join_type = $to_jt->{-join_type};
751 $join_type =~ s/^\s+ | \s+$//xg;
754 $join_type = $self->{_default_jointype} if not defined $join_type;
756 push @sqlf, $self->_generate_join_clause( $join_type );
758 if (ref $to eq 'ARRAY') {
759 push(@sqlf, '(', $self->_recurse_from(@$to), ')');
761 push(@sqlf, $self->_make_as($to));
763 push(@sqlf, ' ON ', $self->_join_condition($on));
765 return join('', @sqlf);
769 my ($self, $sqlbind) = @_;
771 my @sqlbind = @$$sqlbind; # copy
772 my $sql = shift @sqlbind;
773 push @{$self->{from_bind}}, @sqlbind;
779 my ($self, $from) = @_;
780 return join(' ', map { (ref $_ eq 'SCALAR' ? $$_
781 : ref $_ eq 'REF' ? $self->_fold_sqlbind($_)
783 } reverse each %{$self->_skip_options($from)});
787 my ($self, $hash) = @_;
789 $clean_hash->{$_} = $hash->{$_}
790 for grep {!/^-/} keys %$hash;
794 sub _join_condition {
795 my ($self, $cond) = @_;
796 if (ref $cond eq 'HASH') {
801 croak (ref($v) . qq{ reference arguments are not supported in JOINS - try using \"..." instead'})
802 if ref($v) ne 'SCALAR';
806 my $x = '= '.$self->_quote($v); $j{$_} = \$x;
809 return scalar($self->_recurse_where(\%j));
810 } elsif (ref $cond eq 'ARRAY') {
811 return join(' OR ', map { $self->_join_condition($_) } @$cond);
813 die "Can't handle this yet!";
820 $self->{limit_dialect} = shift;
821 undef $self->{_cached_syntax};
823 return $self->{limit_dialect};
826 # Set to an array-ref to specify separate left and right quotes for table names.
827 # A single scalar is equivalen to [ $char, $char ]
830 $self->{quote_char} = shift if @_;
831 return $self->{quote_char};
834 # Character separating quoted table names.
837 $self->{name_sep} = shift if @_;
838 return $self->{name_sep};