Skip to content

Commit 8614fc8

Browse files
authored
Merge pull request #243 from kubo39/remove-deprecated-BackwardCompatPrepared
Remove deprecated BackwardCompatPrepared
2 parents f9d03e2 + 8a86fc7 commit 8614fc8

File tree

4 files changed

+2
-217
lines changed

4 files changed

+2
-217
lines changed

integration-tests/source/mysql/maintests.d

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -172,25 +172,16 @@ unittest
172172
assert(prepared.getArg(0) == 6);
173173
assert(prepared.getArg(1) == "ff");
174174

175-
// exec: bcPrepared sql
176-
auto bcPrepared = cn.prepareBackwardCompatImpl(prepareSQL);
177-
static assert(doSafe || is(typeof(bcPrepared) == BackwardCompatPrepared));
178-
bcPrepared.setArgs(7, "gg");
179-
assert(cn.exec(bcPrepared) == 1);
180-
assert(bcPrepared.getArg(0) == 7);
181-
assert(bcPrepared.getArg(1) == "gg");
182-
183175
// Check results
184176
auto rows = cn.query("SELECT * FROM `execOverloads`").array();
185-
assert(rows.length == 7);
177+
assert(rows.length == 6);
186178

187179
assert(rows[0].length == 2);
188180
assert(rows[1].length == 2);
189181
assert(rows[2].length == 2);
190182
assert(rows[3].length == 2);
191183
assert(rows[4].length == 2);
192184
assert(rows[5].length == 2);
193-
assert(rows[6].length == 2);
194185

195186
assert(rows[0][0] == 1);
196187
assert(rows[0][1] == "aa");
@@ -204,8 +195,6 @@ unittest
204195
assert(rows[4][1] == "ee");
205196
assert(rows[5][0] == 6);
206197
assert(rows[5][1] == "ff");
207-
assert(rows[6][0] == 7);
208-
assert(rows[6][1] == "gg");
209198
}
210199
test!false();
211200
() @safe { test!true(); } ();
@@ -276,16 +265,6 @@ unittest
276265
assert(rows[0].length == 2);
277266
assert(rows[0][0] == 3);
278267
assert(rows[0][1] == "cc");
279-
280-
// BCPrepared sql
281-
auto bcPrepared = cn.prepareBackwardCompatImpl(prepareSQL);
282-
static assert(doSafe || is(typeof(bcPrepared) == BackwardCompatPrepared));
283-
bcPrepared.setArgs(1, "aa");
284-
rows = cn.query(bcPrepared).array;
285-
assert(rows.length == 1);
286-
assert(rows[0].length == 2);
287-
assert(rows[0][0] == 1);
288-
assert(rows[0][1] == "aa");
289268
}
290269

291270
// Test queryRow
@@ -328,15 +307,6 @@ unittest
328307
assert(row.length == 2);
329308
assert(row[0] == 3);
330309
assert(row[1] == "cc");
331-
332-
// BCPrepared sql
333-
auto bcPrepared = cn.prepareBackwardCompatImpl(prepareSQL);
334-
static assert(doSafe || is(typeof(bcPrepared) == BackwardCompatPrepared));
335-
bcPrepared.setArgs(1, "aa");
336-
row = cn.queryRow(bcPrepared).get;
337-
assert(row.length == 2);
338-
assert(row[0] == 1);
339-
assert(row[1] == "aa");
340310
}
341311

342312
// Test queryRowTuple
@@ -355,14 +325,6 @@ unittest
355325
cn.queryRowTuple(prepared, i, s);
356326
assert(i == 2);
357327
assert(s == "bb");
358-
359-
// BCPrepared sql
360-
auto bcPrepared = cn.prepareBackwardCompatImpl(prepareSQL);
361-
static assert(doSafe || is(typeof(bcPrepared) == BackwardCompatPrepared));
362-
bcPrepared.setArgs(3, "cc");
363-
cn.queryRowTuple(bcPrepared, i, s);
364-
assert(i == 3);
365-
assert(s == "cc");
366328
}
367329

