Module connection

Connection module expose function for operations/queries on connected MySQL server.

Copyright © 2010-2014 Alexei Krasnopolski

Version: 1.2.4

Introduced in: 2012-12-17

Authors: Alexei Krasnopolski (krasnop@bellsouth.net) [web site: http://krasnopolski.org/].

References

Description

Connection module expose function for operations/queries on connected MySQL server. The module contains client API functions for all allowed operations.

Function Index

close_statement/2The command closes prepared statement and frees corresponded resources on server.
connection_record/1Returns #connection{} record decribed given connection.
execute_query/2Executes SQL query and return a tuple of field metadata information and list of result rows.
execute_statement/4Executes prepared statement represented with Handler.
execute_statement/6The same as execute_statement/4 except parameter New.
fetch_statement/4Fetchs data from a cursor that was created by statement execution.
get_field_list/3Returns list of field metadata records for table 'Table_name'.
get_prepared_statement_handle/2The same is prepare_statement/2 but it has short return: just a handle of a prepared statement.
is_open/1Returns true if connection is open and healthy.
prepare_statement/2Send command to prepare statement.
reset_statement/2Resets prepared statement and removes all cashed data on server.
send_statement_long_parameter/4Sends parameter of prepered statement to SQL server before statement execution.
transaction/2executes a transaction.

Function Details

connection_record/1

connection_record(Connection_pid::pid()) -> #connection{} | #mysql_error{}

Returns #connection{} record decribed given connection.

is_open/1

is_open(Connection_pid::pid()) -> true | false

Returns true if connection is open and healthy.

execute_query/2

execute_query(Connection_pid::pid(), Query::string()) -> Result

Executes SQL query and return a tuple of field metadata information and list of result rows.

See also: packet_response:handle_response/2.

get_field_list/3

get_field_list(Connection_pid::pid(), Table_name::string(), Column_name::string()) -> Result

Returns list of field metadata records for table 'Table_name'. Column_name is requalar expression using symbols % and _ to filter column names for return.

prepare_statement/2

prepare_statement(Connection_pid::#connection{}, Statement::string()) -> Result

Send command to prepare statement. Returns #ok_stmt_packet.stmt_handle handle of prepared statement that will be used for followed operation with the statement.

get_prepared_statement_handle/2

get_prepared_statement_handle(Connection_pid::pid(), Statement::string()) -> integer()

The same is prepare_statement/2 but it has short return: just a handle of a prepared statement.

send_statement_long_parameter/4

send_statement_long_parameter(Connection_pid, Handle, Parameter_index, Parameter) -> any()

Sends parameter of prepered statement to SQL server before statement execution.

execute_statement/4

execute_statement(Connection_pid, Handle, Parameter_types, Parameters) -> Result

Executes prepared statement represented with Handler. Parameters will replace '?' placeholders in prepared statement. Parameter_types list passes types for each parameter. Returns result as a list of data rows.

See also: execute_statement/5.

execute_statement/6

execute_statement(Connection_pid, Handle, Parameter_types, Parameters, Flags, New) -> Result

Equivalent to execute_statement / 4.

The same as execute_statement/4 except parameter New. The New equals true forces command send parameter types to server.

close_statement/2

close_statement(Connection_pid::pid(), Handle::integer()) -> {Metadata::#metadata{}, []} | #mysql_error{}

The command closes prepared statement and frees corresponded resources on server.

reset_statement/2

reset_statement(Connection_pid::pid(), Handle::integer()) -> {Metadata::#metadata{}, []} | #mysql_error{}

Resets prepared statement and removes all cashed data on server.

fetch_statement/4

fetch_statement(Connection_pid, Handle, Metadata, Row_number) -> Result

Fetchs data from a cursor that was created by statement execution.

transaction/2

transaction(Connection_pid::pid(), F::function()) -> any() | #mysql_error{type = transaction}

executes a transaction. F represents a function with sequence of queries under the transaction management. (f.e F = fun(Connection) -> my:execute_query(...), ... end). The function returns result of F/1 if transaction is successful and returns #mysql_error{} if transaction was rollbacked.


Generated by EDoc, Mar 19 2014, 23:27:00.