Packages
mysql_client
1.2.8
MySQL native client is written in Erlang and provides API that is very close to Connector/C library.
Current section
Files
Jump to
Current section
Files
doc/connection.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Module connection</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
</head>
<body bgcolor="white">
<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
<hr>
<h1>Module connection</h1>
<ul class="index"><li><a href="#description">Description</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul>
Connection module expose function for operations/queries on connected MySQL server.
<p>Copyright © 2010-2014 Alexei Krasnopolski</p>
<p><b>Version:</b> 1.2.8</p>
<p><b>Introduced in:</b> 2012-12-17</p>
<p><b>Authors:</b> Alexei Krasnopolski (<a href="mailto:krasnop@bellsouth.net"><tt>krasnop@bellsouth.net</tt></a>) [<em>web site:</em> <tt><a href="http://krasnopolski.org/" target="_top">http://krasnopolski.org/</a></tt>].</p>
<p><b>References</b><ul><li><a href="http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol" target="_top"><tt>http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol</tt></a></li></ul></p>
<h2><a name="description">Description</a></h2>
Connection module expose function for operations/queries on connected MySQL server.
The module contains client API functions for all allowed operations.
<h2><a name="index">Function Index</a></h2>
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#connection_record-1">connection_record/1</a></td><td>Returns #connection{} record decribed given connection.</td></tr>
<tr><td valign="top"><a href="#is_open-1">is_open/1</a></td><td>Returns true if connection is open and healthy.</td></tr>
<tr><td valign="top"><a href="#execute_query-2">execute_query/2</a></td><td>Executes SQL query and return a tuple of field metadata information and list of result rows.</td></tr>
<tr><td valign="top"><a href="#get_field_list-3">get_field_list/3</a></td><td>Returns list of field metadata records for table 'Table_name'.</td></tr>
<tr><td valign="top"><a href="#prepare_statement-2">prepare_statement/2</a></td><td>Send command to prepare statement.</td></tr>
<tr><td valign="top"><a href="#get_prepared_statement_handle-2">get_prepared_statement_handle/2</a></td><td>The same is prepare_statement/2 but it has short return: just a handle
of a prepared statement.</td></tr>
<tr><td valign="top"><a href="#send_statement_long_parameter-4">send_statement_long_parameter/4</a></td><td>Sends parameter of prepered statement to SQL server before statement execution.</td></tr>
<tr><td valign="top"><a href="#execute_statement-4">execute_statement/4</a></td><td>Executes prepared statement represented with Handler.</td></tr>
<tr><td valign="top"><a href="#execute_statement-6">execute_statement/6</a></td><td>The same as execute_statement/4 except parameter New.</td></tr>
<tr><td valign="top"><a href="#close_statement-2">close_statement/2</a></td><td>The command closes prepared statement and frees corresponded resources on server.</td></tr>
<tr><td valign="top"><a href="#reset_statement-2">reset_statement/2</a></td><td>Resets prepared statement and removes all cashed data on server.</td></tr>
<tr><td valign="top"><a href="#fetch_statement-4">fetch_statement/4</a></td><td>Fetchs data from a cursor that was created by statement execution.</td></tr>
<tr><td valign="top"><a href="#transaction-2">transaction/2</a></td><td>executes a transaction.</td></tr>
</table>
<h2><a name="functions">Function Details</a></h2>
<h3 class="function"><a name="connection_record-1">connection_record/1</a></h3>
<div class="spec">
<p><tt>connection_record(Connection_pid::pid()) -> #connection{} | #mysql_error{}</tt><br></p>
<p> </p>
</div><p>Returns #connection{} record decribed given connection.
</p>
<h3 class="function"><a name="is_open-1">is_open/1</a></h3>
<div class="spec">
<p><tt>is_open(Connection_pid::pid()) -> true | false</tt><br></p>
<p> </p>
</div><p>Returns true if connection is open and healthy.
</p>
<h3 class="function"><a name="execute_query-2">execute_query/2</a></h3>
<div class="spec">
<p><tt>execute_query(Connection_pid::pid(), Query::string()) -> Result</tt>
<ul class="definitions"><li><tt>Result = {Metadata::#metadata{}, ResultSet} | #mysql_error{}</tt></li><li><tt>ResultSet = [Row]</tt></li><li><tt>Row = [integer() | float() | string() | binary() | #mysql_time{} | #mysql_decimal{}]</tt></li></ul></p>
<p> </p>
</div><p>Executes SQL query and return a tuple of field metadata information and list of result rows.</p>
<p><b>See also:</b> <a href="packet_response.html#handle_response-2">packet_response:handle_response/2</a>.</p>
<h3 class="function"><a name="get_field_list-3">get_field_list/3</a></h3>
<div class="spec">
<p><tt>get_field_list(Connection_pid::pid(), Table_name::string(), Column_name::string()) -> Result</tt>
<ul class="definitions"><li><tt>Result = {Metadata::#metadata{}, []} | #mysql_error{}</tt></li></ul></p>
<p> </p>
</div><p>Returns list of field metadata records for table 'Table_name'. Column_name is requalar
expression using symbols % and _ to filter column names for return.
</p>
<h3 class="function"><a name="prepare_statement-2">prepare_statement/2</a></h3>
<div class="spec">
<p><tt>prepare_statement(Connection_pid::#connection{}, Statement::string()) -> Result</tt>
<ul class="definitions"><li><tt>Result = {Metadata::#metadata{}, [#ok_stmt_packet{}]} | #mysql_error{}</tt></li></ul></p>
<p> </p>
</div><p>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.
</p>
<h3 class="function"><a name="get_prepared_statement_handle-2">get_prepared_statement_handle/2</a></h3>
<div class="spec">
<p><tt>get_prepared_statement_handle(Connection_pid::pid(), Statement::string()) -> integer()</tt><br></p>
<p> </p>
</div><p>The same is prepare_statement/2 but it has short return: just a handle
of a prepared statement.
</p>
<h3 class="function"><a name="send_statement_long_parameter-4">send_statement_long_parameter/4</a></h3>
<div class="spec">
<p><tt>send_statement_long_parameter(Connection_pid, Handle, Parameter_index, Parameter) -> any()</tt>
<ul class="definitions"><li><tt>Connection_pid = pid()</tt></li><li><tt>Handle = integer()</tt></li><li><tt>Parameter_index = integer()</tt></li><li><tt>Parameter = binary()</tt></li></ul></p>
<p> </p>
</div><p>Sends parameter of prepered statement to SQL server before statement execution.
</p>
<h3 class="function"><a name="execute_statement-4">execute_statement/4</a></h3>
<div class="spec">
<p><tt>execute_statement(Connection_pid, Handle, Parameter_types, Parameters) -> Result</tt>
<ul class="definitions"><li><tt>Connection_pid = pid()</tt></li><li><tt>Handle = integer()</tt></li><li><tt>Parameter_types = [integer()]</tt></li><li><tt>Parameters = [term()]</tt></li><li><tt>Result = {Metadata::#metadata{}, ResultSet} | #mysql_error{}</tt></li><li><tt>ResultSet = [Row]</tt></li><li><tt>Row = [integer() | float() | string() | binary() | #mysql_time{} | #mysql_decimal{}]</tt></li></ul></p>
<p> </p>
</div><p>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.</p>
<p><b>See also:</b> <a href="#execute_statement-5">execute_statement/5</a>.</p>
<h3 class="function"><a name="execute_statement-6">execute_statement/6</a></h3>
<div class="spec">
<p><tt>execute_statement(Connection_pid, Handle, Parameter_types, Parameters, Flags, New) -> Result</tt>
<ul class="definitions"><li><tt>Connection_pid = pid()</tt></li><li><tt>Handle = integer()</tt></li><li><tt>Parameter_types = [integer()]</tt></li><li><tt>Parameters = [term()]</tt></li><li><tt>Flags = integer()</tt></li><li><tt>New = boolean()</tt></li><li><tt>Result = {Metadata::#metadata{}, ResultSet} | #mysql_error{}</tt></li><li><tt>ResultSet = [Row]</tt></li><li><tt>Row = [integer() | float() | string() | binary() | #mysql_time{} | #mysql_decimal{}]</tt></li></ul></p>
<p> </p>
</div><p>Equivalent to <tt>execute_statement / 4</tt>.</p>
<p>The same as execute_statement/4 except parameter New. The New equals true forces command send parameter types to server.</p>
<h3 class="function"><a name="close_statement-2">close_statement/2</a></h3>
<div class="spec">
<p><tt>close_statement(Connection_pid::pid(), Handle::integer()) -> {Metadata::#metadata{}, []} | #mysql_error{}</tt><br></p>
<p> </p>
</div><p>The command closes prepared statement and frees corresponded resources on server.
</p>
<h3 class="function"><a name="reset_statement-2">reset_statement/2</a></h3>
<div class="spec">
<p><tt>reset_statement(Connection_pid::pid(), Handle::integer()) -> {Metadata::#metadata{}, []} | #mysql_error{}</tt><br></p>
<p> </p>
</div><p>Resets prepared statement and removes all cashed data on server.
</p>
<h3 class="function"><a name="fetch_statement-4">fetch_statement/4</a></h3>
<div class="spec">
<p><tt>fetch_statement(Connection_pid, Handle, Metadata, Row_number) -> Result</tt>
<ul class="definitions"><li><tt>Connection_pid = pid()</tt></li><li><tt>Handle = integer()</tt></li><li><tt>Metadata = #metadata{}</tt></li><li><tt>Row_number = integer()</tt></li><li><tt>Result = {Metadata::#metadata{}, ResultSet} | #mysql_error{}</tt></li><li><tt>ResultSet = [Row]</tt></li><li><tt>Row = [integer() | float() | string() | binary() | #mysql_time{} | #mysql_decimal{}]</tt></li></ul></p>
<p> </p>
</div><p>Fetchs data from a cursor that was created by statement execution.
</p>
<h3 class="function"><a name="transaction-2">transaction/2</a></h3>
<div class="spec">
<p><tt>transaction(Connection_pid::pid(), F::function()) -> any() | #mysql_error{type = transaction}</tt><br></p>
<p> </p>
</div><p>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.
</p>
<hr>
<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
<p><i>Generated by EDoc</i></p>
</body>
</html>