EV-MariaDB

 view release on metacpan or  search on metacpan

MariaDB.xs  view on Meta::CPAN

change_user(EV::MariaDB self, const char *user, const char *password, SV *db_sv, SV *cb)
PREINIT:
    int status;
    const char *db;
CODE:
{
    CHECK_READY(self, cb);

    db = (SvOK(db_sv)) ? SvPV_nolen(db_sv) : NULL;

    /* Stash the new credentials; on_utility_done commits them on success or
       discards on failure so reset() never sees credentials we couldn't use.
       Pass the pending pointers to libmariadb so the strings live across the
       async start/cont sequence (Perl args expire when the XS body returns). */
    replace_str(&self->pending_user, user);
    replace_str(&self->pending_password, password);
    if (db) replace_str(&self->pending_database, db);

    push_cb(self, cb);

    self->state = STATE_CHANGE_USER;
    status = mysql_change_user_start(&self->op_bool_ret, self->conn,

lib/EV/MariaDB.pm  view on Meta::CPAN


Changes the default database. The new name is cached so a subsequent
C<reset> reconnects to it; the cache is rolled back if the operation
fails.

=head2 change_user

    $m->change_user($user, $password, $db_or_undef, sub { my ($ok, $err) = @_ });

Changes the authenticated user and optionally the database. Pass
C<undef> for C<$db> to keep the current database. The new credentials
are cached for C<reset>; the cache is rolled back if the change fails.

B<Note:> The server discards all prepared statements as part of this
operation -- see L</reset_connection> for details.

=head2 reset_connection

    $m->reset_connection(sub { my ($ok, $err) = @_ });

Resets session state (variables, temporary tables, etc.) without

lib/EV/MariaDB.pm  view on Meta::CPAN

the same way as in C<execute>.

Dies with C<"another operation is in progress"> or
C<"cannot bind while pipeline results are pending"> when invoked on a
busy connection.

=head2 reset

    $m->reset;

Disconnects and reconnects using the most recent credentials (as
updated by C<change_user>/C<select_db>/C<set_charset>). Cancels all
pending operations and invalidates every prepared statement handle.
Dies with C<"no previous connection to reset"> if C<connect> has never
been called. Aliased as C<reconnect>.

=head2 finish

    $m->finish;

Closes the connection synchronously and cancels all pending operations

t/13_extra_coverage.t  view on Meta::CPAN

    EV::run;
    ok(scalar(grep { /intentional on_connect exception/ } @warnings),
       'die in on_connect: caught as warning');
    $m->finish if $m && $m->is_connected;
}

# --- Test 14: die inside on_error handler is caught as warning ---
{
    my @warnings;
    local $SIG{__WARN__} = sub { push @warnings, $_[0] };
    # Connect with bad credentials to trigger on_error (connection-level error)
    $m = EV::MariaDB->new(
        host     => $TestMariaDB::host,
        port     => $TestMariaDB::port,
        ($TestMariaDB::socket ? (unix_socket => $TestMariaDB::socket) : ()),
        user     => "nonexistent_user_xyzzy_$$",
        password => "badpass",
        on_error => sub {
            die "intentional on_error exception";
        },
    );

t/14_new_features.t  view on Meta::CPAN

        $m->reset_connection(sub {
            my (undef, $rerr) = @_;
            ok(!$rerr, 'reset_connection invalidate: reset ok');
            eval { $m->execute($stmt, [], sub {}) };
            like($@, qr/no longer valid/, 'reset_connection invalidate: stmt marked closed');
            $m->close_stmt($stmt, sub { EV::break });
        });
    });
});

# Failed change_user must NOT corrupt cached credentials — reset() should
# reconnect with the original user, not the failed one. If the rollback
# is broken, reset() fires on_error with auth failure; we trap that
# explicitly so the regression surfaces as a named failing test, not as
# a TAP plan-count mismatch.
with_mariadb(
    cb => sub {
        my $orig_user = $TestMariaDB::user;
        $m->change_user("__definitely_not_a_real_user_$$", "wrong", undef, sub {
            my (undef, $err) = @_;
            ok($err, 'change_user rollback: bad creds rejected');



( run in 3.301 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )