Mssqlex v2.0.0-beta.0 Mssqlex.Protocol View Source

Implementation of DBConnection behaviour for Mssqlex.ODBC.

Handles translation of concepts to what ODBC expects and holds state for a connection.

This module is not called directly, but rather through other Mssqlex modules or DBConnection functions.

Link to this section Summary

Functions

Deallocate a cursor declared by c:handle_declare/4 with the database. Return {:ok, result, state} on success and to continue, {:error, exception, state} to return an error and continue, or {:disconnect, exception, state} to return an error and disconnect.

Declare a cursor using a query prepared by c:handle_prepare/3. Return {:ok, query, cursor, state} to return altered query query and cursor cursor for a stream and continue, {:error, exception, state} to return an error and continue or {:disconnect, exception, state} to return an error and disconnect.

Fetch the next result from a cursor declared by c:handle_declare/4. Return {:cont, result, state} to return the result result and continue using cursor, {:halt, result, state} to return the result result and close the cursor, {:error, exception, state} to return an error and close the cursor, {:disconnect, exception, state} to return an error and disconnect.

Handle getting the transaction status. Return {:idle, state} if outside a transaction, {:transaction, state} if inside a transaction, {:error, state} if inside an aborted transaction, or {:disconnect, exception, state} to error and disconnect.

Called when the connection has been idle for a period of time. Return {:ok, state} to continue or {:disconnect, exception, state} to disconnect.

Link to this section Types

Link to this type

state()

View Source
state() :: %Mssqlex.Protocol{
  conn_opts: Keyword.t(),
  mssql: :idle | :transaction | :auto_commit,
  pid: pid()
}

Process state.

Includes:

  • :pid: the pid of the ODBC process
  • :mssql: the transaction state. Can be :idle (not in a transaction), :transaction (in a transaction) or :auto_commit (connection in autocommit mode)
  • :conn_opts: the options used to set up the connection.
Link to this type

status()

View Source
status() :: :idle | :transaction | :error

Link to this section Functions

Link to this function

handle_deallocate(query, cursor, opts, state)

View Source

Deallocate a cursor declared by c:handle_declare/4 with the database. Return {:ok, result, state} on success and to continue, {:error, exception, state} to return an error and continue, or {:disconnect, exception, state} to return an error and disconnect.

This callback is called in the client process.

Callback implementation for DBConnection.handle_deallocate/4.

Link to this function

handle_declare(query, params, opts, state)

View Source

Declare a cursor using a query prepared by c:handle_prepare/3. Return {:ok, query, cursor, state} to return altered query query and cursor cursor for a stream and continue, {:error, exception, state} to return an error and continue or {:disconnect, exception, state} to return an error and disconnect.

This callback is called in the client process.

Callback implementation for DBConnection.handle_declare/4.

Link to this function

handle_fetch(query, cursor, opts, state)

View Source

Fetch the next result from a cursor declared by c:handle_declare/4. Return {:cont, result, state} to return the result result and continue using cursor, {:halt, result, state} to return the result result and close the cursor, {:error, exception, state} to return an error and close the cursor, {:disconnect, exception, state} to return an error and disconnect.

This callback is called in the client process.

Callback implementation for DBConnection.handle_fetch/4.

Link to this function

handle_first(query, cursor, opts, state)

View Source
Link to this function

handle_next(query, cursor, opts, state)

View Source
Link to this function

handle_status(_, s)

View Source
handle_status(opts(), state()) :: {DBConnection.status(), state()}

Handle getting the transaction status. Return {:idle, state} if outside a transaction, {:transaction, state} if inside a transaction, {:error, state} if inside an aborted transaction, or {:disconnect, exception, state} to error and disconnect.

If the callback returns a :disconnect tuples then status/2 will return :error.

Callback implementation for DBConnection.handle_status/2.

Link to this function

ping(state)

View Source
ping(state :: any()) ::
  {:ok, new_state :: any()} | {:disconnect, Exception.t(), new_state :: any()}

Called when the connection has been idle for a period of time. Return {:ok, state} to continue or {:disconnect, exception, state} to disconnect.

This callback is called if no callbacks have been called after the idle timeout and a client process is not using the state. The idle timeout can be configured by the :idle_interval option. This function can be called whether the connection is checked in or checked out.

This callback is called in the connection process.

Callback implementation for DBConnection.ping/1.