Function queryValue
Execute an SQL SELECT command or prepared statement and return a single value: the first column of the first row received.
std .typecons .Nullable!(taggedalgebraic.taggedalgebraic.TaggedAlgebraic!(mysql.types._MYTYPE).TaggedAlgebraic) queryValue
(
Connection conn,
const(char[]) sql,
ColumnSpecialization[] csa = null
) @safe;
Nullable!MySQLVal queryValue(T...)
(
Connection conn,
const(char[]) sql,
T args
)
if (T .length > 0 && !is(T[0] == Variant[]) && !is(T[0] == MySQLVal[]) && !is(T[0] == ColumnSpecialization) && !is(T[0] == ColumnSpecialization[]));
std .typecons .Nullable!(taggedalgebraic.taggedalgebraic.TaggedAlgebraic!(mysql.types._MYTYPE).TaggedAlgebraic) queryValue
(
Connection conn,
const(char[]) sql,
taggedalgebraic .taggedalgebraic .TaggedAlgebraic!(mysql.types._MYTYPE)[] args
) @safe;
std .typecons .Nullable!(taggedalgebraic.taggedalgebraic.TaggedAlgebraic!(mysql.types._MYTYPE).TaggedAlgebraic) queryValue
(
Connection conn,
ref SafePrepared prepared
) @safe;
Nullable!MySQLVal queryValue(T...)
(
Connection conn,
ref Prepared prepared,
T args
)
if (T .length > 0 && !is(T[0] == Variant[]) && !is(T[0] == MySQLVal[]) && !is(T[0] == ColumnSpecialization) && !is(T[0] == ColumnSpecialization[]));
std .typecons .Nullable!(taggedalgebraic.taggedalgebraic.TaggedAlgebraic!(mysql.types._MYTYPE).TaggedAlgebraic) queryValue
(
Connection conn,
ref SafePrepared prepared,
taggedalgebraic .taggedalgebraic .TaggedAlgebraic!(mysql.types._MYTYPE)[] args
) @safe;
If the query did not produce any rows, or the rows it produced have zero columns,
this will return Nullable!MySQLVal()
, ie, null. Test for this with
result
.
If the query DID produce a result, but the value actually received is NULL,
then result
will be FALSE, and result
will produce a MySQLVal
which CONTAINS null. Check for this with result
or result
.
If the SQL command does not produce a result set (such as INSERT/CREATE/etc),
then 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
SafePrepared
, this will also remove all
SafeParameterSpecialization
that may have been applied).
Only use the const(char[]) 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 SafeParameterSpecialization
, use
prepare
to manually create a SafePrepared
,
and set your parameter specializations using SafePrepared
or SafePrepared
.
Type Mappings
See the MySQL/D Type Mappings tables
Parameters
Name | Description |
---|---|
conn | An open Connection to the database. |
sql | The SQL command to be run. |
prepared | The prepared statement to be run. |
csa | Not yet implemented. |
Returns
Nullable!MySQLVal
: This will be null (check via Nullable
) if the
query resulted in an empty result set.
Example
auto myInt = 7;
Nullable!MySQLVal value = myConnection .queryRow("SELECT * FROM `myTable` WHERE `a` = ?", myInt);