A D wrapper for the MySQL C API

mysqlD

I have noticed a sudden small flurry of visits to this page, which has otherwise sat here for about a year unattended. I have made a couple of small changes. First, to note that this stuff and its companion are posted at GitHub - mysqlD, and mysqlN - the protocol level attempt. I've also switched over the comment/question menu item to be something a little more friendly.

mysqlD wraps libmysqlclient, primary source file is mysqld.d last updated Sat Oct 15 2011.

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 depends on myqsl.d, which is, except for three typedefs, a straight translation into D of the relevant MySQL C API header files

It does not aim to replace the latter. There's lots of stuff in there that is probably used rather infrequently. If you need it, it is there for the calling.

Neither does this version pretend to be comprehensive. At present, explicit support for MySQL stored procedures, transactions, and multi-statement operations in general is missing.

Its primary objects are:

It has currently only been compiled and unit tested on Ubuntu with D2.055, and the MySQL 5.5 client library. The required MySQL header files were translated the hard way, since we don't have the benefit of an htod ln a Linux environment. In the case of relatively complex library header file this is a potential source of errors, since the fact that such a translation compiles is not a guarantee that it is correct. However, it seems to survived all the unit tests I have tried so far.

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. It seems that the MySQL client library embeds a description of the Unix socket to be used for communication with 'localhost' that does not agree with the one used even by some older servers which adopted a different path ages ago. This is currently hard coded into Connection.

There is another issue with std.variant. This can not currently cope with structs of the size used by MySQL to describe dates and times. The current version defines a modified variant - MyVariant that includes these types.

class MySQLDException: object.Exception;
An exception type for MySQLD

If the module encounters a problem it will throw an exception of type MySQLDException.

this(MYSQL* h, string file, int line);
An exception constructor from MySQL API error information.

this(string msg, string file, int line);
An exception constructor from a string - used when MySQLD sees a problem.

alias MyX;
MySQLDException AKA MyX

class Connection;
A class to encapsulate struct MYSQL and its associated functions and to allow connection to a database.

It is likely that at some future stage of development, Connection will be an implementation of an interface DBConnection (or similar).

This is very thin wrapper stuff, but it is pre-requisite, so wrapped to some extent.

this();
Default constructor - Initialize Connection object

this(string connectionString);
Constructor to create an opened Connection

Params:
string connectionString <host=hostname/IP>;user=username;pwd=password;db=database>

MYSQL* handle();
Get connection handle

Returns:
Pointer to a MYSQL struct - used by many mysql_xxx_xx() calls.

void switchUser(string user, string password, string database = null);
Change user.

Params:
string user user name
string password password
databse database to use (optional)

MY_CHARSET_INFO* charSetInfo();
Get current character set info.

Currently there is no other support for character set operations.

string stats();
Get a string showing the current server statistics.

This and the following methods in the Connection class are MySQL specific, though several of them might well be available from other databas implementations. A general purpose interface could provide an LCD set, and a methos to populate a dictionary with implementation-specific stuff.

Returns:
A string like "Uptime: 6646 Threads: 2 Questions: 282 Slow queries: 0 Opens: 42 Flush tables: 1 Open tables: 1 Queries * per second avg: 0.42"

string currentDB();
Query for the current database

Returns:
The name of the current database.

void skipResult();
Get rid of a query result.

Pulls any outstanding data from the server, then frees it. Use if you have executed a query but are only interested in the status.

bool serverOK();
Ping the server to make sure it is still there

Returns:
true if all is well.

string clientVersion();
Get the client version as a string.

Returns:
Version string.

uint clientVersionNumber();
Get the client version as a number

Returns:
Version number.

string hostInfo();
Determine what host we are connected to.

Returns:
A sring like "localhost via TCP/IP".

string serverVersion();
Get the server version as a string.

Returns:
Version string.

uint serverVersionNumber();
Get the server version as a number

Returns:
Version number.

uint protocol();
Get the protocol that is in use

Returns:
? not documented

void open(string cs);
Open a connection to a specified host.

There's an outstanding issue here. It seems like the current client library and my server disagree about the Unix socket to use for a localhost connection. At present I'm fudging the isue with a hard-coded socket path. I'll maybe resolve this when I get round to upgrading my server, but it could well be a client library issue, since the Unix socket actually used by the server is the 'new' version. The one the client library says it can't find is the 'old' version.

Params:
string cs A connection string like host=hostname/IP;user=username;pwd=password;db=database;