368330
// Test queryValue
@@ -396,14 +358,6 @@ unittest
396358
value = cn.queryValue(prepared, [MYVAL(3), MYVAL("cc")]).get;
397359
assert(!value.valIsNull);
398360
assert(value == 3);
399-
400-
// BCPrepared sql
401-
auto bcPrepared = cn.prepareBackwardCompatImpl(prepareSQL);
402-
static assert(doSafe || is(typeof(bcPrepared) == BackwardCompatPrepared));
403-
bcPrepared.setArgs(1, "aa");
404-
value = cn.queryValue(bcPrepared).get;
405-
assert(!value.valIsNull);
406-
assert(value == 1);
407361
}
408362
}
409363
test!false();

source/mysql/connection.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ version moved to this location.
88
99
$(SAFE_MIGRATION)
1010
+/
11-
module mysql.connection;
1211

12+
module mysql.connection;
1313
public import mysql.unsafe.connection;

source/mysql/unsafe/commands.d

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,6 @@ ulong exec(Connection conn, ref Prepared prepared, Variant[] args) @system
9191
return exec(conn, prepared);
9292
}
9393

94-
///ditto
95-
ulong exec(Connection conn, ref BackwardCompatPrepared prepared) @system
96-
{
97-
auto p = prepared.prepared;
98-
auto result = exec(conn, p);
99-
prepared._prepared = p;
100-
return result;
101-
}
102-
10394
///ditto
10495
ulong exec(Connection conn, ref Prepared prepared) @system
10596
{
@@ -224,15 +215,6 @@ UnsafeResultRange query(Connection conn, ref Prepared prepared, Variant[] args)
224215
return query(conn, prepared);
225216
}
226217

227-
///ditto
228-
UnsafeResultRange query(Connection conn, ref BackwardCompatPrepared prepared) @system
229-
{
230-
auto p = prepared.prepared;
231-
auto result = query(conn, p);
232-
prepared._prepared = p;
233-
return result;
234-
}
235-
236218
/++
237219
Execute an SQL SELECT command or prepared statement where you only want the
238220
first `mysql.result.UnsafeRow`, if any.
@@ -335,15 +317,6 @@ Nullable!UnsafeRow queryRow(Connection conn, ref Prepared prepared, Variant[] ar
335317
return queryRow(conn, prepared);
336318
}
337319

338-
///ditto
339-
Nullable!UnsafeRow queryRow(Connection conn, ref BackwardCompatPrepared prepared) @system
340-
{
341-
auto p = prepared.prepared;
342-
auto result = queryRow(conn, p);
343-
prepared._prepared = p;
344-
return result;
345-
}
346-
347320
/++
348321
Execute an SQL SELECT command or prepared statement where you only want the
349322
first `mysql.result.UnsafeRow`, and place result values into a set of D variables.
@@ -383,14 +356,6 @@ void queryRowTuple(T...)(Connection conn, ref Prepared prepared, ref T args)
383356
prepared.safe._lastInsertID = conn.lastInsertID; // Conceivably, this might be needed when multi-statements are enabled.
384357
}
385358

386-
///ditto
387-
void queryRowTuple(T...)(Connection conn, ref BackwardCompatPrepared prepared, ref T args) @system
388-
{
389-
auto p = prepared.prepared;
390-
queryRowTuple(conn, p, args);
391-
prepared._prepared = p;
392-
}
393-
394359

395360
/++
396361
Execute an SQL SELECT command or prepared statement and return a single value:
@@ -501,11 +466,3 @@ Nullable!Variant queryValue(Connection conn, ref Prepared prepared, Variant[] ar
501466
prepared.setArgs(args);
502467
return queryValue(conn, prepared);
503468
}
504-
///ditto
505-
Nullable!Variant queryValue(Connection conn, ref BackwardCompatPrepared prepared) @system
506-
{
507-
auto p = prepared.prepared;
508-
auto result = queryValue(conn, p);
509-
prepared._prepared = p;
510-
return result;
511-
}

