Module datasource

Datasource module implements API to manage datasource process.

Copyright © 2010-2014 Alexei Krasnopolski

Version: 1.2.4

Introduced in: 2012-12-18

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

Description

Datasource module implements API to manage datasource process. The process keeps information about given datasource and controlls a pool of connections to DS. A functions get_connection/1, return_connection/2 and invalidate_connection/2 directly delegate calls to the connection pool that creates/reuses/disposes a connections. We can think about datasource module as a wrapper for resource_pool_srv module.

Data Types

client_options()

client_options() = #client_options{}

The record keeps client options that server is capable to support for this client and this connection.
-record(client_options, {

charset_number = 33::0..255
- Character set number: default utf-8 (code= 33).
long_password = 1::0|1
- new more secure passwords.
found_rows = 0::0|1
- Found instead of affected rows.
long_flag = 1::0|1
- Get all column flags.
connect_with_db = 1::0|1
- One can specify db on connect.
no_schema = 0::0|1
- Don't allow database.table.column.
compress = 0::0|1
- Can use compression protocol.
odbc = 0::0|1
- Odbc client.
local_files = 0::0|1
- Can use LOAD DATA LOCAL.
ignore_space = 0::0|1
- Ignore spaces before '('.
protocol_41 = 1::0|1
- New 4.1 protocol.
interactive = 1::0|1
- This is an interactive client.
ssl = 0::0|1
- Switch to SSL after handshake.
ignore_sigpipe = 0::0|1
- IGNORE sigpipes.
transactions = 1::0|1
- Client knows about transactions.
reserved = 0::0|1
- Old flag for 4.1 protocol.
secure_connection = 1::0|1
- New 4.1 authentication.
multi_statements = 1::0|1
- Enable/disable multi-stmt support.
multi_results = 1::0|1
- Enable/disable multi-results.
trans_isolation_level = default::read_uncommitted | read_committed | repeatable_read | serializable
- transaction isolation level.
}).

connection()

connection() = #connection{}

The record keeps information that helps connection server runs.
-record(connection, {

socket :: port()
- tcp socket linked to MySQL server.
owner :: pid()
- pid of process that borrows this connection from connection pool. undefined if the connection is idle.
ds_def :: #datasource{}
- datasource record.
server_info :: #server_info{}
- server info record.
}).

datasource()

datasource() = #datasource{}

datasource record information describes connections pool. The information is using for creating connections of the pool.
-record(datasource, {

name :: atom()
- datasource name.
host = "localhost" :: string()
- server host name or IP.
port = 3306 :: integer()
- host port number.
database = "" :: string()
- database name.
user :: string()
- user logon name.
password :: string()
- password.
flags = #client_options{} :: #client_options{}
- client options for connections of the datasource.
}).

eof_packet()

eof_packet() = #eof_packet{}

represents end of file (EOF) packet received from server after generic query or command.
-record(eof_packet, {

warning_count::integer()
- number of warnings.
server_status::#server_status{}
- server status after query.
}).

error_packet()

error_packet() = #error_packet{}

represents ERROR packet received from server after generic query or command.
-record(error_packet, {

errno::integer()
- MySQL error number.
sqlstate::string()
- MySQL state identifire.
message::string()
- error message.
}).

field_metadata()

field_metadata() = #field_metadata{}

represents field metadata of record set.
-record(field_metadata, {

catalog::string()
- catalog name (unused in recent versions).
schema::string()
- schema (database) name.
table::string()
- table name from sql query (after AS).
origtable::string()
- original table name from schema.
name::string()
- field name from sql query (after AS).
origname::string()
- original field name from schema.
charsetnr::integer()
- code of character set.
length::integer()
- length of the field.
type::0..255
- type of the field (see mysql_types.hrl).
flags::bitstring()
- flags (see mysql_types.hrl).
scale::0..255
- scale.
default::binary()
- default value.
}).

metadata()

metadata() = #metadata{}

