DBD-JDBC
view release on metacpan or search on metacpan
lib/DBD/JDBC.pm view on Meta::CPAN
my ($statement_handle);
return undef unless
_send_request($dbh,
$dbh->FETCH('jdbc_socket'), $dbh->FETCH('jdbc_ber'),
[PREPARE_REQ => [STRING => $statement,
($keyType?'STRING':'NULL') => $keyType,
$keyTypeCode => [@$keyList] ] ],
[PREPARE_RESP => \$statement_handle]);
my $param_count = _count_params($statement);
my $sth = DBI::_new_sth($dbh, {
'Statement' => $statement,
'NUM_OF_PARAMS' => $param_count,
'NUM_OF_FIELDS' => undef,
});
$sth->STORE('jdbc_handle' => $statement_handle);
$sth->STORE('jdbc_socket' => $dbh->FETCH('jdbc_socket'));
$sth->STORE('jdbc_ber' => $dbh->FETCH('jdbc_ber'));
$sth->STORE('jdbc_rowcount' => -1);
## Set up ParamValues (DBI 1.28). Initialize the keys to the
## parameter numbers (if any).
$sth->STORE('jdbc_params', {});
$sth->STORE('jdbc_params_types', {});
for my $i (1..$param_count) {
$sth->{'jdbc_params'}->{$i} = undef;
$sth->{'jdbc_params_types'}->{$i} = undef;
}
# Copy the current value of inherited properties to the server.
$sth->STORE('LongReadLen' => $dbh->FETCH('LongReadLen'));
$sth->STORE('LongTruncOk' => $dbh->FETCH('LongTruncOk') ? 1 : 0);
$sth->STORE('ChopBlanks' => $dbh->FETCH('ChopBlanks') ? 1 : 0);
$sth->STORE('jdbc_longreadall' =>
$dbh->FETCH('jdbc_longreadall') ? 1 : 0);
$sth;
}
# JDBC: Connection.commit
sub commit {
my ($dbh) = shift;
my ($resp);
return _send_request($dbh,
$dbh->FETCH('jdbc_socket'), $dbh->FETCH('jdbc_ber'),
[COMMIT_REQ => 0],
[COMMIT_RESP => \$resp]);
}
# JDBC: Connection.rollback
sub rollback {
my ($dbh) = shift;
my ($resp);
return _send_request($dbh,
$dbh->FETCH('jdbc_socket'), $dbh->FETCH('jdbc_ber'),
[ROLLBACK_REQ => 0],
[ROLLBACK_RESP => \$resp]);
}
# Confirms that the server is alive and that this particular
# (JDBC) connection has not been closed.
#
# JDBC: Connection.isClosed
sub ping {
my ($dbh) = shift;
# If the connection isn't active, no point in pinging it.
return 0 unless $dbh->FETCH('Active');
my ($resp);
return undef unless
_send_request($dbh,
$dbh->FETCH('jdbc_socket'), $dbh->FETCH('jdbc_ber'),
[PING_REQ => 0],
[PING_RESP => \$resp]);
return $resp;
}
# Sends a disconnect message to the server. The server will
# attempt to close any open ResultSets and Statements, then
# close the JDBC Connection. This driver's end of the socket
# will be closed.
#
# JDBC: ResultSet.close, Statement.close, Connection.close
sub disconnect {
my ($dbh) = shift;
my ($debug) = $dbh->trace();
# Don't disconnect inactive connections.
return 1 unless $dbh->FETCH('Active');
$dbh->STORE('Active' => 0);
my $resp;
my ($result) = _send_request($dbh,
$dbh->FETCH('jdbc_socket'),
$dbh->FETCH('jdbc_ber'),
[DISCONNECT_REQ => 0],
[DISCONNECT_RESP => \$resp]);
$dbh->FETCH('jdbc_socket')->close();
return $result;
}
# A private disconnect method which can be called from user
# code even in environments such as Apache::DBI which disable
# the standard disconnect. It's possible for a JDBC exception
# to be returned which indicates that the underlying database
# connection is non-functional. The DBD::JDBC server doesn't
# know anything about specific database error codes, so it
# can't handle the exception, but user code may be able to
# tell that the connection should be closed.
sub jdbc_disconnect {
my ($dbh) = shift;
disconnect($dbh);
}
# This is the func implementation. It expects the method name
# to be a valid java.sql.Connection method name. The
# parameter list may be empty if the method takes no
# arguments. Otherwise, parameters may be specified as
( run in 1.935 second using v1.01-cache-2.11-cpan-39bf76dae61 )