Skip to content

Commit 145a956

Browse files
committed
Add MySQLVal[] versions to all functions. Deprecate Variant[] versions.
Switch queryValue return type to MySQLVal instead of Variant.
1 parent cb9b55d commit 145a956

File tree

5 files changed

+121
-34
lines changed

5 files changed

+121
-34
lines changed

source/mysql/commands.d

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import mysql.protocol.constants;
2424
import mysql.protocol.extra_types;
2525
import mysql.protocol.packets;
2626
import mysql.result;
27+
import mysql.types;
2728

2829
/// This feature is not yet implemented. It currently has no effect.
2930
/+
@@ -205,12 +206,20 @@ ulong exec(T...)(Connection conn, const(char[]) sql, T args)
205206
return exec(conn, prepared);
206207
}
207208
///ditto
209+
deprecated("Variant support is deprecated. Use MySQLVal[] instead of Variant[]")
208210
ulong exec(Connection conn, const(char[]) sql, Variant[] args)
209211
{
210212
auto prepared = conn.prepare(sql);
211213
prepared.setArgs(args);
212214
return exec(conn, prepared);
213215
}
216+
///ditto
217+
ulong exec(Connection conn, const(char[]) sql, MySQLVal[] args)
218+
{
219+
auto prepared = conn.prepare(sql);
220+
prepared.setArgs(args);
221+
return exec(conn, prepared);
222+
}
214223

215224
///ditto
216225
ulong exec(Connection conn, ref Prepared prepared)
@@ -228,12 +237,20 @@ ulong exec(T...)(Connection conn, ref Prepared prepared, T args)
228237
return exec(conn, prepared);
229238
}
230239
///ditto
240+
deprecated("Variant support is deprecated. Use MySQLVal[] instead of Variant[]")
231241
ulong exec(Connection conn, ref Prepared prepared, Variant[] args)
232242
{
233243
prepared.setArgs(args);
234244
return exec(conn, prepared);
235245
}
236246

247+
///ditto
248+
ulong exec(Connection conn, ref Prepared prepared, MySQLVal[] args)
249+
{
250+
prepared.setArgs(args);
251+
return exec(conn, prepared);
252+
}
253+
237254
///ditto
238255
ulong exec(Connection conn, ref BackwardCompatPrepared prepared)
239256
{
@@ -331,13 +348,22 @@ ResultRange query(T...)(Connection conn, const(char[]) sql, T args)
331348
return query(conn, prepared);
332349
}
333350
///ditto
351+
deprecated("Variant support is deprecated. Use MySQLVal[] instead of Variant[]")
334352
ResultRange query(Connection conn, const(char[]) sql, Variant[] args)
335353
{
336354
auto prepared = conn.prepare(sql);
337355
prepared.setArgs(args);
338356
return query(conn, prepared);
339357
}
340358

359+
///ditto
360+
ResultRange query(Connection conn, const(char[]) sql, MySQLVal[] args)
361+
{
362+
auto prepared = conn.prepare(sql);
363+
prepared.setArgs(args);
364+
return query(conn, prepared);
365+
}
366+
341367
///ditto
342368
ResultRange query(Connection conn, ref Prepared prepared)
343369
{
@@ -354,11 +380,18 @@ ResultRange query(T...)(Connection conn, ref Prepared prepared, T args)
354380
return query(conn, prepared);
355381
}
356382
///ditto
383+
deprecated("Variant support is deprecated. Use MySQLVal[] instead of Variant[]")
357384
ResultRange query(Connection conn, ref Prepared prepared, Variant[] args)
358385
{
359386
prepared.setArgs(args);
360387
return query(conn, prepared);
361388
}
389+
///ditto
390+
ResultRange query(Connection conn, ref Prepared prepared, MySQLVal[] args)
391+
{
392+
prepared.setArgs(args);
393+
return query(conn, prepared);
394+
}
362395

