Skip to content

Commit

Permalink
perltidy
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadam committed Oct 22, 2024
1 parent 95cb405 commit 6fbf5cb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions t/11-sql.t
Original file line number Diff line number Diff line change
Expand Up @@ -233,24 +233,24 @@ is($stmt->as_sql_where, "WHERE ((foo = ?) AND (foo = ?) AND (foo = ?)) AND ((foo

## as_escape
$stmt = ns();
$stmt->add_where(foo => {op => 'LIKE', value => '100%', escape => '\\'});
$stmt->add_where(foo => { op => 'LIKE', value => '100%', escape => '\\' });
is($stmt->as_sql_where, "WHERE (foo LIKE ? ESCAPE '\\')\n");
is($stmt->bind->[0], '100%'); # escape doesn't automatically escape the value
is($stmt->bind->[0], '100%'); # escape doesn't automatically escape the value
$stmt = ns();
$stmt->add_where(foo => {op => 'LIKE', value => '100\\%', escape => '\\'});
$stmt->add_where(foo => { op => 'LIKE', value => '100\\%', escape => '\\' });
is($stmt->as_sql_where, "WHERE (foo LIKE ? ESCAPE '\\')\n");
is($stmt->bind->[0], '100\\%');
is($stmt->bind->[0], '100\\%');
$stmt = ns();
$stmt->add_where(foo => {op => 'LIKE', value => '100%', escape => '!'});
$stmt->add_where(foo => { op => 'LIKE', value => '100%', escape => '!' });
is($stmt->as_sql_where, "WHERE (foo LIKE ? ESCAPE '!')\n");
$stmt = ns();
$stmt->add_where(foo => {op => 'LIKE', value => '100%', escape => "''"});
$stmt->add_where(foo => { op => 'LIKE', value => '100%', escape => "''" });
is($stmt->as_sql_where, "WHERE (foo LIKE ? ESCAPE '''')\n");
$stmt = ns();
$stmt->add_where(foo => {op => 'LIKE', value => '100%', escape => "\\'"});
$stmt->add_where(foo => { op => 'LIKE', value => '100%', escape => "\\'" });
is($stmt->as_sql_where, "WHERE (foo LIKE ? ESCAPE '\\'')\n");
$stmt = ns();
eval { $stmt->add_where(foo => {op => 'LIKE', value => '_', escape => "!!!"}); };
eval { $stmt->add_where(foo => { op => 'LIKE', value => '_', escape => "!!!" }); };
like($@, qr/length/, 'right error');

$stmt = ns();
Expand Down
16 changes: 8 additions & 8 deletions t/61-escape.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,52 +34,52 @@ $exclamation->save;

subtest 'escape_char 1' => sub {
my @got = Foo->search({ text => { op => 'LIKE', value => '100!%', escape => '!' } });
is scalar(@got), 1, 'right number';
is scalar(@got), 1, 'right number';
is $got[0]->name, 'percent', 'right name';
};

subtest 'escape_char 2' => sub {
my @got = Foo->search({ text => { op => 'LIKE', value => '100#_', escape => '#' } });
is scalar(@got), 1, 'right number';
is scalar(@got), 1, 'right number';
is $got[0]->name, 'underscore', 'right name';
};

subtest 'self escape' => sub {
my @got = Foo->search({ text => { op => 'LIKE', value => '100!!', escape => '!' } });
is scalar(@got), 1, 'right number';
is scalar(@got), 1, 'right number';
is $got[0]->name, 'exclamation', 'right name';
};

subtest 'use wildcard charactor as escapr_char' => sub {
plan skip_all => 'MariaDB does not support it' if Foo->driver->dbh->{Driver}->{Name} eq 'MariaDB';
my @got = Foo->search({ text => { op => 'LIKE', value => '100_%', escape => '_' } });
is scalar(@got), 1, 'right number';
is scalar(@got), 1, 'right number';
is $got[0]->name, 'percent', 'right name';
};

subtest 'use of special characters' => sub {
subtest 'escape_char single quote' => sub {
my @got = Foo->search({ text => { op => 'LIKE', value => "100'_", escape => "''" } });
is scalar(@got), 1, 'right number';
is scalar(@got), 1, 'right number';
is $got[0]->name, 'underscore', 'right name';
};

if (Foo->driver->dbh->{Driver}->{Name} =~ /mysql|mariadb/i) {
subtest 'escape_char single quote' => sub {
my @got = Foo->search({ text => { op => 'LIKE', value => "100'_", escape => "\\'" } });
is scalar(@got), 1, 'right number';
is scalar(@got), 1, 'right number';
is $got[0]->name, 'underscore', 'right name';
};

subtest 'escape_char backslash' => sub {
my @got = Foo->search({ text => { op => 'LIKE', value => '100\\_', escape => '\\\\' } });
is scalar(@got), 1, 'right number';
is scalar(@got), 1, 'right number';
is $got[0]->name, 'underscore', 'right name';
};
} else {
subtest 'escape_char backslash' => sub {
my @got = Foo->search({ text => { op => 'LIKE', value => '100\\_', escape => '\\' } });
is scalar(@got), 1, 'right number';
is scalar(@got), 1, 'right number';
is $got[0]->name, 'underscore', 'right name';
};
}
Expand Down

0 comments on commit 6fbf5cb

Please sign in to comment.