void open(string host, string user, string pwd, string db);
Open a connection to a specified host/database.

(Similar socket reservation)

Params:
string host Host name or IP address
string user User name
string pwd password
string db Database name

void close();
Close the connection

bool autoCommit();
Determine the auto-commit mode

Returns:
true if auto-commit is on.

bool autoCommit(bool mode);
Set the auto-commit mode.

Params:
bool mode true/false to set the new mode.

Returns:
The previous mode.

void initialCommand(string sql);
Set a SQL command string to be executed on connection.

See the MySQL documentation for mysql_options() for details of options that can be set.

Params:
string sql A SQL string.

void compress();
Tell the client to compress its communications.

void connectTimeout(uint seconds);
Modify the connection time-out period.

Params:
uint seconds New value in seconds.

void readTimeout(uint seconds);
Modify the time-out period for reads.

Params:
uint seconds New value in seconds.

void writeTimeout(uint seconds);
Modify the time-out period for writes.

Params:

void useNamedPipe();
Tell the client to use a named pipe.

A Windows option - named pipe is default for Linux

void reconnect(bool tryReconnect);
Tell the client to attempt to reconnect if the connection is lost.

void reportTruncation(bool report);
Tell the server to report truncation if the buffer provided for an out parameter is not big enough. Default in MySQL 5 is yes.

Params:
repoert bool yes/no.

struct MySQLColumn;
A struct to hold column metadata

string schema;
The database that the table having this column belongs to.

string table;
The table that this column belongs to.

string name;
The name of the column.

uint index;
Zero based index of the column within a table row.

bool defaultNull;
Is the default value NULL?

string defaultValue;
The default value as a string if not NULL

bool nullable;
Can the column value be set to NULL

string type;
What type is the column - tinyint, char, varchar, blob, date etc

long charsMax;
Capacity in characters, -1L if not applicable

long octetsMax;
Capacity in bytes - same as chars if not a unicode table definition, -1L if not applicable.

short numericPrecision;
Presentation information for numerics, -1L if not applicable.

short numericScale;
Scale information for numerics or NULL, -1L if not applicable.

string charSet;
Character set, "" if not applicable.

string collation;
Collation, "" if not applicable.

string colType;
More detail about the column type, e.g. "int(10) unsigned".

string key;
Information about the column's key status, blank if none.

string extra;
Extra information.

string privileges;
Privileges for logged in user.

string comment;
Any comment that was set at table definition time.

struct MySQLProcedure;
A struct to hold stored function metadata

struct MetaData;
Facilities to recover meta-data from a connection

It is important to bear in mind that the methods provided will only return the information that is available to the connected user. This may well be quite limited.

string[] databases(string like = null);
List the available databases

Note that if you have connected using the credentials of a user with limited permissions you may not get many results.

Params:
string like A simple wildcard expression with '%' or '' terms for a limited selection, or null for all.

string[] tables(string like = null);
List the tables in the current database

Params:
string like A simple wildcard expression with '%' or '' terms for a limited selection, or null for all.

MySQLColumn[] columns(string table);
Get column metadata for a table in the current database

Params:
string table The table name

Returns:
An array of MySQLColumn structs

MySQLProcedure[] functions();
Get list of stored functions in the current database, and their properties

MySQLProcedure[] procedures();
Get list of stored procedures in the current database, and their properties

struct BindExt;
An extension to MYSQL_BIND

The mySQL API deals with character/byte arrays using char*. Since D arrays are length/pointer beasts extra binding information is required. MYSQL_BIND provides a convenient void* extension field.

We point this at the BindExt struct, with fields:
  • pa - a pointer to the bound array, through which we can manipulate its length and rerieve its pointer.
  • chunkBuffer - a ubyte[] that is used as an intermediate buffer when doing chunked transfers.
  • inCD - a delegate used for IN transfers.
  • outCD - a delegate used for out transfers.


struct Command;
A class to encapsulate struct mysql_real_query(), MYSQL_STMT, and their associated functions.

Methods execXXX are provided to execute simple SQL queries/commands, to execute prepared statements, and to create result set objects. There are also ancillary methods to create parameters for prepared statements, etc.

this(Connection con);
Constructor to produce a Command object with no SQL and preset length binding data arrays.

Params:
Connection con Reference to a Connection

this(string constr, string sql);
Constructor to produce a Command object with a current SQL command string

Params:
con Reference to a Connection.
string sql A SQL string.

this(Connection con, string sql);
Constructor to produce a one-off Command object with a current SQL command string