363396
///ditto
364397
ResultRange query(Connection conn, ref BackwardCompatPrepared prepared)
@@ -461,6 +494,14 @@ Nullable!Row queryRow(T...)(Connection conn, const(char[]) sql, T args)
461494
return queryRow(conn, prepared);
462495
}
463496
///ditto
497+
Nullable!Row queryRow(Connection conn, const(char[]) sql, MySQLVal[] args)
498+
{
499+
auto prepared = conn.prepare(sql);
500+
prepared.setArgs(args);
501+
return queryRow(conn, prepared);
502+
}
503+
///ditto
504+
deprecated("Variant support is deprecated. Use MySQLVal[] instead of Variant[]")
464505
Nullable!Row queryRow(Connection conn, const(char[]) sql, Variant[] args)
465506
{
466507
auto prepared = conn.prepare(sql);
@@ -484,11 +525,18 @@ Nullable!Row queryRow(T...)(Connection conn, ref Prepared prepared, T args)
484525
return queryRow(conn, prepared);
485526
}
486527
///ditto
528+
deprecated("Variant support is deprecated. Use MySQLVal[] instead of Variant[]")
487529
Nullable!Row queryRow(Connection conn, ref Prepared prepared, Variant[] args)
488530
{
489531
prepared.setArgs(args);
490532
return queryRow(conn, prepared);
491533
}
534+
///ditto
535+
Nullable!Row queryRow(Connection conn, ref Prepared prepared, MySQLVal[] args)
536+
{
537+
prepared.setArgs(args);
538+
return queryRow(conn, prepared);
539+
}
492540

493541
///ditto
494542
Nullable!Row queryRow(Connection conn, ref BackwardCompatPrepared prepared)
@@ -672,50 +720,65 @@ delegate.
672720
csa = An optional array of `ColumnSpecialization` structs. If you need to
673721
use this with a prepared statement, please use `mysql.prepared.Prepared.columnSpecials`.
674722
+/
675-
Nullable!Variant queryValue(Connection conn, const(char[]) sql, ColumnSpecialization[] csa = null)
723+
Nullable!MySQLVal queryValue(Connection conn, const(char[]) sql, ColumnSpecialization[] csa = null)
676724
{
677725
return queryValueImpl(csa, conn, ExecQueryImplInfo(false, sql));
678726
}
679727
///ditto
680-
Nullable!Variant queryValue(T...)(Connection conn, const(char[]) sql, T args)
728+
Nullable!MySQLVal queryValue(T...)(Connection conn, const(char[]) sql, T args)
681729
if(T.length > 0 && !is(T[0] == Variant[]) && !is(T[0] == ColumnSpecialization) && !is(T[0] == ColumnSpecialization[]))
682730
{
683731
auto prepared = conn.prepare(sql);
684732
prepared.setArgs(args);
685733
return queryValue(conn, prepared);
686734
}
687735
///ditto
688-
Nullable!Variant queryValue(Connection conn, const(char[]) sql, Variant[] args)
736+
Nullable!MySQLVal queryValue(Connection conn, const(char[]) sql, MySQLVal[] args)
737+
{
738+
auto prepared = conn.prepare(sql);
739+
prepared.setArgs(args);
740+
return queryValue(conn, prepared);
741+
}
742+
///ditto
743+
deprecated("Variant support is deprecated. Use MySQLVal[] instead of Variant[]")
744+
Nullable!MySQLVal queryValue(Connection conn, const(char[]) sql, Variant[] args)
689745
{
690746
auto prepared = conn.prepare(sql);
691747
prepared.setArgs(args);
692748
return queryValue(conn, prepared);
693749
}
694750

