mysql

A native D driver for the MySQL database system. Source file mysql.d.

This module attempts to provide composite objects and methods that will allow a wide range of common database operations, but be relatively easy to use. The design is a first attempt to illustrate the structure of a set of modules to cover popular database systems and ODBC.

It has no dependecies on GPL header files or libraries, instead communicating directly with the server via the published client/server protocol.

http://forge.mysql.com/wiki/MySQL_Internals_ClientServer_Protocol
http://forge.mysql.com/w/index.php?title=MySQL_Internals_ClientServer_Protocol&diff=5078&oldid=4374

This version is not by any means comprehensive, and there is still a good deal of work to do. As a general design position it avoids providing wrappers for operations that can be accomplished by simple SQL sommands, unless the command produces a result set. There are some instances of the latter category to provide simple meta-data for the database,

Its primary objects are:

  • Connection:
    • Connection to the server, and querying and setting of server parameters.
  • Command: Handling of SQL requests/queries/commands, with principal methods:
    • execSQL() - plain old SQL query.
    • execTuple() - get a set of values from a select or similar query into a matching tuple of D variables.
    • execPrepared() - execute a prepared statement.
    • execResult() - execute a raw SQL statement and get a complete result set.
    • execSequence() - execute a raw SQL statement and handle the rows one at a time.
    • execPreparedResult() - execute a prepared statement and get a complete result set.
    • execPreparedSequence() - execute a prepared statement and handle the rows one at a time.
    • execFunction() - execute a stored function with D variables as input and output.
    • execProcedure() - execute a stored procedure with D variables as input.
  • ResultSet:
    • A random access range of rows, where a Row is basically an array of variant.
  • ResultSequence:
      $(LIAn input range of similar rows.)

It has currently only been compiled and unit tested on Ubuntu with D2.055 using a TCP loopback connection to a server on the local machine.

There are numerous examples of usage in the unittest sections.

The file mysqld.sql, included with the module source code, can be used to generate the tables required by the unit tests.

There is an outstanding issue with Connections. Normally MySQL clients sonnect to a server on the same machine via a Unix socket on *nix systems, and through a named pipe on Windows. Neither of these conventions is currently supported. TCP must be used for all connections.

Since there is currently no SHA1 support on Phobos, a simple translation of the NIST example C code for SHA1 is also included with this module.

Members

Aliases

CSN
alias CSN = ColumnSpecialization
Undocumented in source.
MYX
alias MYX = MySQLException
Undocumented in source.
PSN
alias PSN = ParameterSpecialization
Undocumented in source.

Classes

Connection
class Connection

A struct representing a database connection.

MySQLException
class MySQLException

An exception type to distinguish exceptions thrown by this module.

Enums

RefreshFlags
enum RefreshFlags

Server refresh flags

SQLType
enum SQLType

Column type codes

SvrCapFlags
enum SvrCapFlags

Server capability flags.

Functions

getInt
uint getInt(ubyte* ubp)
Undocumented in source. Be warned that the author may not have intended to support it.
getInt24
uint getInt24(ubyte* ubp)
Undocumented in source. Be warned that the author may not have intended to support it.
getShort
ushort getShort(ubyte* ubp)
Undocumented in source. Be warned that the author may not have intended to support it.
pack
ubyte[] pack(TimeOfDay tod)

Function to pack a TimeOfDay into a binary encoding for transmission to the server.

pack
ubyte[] pack(Date dt)

Function to pack a Date into a binary encoding for transmission to the server.

pack
ubyte[] pack(DateTime dt)

Function to pack a DateTime into a binary encoding for transmission to the server.

packLCS
ubyte[] packLCS(void[] a)
Undocumented in source. Be warned that the author may not have intended to support it.
packLength
ubyte[] packLength(size_t l, size_t offset)
Undocumented in source. Be warned that the author may not have intended to support it.
parseLCB
ulong parseLCB(ubyte* ubp, bool nullFlag)
Undocumented in source. Be warned that the author may not have intended to support it.
parseLCS
ubyte[] parseLCS(ubyte* ubp, bool nullFlag)
Undocumented in source. Be warned that the author may not have intended to support it.
toDate
Date toDate(ubyte[] a)

Function to extract a Date from a binary encoded row.

toDate
Date toDate(string s)

Function to extract a Date from a text encoded column value.

toDateTime
DateTime toDateTime(ubyte[] a)

Function to extract a DateTime from a binary encoded row.

toDateTime
DateTime toDateTime(string s)

Function to extract a DateTime from a text encoded column value.

toDateTime
DateTime toDateTime(ulong x)

Function to extract a DateTime from a ulong.

toTimeDiff
TimeDiff toTimeDiff(ubyte[] a)

Function to extract a time difference from a binary encoded row.

toTimeDiff
TimeDiff toTimeDiff(string s)

Function to extract a time difference from a text encoded column value.

toTimeOfDay
TimeOfDay toTimeOfDay(ubyte[] a)

Function to extract a TimeOfDay from a binary encoded row.

toTimeOfDay
TimeOfDay toTimeOfDay(string s)

Function to extract a TimeOfDay from a text encoded column value.

Structs

Column
struct Column

Composite representation of a column value

ColumnSpecialization
struct ColumnSpecialization

A struct to represent specializations of prepared statement parameters.

Command
struct Command

Encapsulation of an SQL command or query.

EOFPacket
struct EOFPacket

A struct representing an EOF packet

FieldDescription
struct FieldDescription

A struct representing a field (column) description packet

MetaData
struct MetaData

Facilities to recover meta-data from a connection

MySQLColumn
struct MySQLColumn

A struct to hold column metadata

MySQLProcedure
struct MySQLProcedure

A struct to hold stored function metadata

OKPacket
struct OKPacket

A struct representing an OK or Error packet

ParamDescription
struct ParamDescription

A struct representing a prepared statement parameter description packet

ParameterSpecialization
struct ParameterSpecialization

A struct to represent specializations of prepared statement parameters.

PreparedStmtHeaders
struct PreparedStmtHeaders

A struct representing the collation of a prepared statement parameter description sequence

ResultSequence
struct ResultSequence

An input range of Rows.

ResultSet
struct ResultSet

A Random access range of Rows.

ResultSetHeaders
struct ResultSetHeaders

A struct representing the collation of a sequence of FieldDescription packets.

Row
struct Row

A struct to represent a single row of a result set.

TimeDiff
struct TimeDiff

A simple struct to represent time difference.

Timestamp
struct Timestamp

A D struct to stand for a TIMESTAMP

Variables

defaultClientFlags
uint defaultClientFlags;
Undocumented in source.

Meta

Authors

Steve Teale