This constructor obtains a Connection on-the-fly, so if you only have one database query to make yu can do so with minimal code.

Params:
Connection con Reference to a Connection.
string sql A SQL string.

@property int disposition();
An int that describes the outcome of a command

@property uint fields();
A uint that gives the number of columns in the result set of a prepared query.

int prepare();
Prepare a command.

Prepare is optional. You only call it in cases where you are going to bind D variables as input sources or output targets, and you want to check how many bindings are needed.

If you don't call it, the execPrepared and execTuple etc methods requiring it will call it for you.

Returns:
The number of input parameters - ? - that were found in the SQL

void close();
Put the Command object back into an initial state, with no associated SQL.

static string escapeString(Connection con, string orig);
Escape a string to be composed into an SQL query.

This needs to be used to launder any user entered string, and string literals used in your program as components of a query string.

Does transformations such as

Params:
string orig the unescaped string.

Returns:
The sanitized string.

@property string sql();
Set the SQL for the Command object.

Returns:
The SQL string currently set for the Command.

@property string sql(string s);
Set the SQL for the Command object.

Params:
sql An SQL string.

Returns:
The previously set string.

Connection connection();
Gets a reference to the connection that was used to create this Command.

void cancel();
Attempt to cancel an ongoing command

void reset();
Put the Command object back into the state before prepare() and execXXX().

The current SQL is retained.

void clearParams();
Clears the arrays of parameters/bind structs created for this object.

void createParam(T)(ref T target, int direction = ParamIn, uint inChunkSize = 0, uint outChunkSize = 0, InChunkDelegate inCD = null, OutChunkDelegate outCD = null);
Create a parameter - in, inout, or out, and possibly 'chunked'.

The new parameter is appended to the appropriate array of binding parameters (in or out or both) associated with the Command object.

If you have a bunch of similar parameters to set up that are all of the same kind, e.g. all IN, and none chunked, or all OUT and not chunked, you can use setInBindings(). As long as you use the correct sequence, you can mix the two approaches.

Example:
setInBindings(a, b, c);
createParam(d, ParamIn, 65535);
setInBindings(e, f, g);


Params:
T The type for the parameter.
target A value of that type from which input will be taken or into which output will be placed.
direction ParamIn, ParamInOut, or ParamOut - defaults to ParamIn
inChunkSize Size of chunks for IN transfer.
outChunkSize Size of chunks for OUT chunked transfer.
inCD delegate for IN transfer.
outCD delegate for OUT transfer.

void createVariantParam(ref MyVariant target, int direction = ParamIn, uint inChunkSize = 0, uint outChunkSize = 0, InChunkDelegate inCD = null, OutChunkDelegate outCD = null);
Create a parameter linked to a Variant - in, inout, or out, and possibly 'chunked'.

The new parameter is appended to the appropriate array of binding parameters (in or out or both) associated with the Command object.

Params:
int direction ParamIn, ParamInOut, or ParamOut - defaults to ParamIn
uint inChunkSize Size of chunks for IN transfer.
uint outChunkSize Size of chunks for OUT chunked transfer.
InChunkDelegate inCD delegate for IN transfer.
OutChunkDelegate outCD delegate for OUT transfer.

void updateIP(T)(ref T target, T newValue);
Update an input parameter prior to a further execution of execPrepared()

This method is required because the in bind properties of string or byte[] parameters need to be adjusted to take into account of the length of the new value and the fact that its pointer will likely have changed.

It's effect is equivalent to a simple assignment of a new value in the case of non-array variables.

You can do a bunch of matching parameters together using updateInBindings().

There is a caveat. You can't do this trick with a chunked input parameter that is tied to a delegate to source the data, but you don't need to.

Params:
T the variable type.
target The variable that will source the data for the parameter.
newValue Its new value.

void updateIP(T)(ref T target);
Update an input parameter prior to a further execution of execPrepared()

This method is required because the in bind properties of string or byte[] parameters need to be adjusted to take into account of the length of the new value and the fact that its pointer will likely have changed.

Use this overload when you have assigned the value yourself, or when some function has modified target,

You can do a bunch of matching parameters together using updateInBindings().

There is a caveat. You can't do this trick with a chunked input parameter that is tied to a delegate to source the data, but you don't need to.

Params:
T the variable type.
target the variable that will source the data for the parameter.

void bindInArray(ref VariantN!(maxSize)[] va);
Create plain (no chunking) IN binding parameters for a bunch of Variants in an array.