695751
///ditto
696-
Nullable!Variant queryValue(Connection conn, ref Prepared prepared)
752+
Nullable!MySQLVal queryValue(Connection conn, ref Prepared prepared)
697753
{
698754
auto preparedInfo = conn.registerIfNeeded(prepared.sql);
699755
auto result = queryValueImpl(prepared.columnSpecials, conn, prepared.getExecQueryImplInfo(preparedInfo.statementId));
700756
prepared._lastInsertID = conn.lastInsertID; // Conceivably, this might be needed when multi-statements are enabled.
701757
return result;
702758
}
703759
///ditto
704-
Nullable!Variant queryValue(T...)(Connection conn, ref Prepared prepared, T args)
760+
Nullable!MySQLVal queryValue(T...)(Connection conn, ref Prepared prepared, T args)
705761
if(T.length > 0 && !is(T[0] == Variant[]) && !is(T[0] == ColumnSpecialization) && !is(T[0] == ColumnSpecialization[]))
706762
{
707763
prepared.setArgs(args);
708764
return queryValue(conn, prepared);
709765
}
710766
///ditto
711-
Nullable!Variant queryValue(Connection conn, ref Prepared prepared, Variant[] args)
767+
Nullable!MySQLVal queryValue(Connection conn, ref Prepared prepared, MySQLVal[] args)
768+
{
769+
prepared.setArgs(args);
770+
return queryValue(conn, prepared);
771+
}
772+
///ditto
773+
deprecated("Variant support is deprecated. Use MySQLVal[] instead of Variant[]")
774+
Nullable!MySQLVal queryValue(Connection conn, ref Prepared prepared, Variant[] args)
712775
{
713776
prepared.setArgs(args);
714777
return queryValue(conn, prepared);
715778
}
716779