represents metadata of record set.
-record(metadata, {

field_count=0::integer()
- field count in the query.
param_count=0::integer()
- parameter count in prepared statement.
server_status::#server_status{}
- server status after query.
field_metadata = []::list(#field_metadata{})
- field metadata is a list of metadata for each field in the query.
param_metadata = []::list(#field_metadata{})
- parameter metadata is a list of metadata for each parameter in the prepared statement..
}).

mysql_decimal()

mysql_decimal() = #mysql_decimal{}

represents value of decimal field.
-record(mysql_decimal, {

int = ""::string()
- integer part.
fraction = ""::string()
- fraction part.
}).

mysql_error()

mysql_error() = #mysql_error{}

Record represents an exception that is thrown by a client's module.
-record(mysql_error, {

type:: tcp | connection | sqlquery | statement | transaction
- .
errno = none:: none | integer()
- .
sqlstate = []::string()
- .
source = []::string()
- .
message = []::string()
- .
}).

mysql_time()

mysql_time() = #mysql_time{}

represents value of time/date field.
-record(mysql_time, {

neg = false::boolean()
- sign of the field.
year = 0::integer()
- year.
month = 0::0..12
- month.
day = 0::0..31
- day of month.
hour = 0::0..23
- hour.
minute = 0::0..59
- minute.
second = 0::0..59
- second.
second_part = 0
- second part.
}).

ok_packet()

ok_packet() = #ok_packet{}

represents OK packet received from server after generic query or command.
-record(ok_packet, {

affected_rows::integer()
- number affected rows in table(s) during processing query.
insert_id::integer()
- insert query returns generated id for new row.
server_status::#server_status{}
- server status after query.
warning_count::integer()
- number of warnings.
message::string()
- warn/error message.
}).

ok_stmt_packet()

ok_stmt_packet() = #ok_stmt_packet{}

represents OK packet received from server after statement prepare command.
-record(ok_stmt_packet, {

stmt_handle::integer()
- prepared statement handle for using with following commands.
columns_number::integer()
- number of columns in prepared statement.
params_number::integer()
- number of parameters in prepared statement.
warn_count::integer()
- number of warnings.
}).

packet()

packet() = #packet{}

represents binary packet for low level network connection.
-record(packet, {

continue = false::boolean()
- indicates it is not last packet in sequence.
seq_number = 0::integer()
- number of the packet in sequence.
uncompressed_size = 0::integer()
- size of packet before compression.
body = <<>>::binary()
- binary body of the packet.
}).

rs_header()

rs_header() = #rs_header{}

represents a header of record set.
-record(rs_header, {

field_count::integer()
- number of fields in record set.
extra::any()
- extra information.
}).

server_info()

server_info() = #server_info{}

The server_info() contains information that SQL server sent during handshake about itself. -record(server_info, {

protocol_version::integer()
- protocol version.
server_version::string()
- server version.
thread_Id::integer()
- current connection thread ID.
server_capabilities::#client_options{}
- server capabilities.
server_status::#server_status{}
- server status.
scramble_buff::binary()
- scrumble buffer for password encryption.
}).

server_status()

server_status() = #server_status{}

The server_status() record contains information about status of SQL server after query.
-record(server_status, {

inTransaction = false::boolean()
- Transaction has started.
autocommit = false::boolean()
- Server in auto_commit mode.
moreResultExists = false::boolean()
- Multi query - next query exists.
queryNoGoodIndexUsed = false::boolean()
- .
queryNoIndexUsed = false::boolean()
- .
cursorExists = false::boolean()
- read-only non-scrollable cursor for a query was opened.
lastRowSent = false::boolean()
- read-only cursor is exhausted.
noBackSlashEscapes = true::boolean()
- .
queryWasSlow = false::boolean()
- this query was logged to the slow query log.
psOutParams = false::boolean()
- To mark ResultSet containing output parameter values.
}).

Function Index

change_user/4Changes user for the datasource.
close/1Stops datasource DS_name and disposes all linked resources.
get_connection/1Provides with connection process pid.
invalidate_connection/2Sends request to dispose the connection.
return_connection/2Returns the connection to connection pool.
select_db/2Selects or changes current database (or schema).

Function Details

close/1

close(DS_name::atom()) -> ok | {error, Error}

Stops datasource DS_name and disposes all linked resources.

change_user/4

change_user(Connection_name::pid(), User::string(), Password::string(), Db::string) -> #connection{} | #mysql_error{}

Changes user for the datasource. This change concerns all connections of the connected datasource/pool.

See also: helper_connection:change_user/4.

select_db/2

select_db(Connection_name::pid(), DBName::string()) -> Result

Selects or changes current database (or schema). Change concerns all connections of the given datasource/pool.

get_connection/1

get_connection(DS_name::atom()) -> pid() | #mysql_error{}

Provides with connection process pid. Connection pool returns idle connection or creates new connection process if no idle connection is found.

return_connection/2

return_connection(DS_name::atom(), Resource::pid()) -> ok | #mysql_error{}

Returns the connection to connection pool.

invalidate_connection/2

invalidate_connection(DS_name::atom(), Resource::pid()) -> ok | #mysql_error{}

Sends request to dispose the connection.


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