Params:
VariantN!(maxSize)[] va Array of MyVariant.

void bindOutArray(ref VariantN!(maxSize)[] va);
Create plain (no chunking) OUT binding parameters for a bunch of Variants in an array.

Params:
VariantN!(maxSize)[] va Array of MyVariant.

void bindInStruct(S)(ref S s);
Create plain (no chunking) IN binding parameters for the fields of a struct.

Params:
S The struct type to be handled.
s Instance of S

void bindOutStruct(S)(ref S s);
Create plain (no chunking) OUT binding parameters for the fields of a struct.

Params:
S The struct type to be handled.
s Instance of S

void setInBindings(T...)(ref T args);
Create plain (no chunking) IN binding parameters from a tuple of variables.

Params:
args List of variables

void setOutBindings(T...)(ref T args);
Create plain (no chunking) OUT binding parameters from a tuple of variables.

Params:
args List of variables

void updateInBindings(T...)(ref T args);
Update a set of IN binding parameters from a tuple of variables.

To use this, the variables must already have had new values assigned.

Params:
args List of variables

int execSQL(out ulong ra);
Execute a plain SQL command.

You can use this method to execute any SQL statement.

The method will provide information about the outcome in addition to the return value. If it was a non-query - something like INSERT, DELETE, or UPDATE, the return value will be NON_QUERY, and the out parameter value should be the number of rows affected.

If the statement was something such as a SELECT, with a potential (though possibly empty) result set, then disposition will be set to RESULT, in which case the getResultSet() method will give you access to it, and the Command object's fields property will be set to the number of columns in the result set. The out parameter ra will be set to zero in this case.

If this method generates a result set, and you subsequently call another execXXX method, the result will be wasted.

Returns:
The result disposition.

Params:
ulong ra out - the number of rows affected or in the result set.

int execPrepared(out ulong ra);
Execute a prepared command.

With MySQL, Almost any SQL statement can be prepared, with input/output parameters either represented by '?' in the SQL statement, or implicit, as in the case where there is a result set. For example:

select col1, col2 from sometable where col3=?

Could require two OUT parameters to receive the results from col1 and col2, and one in parameter to provide the condition. However mysqld splits the cases where there would be a result set, so only IN parameters are considered here. Further work will be required when stored procedures can have IN and OUT parameters.

If you have ? placemarkers, you must bind them to variables in your program using the setInBindings() and/or individually via the createParam() method etc.

You may call prepare() explicitly so that you can check the number of parameters required for the statement. If you don't, execPrepared will call it for you, and will throw if the number of parameters in the SQL and the number of parameters actually created don't match.

If you have not bound any input or output parameters then you could just use execSQL for things like INSERT, UPDATE, and DELETE, and unless you plan to use the same statement many times in a session, this may be more efficient.

Params:
ulong ra out - the number of rows affected or zero if there is a result set.

Returns:
The number of columns in the result set if there were results

ResultSet getResultSet();
Get a ResultSet object corresponding to the result set of a previous execSQL().

This method gives access to the results of a SELECT or some other SQL statement that generated a result set via execSQL(). You should probably have used used execSQLResult() or execPreparedResult() in the first place for such cases.

A ResultSet buffers all the rows to the client.

Returns:
A ResultSet object for the relevant result set.

ResultSequence getResultSequence();
Get a ResultSequence object corresponding to the result set of a previous execSQL.

This method gives access to the results of a SELECT or some other SQL statement that generates a result set via execSQL(). You should probably have used used execResult() or execSequence() in the first place for such cases.

A ResultSequence does not buffer rows to the client - they must be fetched individually.

Returns:
A ResultSequence object for the relevant result set.

ResultSet execSQLResult();
Get a ResultSet by directly executing an SQL command that is expected to produce one.

This method is to be used for ad-hoc SELECTs and other queries that return a result set. The returned ResultSet can be used as a random access Range to iterate through the resulting rows and access column data. The entire result set is buffered to the client.

This method throws if there is no result set.

Returns:
A ResultSet object.

ResultSet execPreparedResult(ChunkingSpec[] csa = null);
Get a ResultSet by executing a prepared SQL command that is expected to produce one.

This method takes the statement data from a call to execPrepared, and if that has a result set, returns a ResultSet object that can be used as a random access Range to iterate through the resulting rows and access column data.

The entire result set is buffered to the client. This method throws if there is no result set.

Params:
ChunkingSpec[] csa an array indicating any columns that need to be transferred in chunks.