717780
///ditto
718-
Nullable!Variant queryValue(Connection conn, ref BackwardCompatPrepared prepared)
781+
Nullable!MySQLVal queryValue(Connection conn, ref BackwardCompatPrepared prepared)
719782
{
720783
auto p = prepared.prepared;
721784
auto result = queryValue(conn, p);
@@ -724,21 +787,21 @@ Nullable!Variant queryValue(Connection conn, ref BackwardCompatPrepared prepared
724787
}
725788

726789
/// Common implementation for `queryValue` overloads.
727-
package Nullable!Variant queryValueImpl(ColumnSpecialization[] csa, Connection conn,
790+
package Nullable!MySQLVal queryValueImpl(ColumnSpecialization[] csa, Connection conn,
728791
ExecQueryImplInfo info)
729792
{
730793
auto results = queryImpl(csa, conn, info);
731794
if(results.empty)
732-
return Nullable!Variant();
795+
return Nullable!MySQLVal();
733796
else
734797
{
735-
auto row = results.front;
798+
auto row = results.safe.front;
736799
results.close();
737800

738801
if(row.length == 0)
739-
return Nullable!Variant();
802+
return Nullable!MySQLVal();
740803
else
741-
return Nullable!Variant(row[0]);
804+
return Nullable!MySQLVal(row[0]);
742805
}
743806
}
744807

source/mysql/connection.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import mysql.protocol.constants;
1717
import mysql.protocol.packets;
1818
import mysql.protocol.sockets;
1919
import mysql.result;
20+
import mysql.types;
2021
debug(MYSQLN_TESTS)
2122
{
2223
import mysql.test.common;
@@ -324,7 +325,7 @@ struct BackwardCompatPrepared
324325

325326
///ditto
326327
deprecated("Change 'preparedStmt.queryValue()' to 'conn.queryValue(preparedStmt)'")
327-
Nullable!Variant queryValue()
328+
Nullable!MySQLVal queryValue()
328329
{
329330
return .queryValue(_conn, _prepared);
330331
}

source/mysql/metadata.d

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/// Retrieve metadata from a DB.
1+
/// Retrieve metadata from a DB.
22
module mysql.metadata;
33

44
import std.array;
@@ -10,6 +10,7 @@ import mysql.commands;
1010
import mysql.exceptions;
1111
import mysql.protocol.sockets;
1212
import mysql.result;
13+
import mysql.types;
1314

1415
/// A struct to hold column metadata
1516
struct ColumnInfo
@@ -24,24 +25,24 @@ struct ColumnInfo
2425
size_t index;
2526
/++
2627
Is the COLUMN_DEFAULT column (in the information schema's COLUMNS table) NULL?
27-
28+
2829
What this means:
29-
30+
3031
On MariaDB 10.2.7 and up:
3132
- Does the column have a default value?
32-
33+
3334
On MySQL and MariaDB 10.2.6 and below:
3435
- This can be true if the column doesn't have a default value OR
3536
if NULL is the column's default value.
36-
37+
3738
See_also:
3839
See COLUMN_DEFAULT description at
3940
$(LINK https://mariadb.com/kb/en/library/information-schema-columns-table/)
4041
+/
4142
bool defaultNull;
4243
/++
4344
The default value as a string if not NULL.
44-
45+
4546
Depending on the database (see comments for `defaultNull` and the
4647
related "see also" link there), this may be either `null` or `"NULL"`
4748
if the column's default value is NULL.
@@ -100,7 +101,7 @@ information that is available to the connected user. This may well be quite limi
100101
struct MetaData
101102
{
102103
import mysql.connection;
103-
104+
104105
private:
105106
Connection _con;
106107

@@ -110,13 +111,13 @@ private:
110111
string query = procs ? "SHOW PROCEDURE STATUS WHERE db='": "SHOW FUNCTION STATUS WHERE db='";
111112
query ~= _con.currentDB ~ "'";
112113

113-
auto rs = _con.query(query).array;
114+
auto rs = _con.query(query).safe.array;
114115
MySQLProcedure[] pa;
115116
pa.length = rs.length;
116117
foreach (size_t i; 0..rs.length)
117118
{
118119
MySQLProcedure foo;
119-
Row r = rs[i];
120+
auto r = rs[i];
120121
foreach (int j; 0..11)
121122
{
122123
if (r.isNull(j))
@@ -174,16 +175,16 @@ public:
174175

175176
/++
176177
List the available databases
177-
178+
178179
Note that if you have connected using the credentials of a user with
179180
limited permissions you may not get many results.
180-
181+
181182
Returns:
182183
An array of strings
183184
+/
184185
string[] databases()
185186
{
186-
auto rs = _con.query("SHOW DATABASES").array;
187+
auto rs = _con.query("SHOW DATABASES").safe.array;
187188
string[] dbNames;
188189
dbNames.length = rs.length;
189190
foreach (size_t i; 0..rs.length)
@@ -193,13 +194,13 @@ public:
193194

194195
/++
195196
List the tables in the current database
196-
197+
197198
Returns:
198199
An array of strings
199200
+/
200201
string[] tables()
201202
{
202-
auto rs = _con.query("SHOW TABLES").array;
203+
auto rs = _con.query("SHOW TABLES").safe.array;
203204
string[] tblNames;
204205
tblNames.length = rs.length;
205206
foreach (size_t i; 0..rs.length)
@@ -209,7 +210,7 @@ public:
209210

210211
/++
211212
Get column metadata for a table in the current database
212-
213+
213214
Params:
214215
table = The table name
215216
Returns:
@@ -229,13 +230,13 @@ public:
229230
" COLUMN_KEY, EXTRA, PRIVILEGES, COLUMN_COMMENT" ~
230231
" FROM information_schema.COLUMNS WHERE" ~
231232
" table_schema='" ~ _con.currentDB ~ "' AND table_name='" ~ table ~ "'";
232-
auto rs = _con.query(query).array;
233+
auto rs = _con.query(query).safe.array;
233234
ColumnInfo[] ca;
234235
ca.length = rs.length;
235236
foreach (size_t i; 0..rs.length)
236237
{
237238
ColumnInfo col;
238-
Row r = rs[i];
239+
auto r = rs[i];
239240
for (int j = 1; j < 19; j++)
240241
{
241242
string t;

source/mysql/result.d

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,9 @@ struct ResultRange
342342
{
343343
SafeResultRange safe;
344344
alias safe this;
345-
deprecated("Usage of Variant is deprecated. Use SafeResultRange instead of ResultRange")
346-
inout(Row) front() inout { return inout(Row)(safe.front); }
345+
inout(Row) front() inout { return inout(Row)(safe.front); }
347346

348-
deprecated("Usage of Variant is deprecated. Use SafeResultRange instead of ResultRange")
347+
deprecated("Usage of Variant is deprecated. Use safe member to get a SafeResultRange")
349348
Variant[string] asAA()
350349
{
351350
ensureValid();

0 commit comments

Comments
 (0)