query

Execute an SQL SELECT command or prepared statement.

This returns an input range of mysql.result.Row, so if you need random access to the mysql.result.Row elements, simply call std.array.array() on the result.

If the SQL command does not produce a result set (such as INSERT/CREATE/etc), then mysql.exceptions.MYXNoResultRecieved will be thrown. Use exec instead for such commands.

If args is supplied, the sql string will automatically be used as a prepared statement. Prepared statements are automatically cached by mysql-native, so there's no performance penalty for using this multiple times for the same statement instead of manually preparing a statement.

If args and prepared are both provided, args will be used, and any arguments that are already set in the prepared statement will automatically be replaced with args (note, just like calling mysql.prepared.Prepared.setArgs, this will also remove all mysql.prepared.ParameterSpecialization that may have been applied).

Only use the string sql overload that doesn't take args when you are not going to be using the same command repeatedly and you are CERTAIN all the data you're sending is properly escaped. Otherwise, consider using overload that takes a Prepared.

If you need to use any mysql.prepared.ParameterSpecialization, use mysql.connection.prepare to manually create a mysql.prepared.Prepared, and set your parameter specializations using mysql.prepared.Prepared.setArg or mysql.prepared.Prepared.setArgs.

More...

Parameters

conn Connection

An open mysql.connection.Connection to the database.

prepared Prepared

The prepared statement to be run.

Return Value

A (possibly empty) mysql.result.ResultRange.

Detailed Description

Type Mappings

$(TYPE_MAPPINGS)

Examples

ResultRange oneAtATime = myConnection.query("SELECT * from `myTable`");
Row[]       allAtOnce  = myConnection.query("SELECT * from `myTable`").array;

auto myInt = 7;
ResultRange rows = myConnection.query("SELECT * FROM `myTable` WHERE `a` = ?", myInt);

Meta