Skip to content

Commit

Permalink
ping() by op_info_database
Browse files Browse the repository at this point in the history
  • Loading branch information
nakagami committed Jul 10, 2023
1 parent d4b43ec commit 36bf5cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
11 changes: 11 additions & 0 deletions src/efirebirdsql_op.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
-define(DEBUG_FORMAT(X,Y), ok).

-export([op_connect/6, op_attach/2, op_detach/1, op_create/3, op_transaction/2,
op_info_database/2,
op_allocate_statement/1, op_prepare_statement/3, op_free_statement/2,
op_execute/3, op_execute2/3, op_exec_immediate/2, op_ping/0, op_info_sql/2, op_fetch/2,
op_commit_retaining/1, op_commit/1, op_rollback_retaining/1, op_rollback/1,
Expand Down Expand Up @@ -232,6 +233,16 @@ op_create(Conn, Database, PageSize) ->
efirebirdsql_conv:list_to_xdr_string(Database),
efirebirdsql_conv:list_to_xdr_bytes(Dpb2)])).

%%% database information
op_info_database(DbHandle, InfoRequest) ->
?DEBUG_FORMAT("op_info_database(db_handle=~p,request=~p) -> ", [DbHandle, InfoRequest]),
list_to_binary([
efirebirdsql_conv:byte4(op_val(op_info_database)),
efirebirdsql_conv:byte4(DbHandle),
efirebirdsql_conv:byte4(0),
efirebirdsql_conv:list_to_xdr_bytes(InfoRequest),
efirebirdsql_conv:byte4(?BUFSIZE)]).

%%% begin transaction
op_transaction(DbHandle, Tpb) ->
?DEBUG_FORMAT("op_transaction(db_handle=~p) -> ", [DbHandle]),
Expand Down
27 changes: 8 additions & 19 deletions src/efirebirdsql_protocol.erl
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ prepare_statement(Conn, Stmt) ->

-spec free_statement(conn(), stmt(), atom()) -> {ok, stmt()} | {error, integer(), binary()}.
free_statement(Conn, Stmt, Type) ->
?DEBUG_FORMAT("free_statement() stmt_handle=~p:~p~n", [Stmt#stmt.stmt_handle, Stmt#stmt.sql]),
?DEBUG_FORMAT("free_statement() stmt_handle=~p:type=~p:~p~n", [Stmt#stmt.stmt_handle, Type, Stmt#stmt.sql]),
efirebirdsql_socket:send(Conn,
efirebirdsql_op:op_free_statement(Stmt#stmt.stmt_handle, Type)),
case efirebirdsql_op:get_response(Conn) of
Expand Down Expand Up @@ -279,25 +279,14 @@ ping(Conn) ->
% {op_response, _, _} -> ok;
% _ -> error
% end.
case Conn#conn.auto_commit of
true -> ok;
false ->
case begin_transaction(false, Conn) of
{ok, C2} ->
case allocate_statement(C2) of
{ok, Stmt} ->
free_statement(C2, Stmt, drop),
commit(C2),
ok;
{error, _ErrNo, _Msg} ->
rollback(C2),
error
end;
_ -> error
end
end.


% [isc_info_ods_version, isc_info_end]
efirebirdsql_socket:send(Conn,
efirebirdsql_op:op_info_database(Conn#conn.db_handle, [32, 1])),
case efirebirdsql_op:get_response(Conn) of
{op_response, _, _} -> ok;
{error, _, _} -> error
end.

%% Fetch

Expand Down

0 comments on commit 36bf5cf

Please sign in to comment.