From 36bf5cf2d24715a6e0181d8fe36c29f00232f945 Mon Sep 17 00:00:00 2001 From: Hajime Nakagami Date: Mon, 10 Jul 2023 14:51:48 +0900 Subject: [PATCH] ping() by op_info_database --- src/efirebirdsql_op.erl | 11 +++++++++++ src/efirebirdsql_protocol.erl | 27 ++++++++------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/efirebirdsql_op.erl b/src/efirebirdsql_op.erl index 44ff586..08a6c17 100644 --- a/src/efirebirdsql_op.erl +++ b/src/efirebirdsql_op.erl @@ -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, @@ -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]), diff --git a/src/efirebirdsql_protocol.erl b/src/efirebirdsql_protocol.erl index 652446d..7f8adfb 100644 --- a/src/efirebirdsql_protocol.erl +++ b/src/efirebirdsql_protocol.erl @@ -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 @@ -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