<commit_before>%%% The MIT License (MIT)

%%% Copyright (c) 2016-2018 <NAME><<EMAIL>>

-module(efirebirdsql_protocol).

-export([connect/5, connect/6, detach/1, begin_transaction/2]).
-export([allocate_statement/1, prepare_statement/2, free_statement/1]).
-export([execute/2, execute2/2, fetchrows/1, description/2]).
-export([commit/1, rollback/1]).

-include("efirebirdsql.hrl").

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Utility functions in module

connect_database(TcpMod, Sock, Username, Password, Database, PageSize, IsCreateDB, State) ->
    case IsCreateDB of
        true ->
            create_database(TcpMod, Sock, Username, Password, Database, PageSize, State);
        false ->
            attach_database(TcpMod, Sock, Username, Password, Database, State)
    end.

attach_database(TcpMod, Sock, User, Password, Database, State) ->
    TcpMod:send(Sock,
        efirebirdsql_op:op_attach(User, Password, Database, State#state.accept_version)),
    case efirebirdsql_op:get_response(TcpMod, Sock) of
        {op_response, {ok, Handle, _}} ->
            State2 = State#state{db_handle=Handle},
            allocate_statement(State2);
        {op_response, {error, Msg}} ->
            {{error, Msg}, State}
    end.

create_database(TcpMod, Sock, User, Password, Database, PageSize, State) ->
    TcpMod:send(Sock,
        efirebirdsql_op:op_create(User, Password, Database, PageSize, State#state.accept_version)),
    case efirebirdsql_op:get_response(TcpMod, Sock) of
        {op_response, {ok, Handle, _}} ->
            State2 = State#state{db_handle=Handle},
            allocate_statement(State2);
        {op_response, {error, Msg}} ->
            {{error, Msg}, State}
    end.

allocate_statement(TcpMod, Sock, DbHandle) ->
    TcpMod:send(Sock,
        efirebirdsql_op:op_allocate_statement(DbHandle)),
    case efirebirdsql_op:get_response(TcpMod, Sock) of
        {op_response, {ok, Handle, _}} -> {ok, Handle};
        {op_response, {error, Msg}} ->{error, Msg}
    end.


connect(Host, Username, Password, Database, IsCreateDB, PageSize, State) ->
    TcpMod = State#state.mod,
    Sock = State#state.sock,
    TcpMod:send(Sock,
        efirebirdsql_op:op_connect(Host, Username, Password, Database, State#state.public_key, State#state.wire_crypt)),
    case efirebirdsql_op:get_response(TcpMod, Sock) of
        {op_accept, {AcceptVersion, _AcceptType}} ->
            connect_database(TcpMod, Sock, Username, Password, Database, PageSize, IsCreateDB, State#state{accept_version=AcceptVersion});
        {op_cond_accept, {_AcceptVersion, _AcceptType}} ->
            io:format("op_cond_accept");
        {op_accept_data, {_AcceptVersion, _AcceptType}} -><commit_msg>remove function<commit_after>%%% The MIT License (MIT)

%%% Copyright (c) 2016-2018 <NAME><<EMAIL>>

-module(efirebirdsql_protocol).

-export([connect/5, connect/6, detach/1, begin_transaction/2]).
-export([allocate_statement/1, prepare_statement/2, free_statement/1]).
-export([execute/2, execute2/2, fetchrows/1, description/2]).
-export([commit/1, rollback/1]).

-include("efirebirdsql.hrl").

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Utility functions in module

connect_database(TcpMod, Sock, Username, Password, Database, PageSize, IsCreateDB, State) ->
    case IsCreateDB of
        true ->
            create_database(TcpMod, Sock, Username, Password, Database, PageSize, State);
        false ->
            attach_database(TcpMod, Sock, Username, Password, Database, State)
    end.

attach_database(TcpMod, Sock, User, Password, Database, State) ->
    TcpMod:send(Sock,
        efirebirdsql_op:op_attach(User, Password, Database, State#state.accept_version)),
    case efirebirdsql_op:get_response(TcpMod, Sock) of
        {op_response, {ok, Handle, _}} ->
            State2 = State#state{db_handle=Handle},
            allocate_statement(State2);
        {op_response, {error, Msg}} ->
            {{error, Msg}, State}
    end.

create_database(TcpMod, Sock, User, Password, Database, PageSize, State) ->
    TcpMod:send(Sock,
        efirebirdsql_op:op_create(User, Password, Database, PageSize, State#state.accept_version)),
    case efirebirdsql_op:get_response(TcpMod, Sock) of
        {op_response, {ok, Handle, _}} ->
            State2 = State#state{db_handle=Handle},
            allocate_statement(State2);
        {op_response, {error, Msg}} ->
            {{error, Msg}, State}
    end.

connect(Host, Username, Password, Database, IsCreateDB, PageSize, State) ->
    TcpMod = State#state.mod,
    Sock = State#state.sock,
    TcpMod:send(Sock,
        efirebirdsql_op:op_connect(Host, Username, Password, Database, State#state.public_key, State#state.wire_crypt)),
    case efirebirdsql_op:get_response(TcpMod, Sock) of
        {op_accept, {AcceptVersion, _AcceptType}} ->
            connect_database(TcpMod, Sock, Username, Password, Database, PageSize, IsCreateDB, State#state{accept_version=AcceptVersion});
        {op_cond_accept, {_AcceptVersion, _AcceptType}} ->
            io:format("op_cond_accept");
        {op_accept_data, {_AcceptVersion, _AcceptType}} ->
{'fraction_non_alphanumeric': 0.16336347893015202, 'fraction_numerical': 0.010005772561092939, 'mean_word_length': 3.9084041548630784, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '494391', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1654, 'n_words': 327}