Returns:
A ResultSet object.

ResultSequence execSQLSequence();
Performs a query, and returns a ResultSequence object.

This method is to be used for ad-hoc SELECTs and other queries that return a result set. The returned ResultSequence can be used as an Input Range to iterate through the resulting rows one at a time. The result set is not buffered to the client.

Returns:
A ResultSequence object.

ResultSequence execPreparedSequence(ChunkingSpec[] csa = null);
Get a ResultSequence by executing a prepared SQL command that is expected to produce a result set.

This method takes the statement data from a call to execPrepared, and if that has a result set, returns a ResultSequence object that can be used as an Input Range to iterate through the resulting rows and access column data.

The result set is not buffered to the client.

Params:
ChunkingSpec[] csa an array indicating any columns that need to be transferred in chunks.

Returns:
A ResultSequence object.

bool execScalar(T)(ref T target);
Perform a query, and populate the value of a single column value into a D variable.

If the query does not produce a result set, or produces a result set that has more than one column then execScalar will throw. If it produces a result set with multiple rows, only the first row will be considered. If it is not possible to convert the column value to type T, then execScalar will throw.

The column value is automatically placed in the supplied variable. If it was NULL target will be unchanged.

This is effectively obsoleted by execTuple(), and will likely be removed.

Params:
T A variable type.
target An instance of that type, if it is a string type, the length should be set to what can be accepted.

Returns:
True if the result was a non-null value.

bool[] execTuple(T...)(ref T args);
Perform a query, and populate values for a single resulting row into a tuple of D variables.

If the query does not produce a result set, or produces one that has a number of columns that does not match the tuple, then execTuple will throw. If it produces a result set with multiple rows, only the first row will be considered.

If it is not possible to convert the column value to the type of the tuple element, then execTuple will throw.

OUT bindings are created automatically, and the results will appear in the variables of the tuple.

Params:
T A type tuple (normally this will be infered.)
args A list of variables. If any are strings or byte arrays, the length must be set to what can be accepted.

Returns:
An array of bool indicating the values that were not NULL.

bool execFunction(T, U...)(string name, ref T target, U args);
Execute a stored function, with any required input variables, and store the return value into a D variable.

For this method, no query string is to be provided. The required one is of the form "select foo(?, ? ...)". The method generates it and the appropriate bindings - in, and out. Chunked transfers are not supported in either direction. If you need them, create the parameters separately, then use execPreparedResult() to get a one-row, one-column result set.

If it is not possible to convert the column value to the type of target, then execFunction will throw. If the result is NULL, that is indicated by a false return value, and target is unchanged.

In the interest of performance, this method assumes that the user has the required information about the number and types of IN parameters and the type of the output variable. In the same interest, if the method is called repeatedly for the same stored function, prepare() is omitted after the first call.

Params:
T The type of the variable to receive the return result.
U type tuple of args
name The name of the stored function.
target the D variable to receive the stored function return result.
args The list of D variables to act as IN arguments to the stored function.

Returns:
True if the result was a non-null value.

void execProcedure(T...)(string name, ref T args);
Execute a stored procedure, with any required input variables.

For this method, no query string is to be provided. The required one is of the form "call proc(?, ? ...)". The method generates it and the appropriate in bindings. Chunked transfers are not supported. If you need them, create the parameters separately, then use execPrepared() or execPreparedResult().

In the interest of performance, this method assumes that the user has the required information about the number and types of IN parameters. In the same interest, if the method is called repeatedly for the same stored function, prepare() and other redundant operations are omitted after the first call.

OUT parameters are not currently supported. It should generally be possible with MySQL to present them as a result set.

Params:
T The type of the variable to receive the return result.
U type tuple of args
name The name of the stored function.
target the D variable to receive the stored function return result.
args The list of D variables to act as IN arguments to the stored function.

class FieldInfo;
A utility class to provide information about the columns of a result set.

This provides facilities required by ResultSet and ResultSequence, and a number of methods for relating structs and Variant arrays to columns.

void indexFields();
Create an index so you can refer to result set columns by name.

This will slow things down, so access to column values by name is optional. Use an integer index to access row data if you want the best performance.

void checkStruct(S)(ref S s);
Check a struct to see if it is compatible with a set of column metadata.

The struct must have field names corresponding one to one - order and name - with the column names and types in the result set. The only wiggle room is that integer types in the struct can be bigger than necessary - e.g. long for a column that is byte. However, signed/unsigned mismatches are not tolerated. If the same struct was used for the previous row the name and type checking is skipped.

