Function queryValue

Execute a one-off SQL SELECT command and returns a single value, the first column of the first row received.

std.typecons.Nullable!(std.variant.VariantN!(32L).VariantN) queryValue (
  Connection conn,
  string sql,
  ColumnSpecialization[] csa = null
);

If the query did not produce any rows, or the rows it produced have zero columns, this will return Nullable!Variant(), ie, null. Test for this with result.isNull.

If the query DID produce a result, but the value actually received is NULL, then result.isNull will be FALSE, and result.get will produce a Variant which CONTAINS null. Check for this with result.get.type == typeid(typeof(null)).

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

Use this method 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 Prepared.

If there are long data items among the expected result columns you can use the csa param to specify that they are to be subject to chunked transfer via a delegate.

Parameters

NameDescription
conn An open Connection to the database.
sql The SQL command to be run.
csa An optional array of ColumnSpecialization structs.

Returns

Nullable!Variant: This will be null (check via Nullable.isNull) if the query resulted in an empty result set.