source/mysql/unsafe/connection.d

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -44,129 +44,3 @@ UnsafePrepared prepareProcedure(Connection conn, string name, int numArgs) @safe
4444
{
4545
return CS.prepareProcedure(conn, name, numArgs).unsafe;
4646
}
47-
48-
/++
49-
This function is provided ONLY as a temporary aid in upgrading to mysql-native v2.0.0.
50-
51-
See `BackwardCompatPrepared` for more info.
52-
+/
53-
deprecated("This is provided ONLY as a temporary aid in upgrading to mysql-native v2.0.0. You should migrate from this to the Prepared-compatible exec/query overloads in 'mysql.commands'.")
54-
BackwardCompatPrepared prepareBackwardCompat(Connection conn, const(char[]) sql)
55-
{
56-
return prepareBackwardCompatImpl(conn, sql);
57-
}
58-
59-
/// Allow mysql-native tests to get around the deprecation message
60-
package(mysql) BackwardCompatPrepared prepareBackwardCompatImpl(Connection conn, const(char[]) sql)
61-
{
62-
return BackwardCompatPrepared(conn, prepare(conn, sql));
63-
}
64-
65-
/++
66-
This is a wrapper over `mysql.unsafe.prepared.Prepared`, provided ONLY as a
67-
temporary aid in upgrading to mysql-native v2.0.0 and its
68-
new connection-independent model of prepared statements. See the
69-
$(LINK2 https://github.com/mysql-d/mysql-native/blob/master/MIGRATING_TO_V2.md, migration guide)
70-
for more info.
71-
72-
In most cases, this layer shouldn't even be needed. But if you have many
73-
lines of code making calls to exec/query the same prepared statement,
74-
then this may be helpful.
75-
76-
To use this temporary compatability layer, change instances of:
77-
78-
---
79-
auto stmt = conn.prepare(...);
80-
---
81-
82-
to this:
83-
84-
---
85-
auto stmt = conn.prepareBackwardCompat(...);
86-
---
87-
88-
And then your prepared statement should work as before.
89-
90-
BUT DO NOT LEAVE IT LIKE THIS! Ultimately, you should update
91-
your prepared statement code to the mysql-native v2.0.0 API, by changing
92-
instances of:
93-
94-
---
95-
stmt.exec()
96-
stmt.query()
97-
stmt.queryRow()
98-
stmt.queryRowTuple(outputArgs...)
99-
stmt.queryValue()
100-
---
101-
102-
to this:
103-
104-
---
105-
conn.exec(stmt)
106-
conn.query(stmt)
107-
conn.queryRow(stmt)
108-
conn.queryRowTuple(stmt, outputArgs...)
109-
conn.queryValue(stmt)
110-
---
111-
112-
Both of the above syntaxes can be used with a `BackwardCompatPrepared`
113-
(the `Connection` passed directly to `mysql.commands.exec`/`mysql.commands.query`
114-
will override the one embedded associated with your `BackwardCompatPrepared`).
115-
116-
Once all of your code is updated, you can change `prepareBackwardCompat`
117-
back to `prepare` again, and your upgrade will be complete.
118-
+/
119-
struct BackwardCompatPrepared
120-
{
121-
import std.variant;
122-
import mysql.unsafe.result;
123-
import std.typecons;
124-
125-
private Connection _conn;
126-
Prepared _prepared;
127-
128-
/// Access underlying `Prepared`
129-
@property Prepared prepared() @safe { return _prepared; }
130-
131-
alias _prepared this;
132-
133-
/++
134-
This function is provided ONLY as a temporary aid in upgrading to mysql-native v2.0.0.
135-
136-
See `BackwardCompatPrepared` for more info.
137-
+/
138-
deprecated("Change 'preparedStmt.exec()' to 'conn.exec(preparedStmt)'")
139-
ulong exec() @system
140-
{
141-
return .exec(_conn, _prepared);
142-
}
143-
144-
///ditto
145-
deprecated("Change 'preparedStmt.query()' to 'conn.query(preparedStmt)'")
146-
ResultRange query() @system
147-
{
148-
return .query(_conn, _prepared);
149-
}
150-
151-
///ditto
152-
deprecated("Change 'preparedStmt.queryRow()' to 'conn.queryRow(preparedStmt)'")
153-
Nullable!Row queryRow() @system
154-
{
155-
return .queryRow(_conn, _prepared);
156-
}
157-
158-
///ditto
159-
deprecated("Change 'preparedStmt.queryRowTuple(outArgs...)' to 'conn.queryRowTuple(preparedStmt, outArgs...)'")
160-
void queryRowTuple(T...)(ref T args) if(T.length == 0 || !is(T[0] : Connection))
161-
{
162-
return .queryRowTuple(_conn, _prepared, args);
163-
}
164-
165-
///ditto
166-
deprecated("Change 'preparedStmt.queryValue()' to 'conn.queryValue(preparedStmt)'")
167-
Nullable!Variant queryValue() @system
168-
{
169-
return .queryValue(_conn, _prepared);
170-
}
171-
}
172-

0 commit comments

Comments
 (0)