Skip to content

Conversation

@hogashi
Copy link

@hogashi hogashi commented Aug 1, 2025

got

Pod says that add_order_by takes string or hashref as arguments.

$stmt->add_order_by('foo');
$stmt->add_order_by({'foo' => 'DESC'});

expected

add_order_by takes string or hash (or scalar ref). ref:

subtest 'ORDER BY' => sub {
subtest 'quote_char: "`", name_sep: "."' => sub {
do {
my $stmt = ns( quote_char => q{`}, name_sep => q{.}, );
$stmt->add_from( 'foo' );
$stmt->add_order_by('baz' => 'DESC');
is($stmt->as_sql, "FROM `foo`\nORDER BY `baz` DESC", 'single order by');
};
do {
my $stmt = ns( quote_char => q{`}, name_sep => q{.}, );
$stmt->add_from( 'foo' );
$stmt->add_order_by( 'baz' => 'DESC' );
$stmt->add_order_by( 'quux' => 'ASC' );
is($stmt->as_sql, "FROM `foo`\nORDER BY `baz` DESC, `quux` ASC", 'multiple order by');
};
do {
my $stmt = ns( quote_char => q{`}, name_sep => q{.}, );
$stmt->add_from( 'foo' );
$stmt->add_order_by( \'baz DESC' );
is($stmt->as_sql, "FROM `foo`\nORDER BY baz DESC", 'scalar ref'); # should not quote
};
};
subtest 'quote_char: "", name_sep: ".", new_line: " "' => sub {
do {
my $stmt = ns( quote_char => q{}, name_sep => q{.}, new_line => q{ } );
$stmt->add_from( 'foo' );
$stmt->add_order_by('baz' => 'DESC');
is($stmt->as_sql, "FROM foo ORDER BY baz DESC", 'single order by');
};
do {
my $stmt = ns( quote_char => q{}, name_sep => q{.}, new_line => q{ });
$stmt->add_from( 'foo' );
$stmt->add_order_by( 'baz' => 'DESC' );
$stmt->add_order_by( 'quux' => 'ASC' );
is($stmt->as_sql, "FROM foo ORDER BY baz DESC, quux ASC", 'multiple order by');
};
subtest 'scalarref' => sub {
my $stmt = ns( quote_char => q{}, name_sep => q{.}, new_line => q{ });
$stmt->add_from( 'foo' );
$stmt->add_order_by( \'baz DESC' );
is($stmt->as_sql, "FROM foo ORDER BY baz DESC"); # should not quote
};
};
};

what I did

I fixed pod for add_order_by arguments to be hash instead of hashref.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant