Connection

A class representing a database connection.

If you are using Vibe.d, consider using mysql.pool.MySQLPool instead of creating a new Connection directly. That will provide certain benefits, such as reusing old connections and automatic cleanup (no need to close the connection when done).

// Suggested usage:

{
	auto con = new Connection("host=localhost;port=3306;user=joe;pwd=pass123;db=myappsdb");
	scope(exit) con.close();

	// Use the connection
	...
}
class Connection {}

Constructors

this
this(string host, string user, string pwd, string db, ushort port, SvrCapFlags capFlags)
this(MySQLSocketType socketType, string host, string user, string pwd, string db, ushort port, SvrCapFlags capFlags)
this(OpenSocketCallbackPhobos openSocket, string host, string user, string pwd, string db, ushort port, SvrCapFlags capFlags)
this(OpenSocketCallbackVibeD openSocket, string host, string user, string pwd, string db, ushort port, SvrCapFlags capFlags)
this(string cs, SvrCapFlags capFlags)
this(MySQLSocketType socketType, string cs, SvrCapFlags capFlags)
this(OpenSocketCallbackPhobos openSocket, string cs, SvrCapFlags capFlags)
this(OpenSocketCallbackVibeD openSocket, string cs, SvrCapFlags capFlags)

Construct opened connection.

Members

Enums

OpenState
enum OpenState
Undocumented in source.

Functions

autoPurge
void autoPurge()

Called whenever mysql-native needs to send a command to the server and be sure there aren't any pending results (which would prevent a new command from being sent).

bumpPacket
void bumpPacket()
Undocumented in source. Be warned that the author may not have intended to support it.
close
void close()

Explicitly close the connection.

connect
void connect(SvrCapFlags clientCapabilities)
Undocumented in source.
enableMultiStatements
void enableMultiStatements(bool on)

Enable multiple statement commands.

getPreparedServerInfo
Nullable!PreparedServerInfo getPreparedServerInfo(const(char[]) sql)

Returns null if not found

initConnection
void initConnection()
Undocumented in source. Be warned that the author may not have intended to support it.
isRegistered
bool isRegistered(Prepared prepared)
bool isRegistered(const(char[]) sql)
bool isRegistered(Nullable!PreparedServerInfo info)

Is the given statement registered on this connection as a prepared statement?

kill
void kill()

Forcefully close the socket without sending the quit command.

pingServer
OKErrorPacket pingServer()

Check the server status.

purgeResult
ulong purgeResult()

Flush any outstanding result set elements.

reconnect
void reconnect()
void reconnect(SvrCapFlags clientCapabilities)

Reconnects to the server using the same connection settings originally used to create the Connection.

refreshServer
OKErrorPacket refreshServer(RefreshFlags flags)

Refresh some feature(s) of the server.

register
void register(Prepared prepared)
void register(const(char[]) sql)

Manually register a prepared statement on this connection.

registerIfNeeded
PreparedServerInfo registerIfNeeded(const(char[]) sql)

If already registered, simply returns the cached PreparedServerInfo.

release
void release(Prepared prepared)
void release(const(char[]) sql)

Manually release a prepared statement on this connection.

releaseAll
void releaseAll()

Manually release all prepared statements on this connection.

releaseQueued
void releaseQueued()

Releases all prepared statements that are queued for release.

resetPacket
void resetPacket()
Undocumented in source. Be warned that the author may not have intended to support it.
selectDB
void selectDB(string dbName)

Select a current database.

serverStats
string serverStats()

Get a textual report on the server status.

Properties

charSet
ubyte charSet [@property getter]

Current character set

closed
bool closed [@property getter]

Check whether this Connection is still connected to the server, or if the connection has been closed.

currentDB
string currentDB [@property getter]

Current database

hasPending
bool hasPending [@property getter]

Gets whether anything (rows, headers or binary) is pending. New commands cannot be sent on a connection while anything is pending (the pending data will automatically be purged.)

lastCommandID
ulong lastCommandID [@property getter]

This gets incremented every time a command is issued or results are purged, so a mysql.result.ResultRange can tell whether it's been invalidated.

lastInsertID
ulong lastInsertID [@property getter]

After a command that inserted a row into a table with an auto-increment ID column, this method allows you to retrieve the last insert ID.

pktNumber
ubyte pktNumber [@property getter]

ordering. First packet should have 0

protocol
ubyte protocol [@property getter]

Return the in-force protocol number.

resultFieldDescriptions
FieldDescription[] resultFieldDescriptions [@property getter]

Gets the result header's field descriptions.

rowsPending
bool rowsPending [@property getter]

Gets whether rows are pending.

serverCapabilities
uint serverCapabilities [@property getter]

Server capability flags

serverStatus
ushort serverStatus [@property getter]

Server status

serverVersion
string serverVersion [@property getter]

Server version

socketType
MySQLSocketType socketType [@property getter]

Socket type being used, Phobos or Vibe.d

Static functions

defaultOpenSocketPhobos
PlainPhobosSocket defaultOpenSocketPhobos(string host, ushort port)
Undocumented in source. Be warned that the author may not have intended to support it.
defaultOpenSocketVibeD
PlainVibeDSocket defaultOpenSocketVibeD(string host, ushort port)
Undocumented in source. Be warned that the author may not have intended to support it.
parseConnectionString
string[] parseConnectionString(string cs)

Parses a connection string of the form "host=localhost;port=3306;user=joe;pwd=pass123;db=myappsdb"

Variables

_binaryPending
bool _binaryPending;
_cCaps
SvrCapFlags _cCaps;
Undocumented in source.
_clientCapabilities
SvrCapFlags _clientCapabilities;
Undocumented in source.
_cpn
ubyte _cpn;

Packet Number in packet header. Serial number to ensure correct

_db
string _db;
Undocumented in source.
_fieldCount
ushort _fieldCount;
_headersPending
bool _headersPending;
Undocumented in source.
_host
string _host;
Undocumented in source.
_insertID
ulong _insertID;
Undocumented in source.
_lastCommandID
ulong _lastCommandID;
Undocumented in source.
_open
OpenState _open;
Undocumented in source.
_openSocketPhobos
OpenSocketCallbackPhobos _openSocketPhobos;
Undocumented in source.
_openSocketVibeD
OpenSocketCallbackVibeD _openSocketVibeD;
Undocumented in source.
_port
ushort _port;
_protocol
ubyte _protocol;
_pwd
string _pwd;
Undocumented in source.
_rowsPending
bool _rowsPending;
Undocumented in source.
_rsh
ResultSetHeaders _rsh;
Undocumented in source.
_sCaps
SvrCapFlags _sCaps;
Undocumented in source.
_sCharSet
ubyte _sCharSet;
Undocumented in source.
_sThread
uint _sThread;
Undocumented in source.
_serverStatus
ushort _serverStatus;
Undocumented in source.
_serverVersion
string _serverVersion;
Undocumented in source.
_socket
MySQLSocket _socket;
Undocumented in source.
_socketType
MySQLSocketType _socketType;
_user
string _user;
Undocumented in source.

Meta