Parameters:
s - a struct instance of some hopefully suitable type

uint index(string colName);
Get a column index from a column name

Indexing the column names will slow things down narinally, so access to column values by name is optional. Use an integer index to access row data if you want the best performance.

Params:
string colName string.

Returns:
uint inex of column

struct ChunkingSpec;
For result sets that are expected to contain columns with long data, it may be required to specify that the column result is fetched in chunks.

If only a chunk size is specified, the fetching will be chunked at that size, with the array length of the target increased incrementally as required. If a delegate is specified, then chunks of the specified size will be fed to that.

alias Row;
In all flavors of a result set, a row is an array of variants - well, actually MyVariants.

class ResultBase;
There is a good deal of common code required for result sets and result sequences, so it lives here in a base class.

void rowToStruct(S)(ref S s);
Populate a matching struct with the values from the current row.

The struct must have field names corresponding one to one - order and name - with the column names and types in the result set. The only wiggle room is that integer types in the struct can be bigger than necessary - e.g. long for a column that is byte. However, signed/unsigned mismatches are not tolerated. If the same struct was used for the previous row the name and type checking is skipped.

Parameters:
s - a struct instance of a suitable type

T getValue(T)(out T target, int index, out bool isnull);
Get a column value by index into a D variable from the current row

Params:
T The type of the target variable.
target An instance of that type.
index The column number within the result set starting at zero.
isnull An out variable that will be set to true if the column was NULL.

Returns:
The value populated.

T getValue(T)(out T target, string name, out bool isnull);
Get a column value by column name into a D variable from the current row

Params:
T The type of the target variable.
target An instance of that type.
name The column name.
isnull An out variable that will be set to true if the column was NULL.

Returns:
The value populated.

VariantN!(maxSize)[string] rowAsVAA();
Convert the current row into an associative array of MyVariant indexed by column name.

Returns:
MyVariant[string] array containing the row data.

string asString(uint col);
Get a column value as a string.

class ResultSet: mysqld.ResultBase;
An object to give convenient access to a complete result set.

After executing a query that produces a result set, you have two choices as to how to proceed. This facility covers the case when you choose to buffer the entire set of results to the client.

The result set in this case becomes a random-access Range of Rows - MyVariant[].

The Variant arrays are created lazily, but the result is not cached, so if you visit the rame row more than once there is some overhead in reconstituting the MyVariant[]. User should cache if required.

@property bool empty();
Make the ResultSet behave as a random access range - empty

@property ResultSet save();
Make the ResultSet behave as a random access range - save

I am currently not clear exactly how this should be done. Maybe Ranges that require save should also require restore? As it is, the ResultSet object returned from save only contains the array of uints that index into the actual result set rows. Maybe I should provide the restore() method?

@property Row front();
Make the ResultSet behave as a random access range - front

Gets the first row in whatever remains of the Range.

@property Row back();
Make the ResultSet behave as a random access range - back

Gets the last row in whatever remains of the Range.

void popFront();
Make the ResultSet behave as a random access range - popFront()

void popBack();
Make the ResultSet behave as a random access range - popBack

Row opIndex(size_t i);
Make the ResultSet behave as a random access range - opIndex

Gets the i'th row of whatever remains of the range

@property size_t length();
Make the ResultSet behave as a random access range - length

void close();
Explicitly clean up the MySQL resources and cancel pending results

class ResultSequence: mysqld.ResultBase;
An object to give convenient access to a result set one row at a time.

After doing a query that produces a result set, you have two choices as to how to proceed. This facility covers the case when you choose to deal with the rows sequentially.

The result set in this case becomes an Input Range of Rows - MyVariant[].

@property bool empty();
Make the ResultSequence behave as an Input Range - empty

@property Row front();
Make the ResultSequence behave as a random access range - front

Gets the current row

void popFront();
Make the ResultSequence behave as a random access range - popFront()

Progresses to the next row of the result set - that will then be 'front'

void close();
Explicitly clean up the MySQL resources and cancel pending results


Also in this Directory

  • errmsg.d Translated errmsg.h
  • mysql.d Translated mysql.h
  • mysqld.cbp Code::Blocks project file
  • mysqld.d mysqld source
  • mysqld.depend Code::Blocks project file
  • mysqld.layout Code::Blocks project file
  • mysqld.sql SQL for test tables.

  • Page mostly generated by Ddoc.