|
2 | 2 |
|
3 | 3 | Starting with version 3.1.0, mysql-native is transitioning to using a fully `@safe` API. This document describes how mysql-native is migrating, and how you can migrate your existing code to the new version.
|
4 | 4 |
|
5 |
| -First, note that the latest version of mysql, while it supports a safe API, is defaulted to supporting the original unsafe API. We highly recommend reading and following the recommendations in this document so you can start using the safe version and be prepared for future changes that will deprecate and remove the unsafe API. |
| 5 | +First, note that the latest version of mysql-native, while it supports a safe API, defaults to using the unsafe mechanisms. This is so the new version can be selected *without modifying* any existing code or imports. Even though the default is unsafe, many tools are provided to allow you to use both safe and unsafe APIs in the same project. I have tried to make every effort to make this transition as seamless as possible. For details, read on. |
| 6 | + |
| 7 | +## Table of contents |
| 8 | + |
| 9 | +* [Why safe?](#why-safe) |
| 10 | +* [Roadmap](#roadmap) |
| 11 | +* [The Major Changes](#the-major-changes) |
| 12 | + * [The safe/unsafe API](#the-safeunsafe-api) |
| 13 | + * [Importing both safe and unsafe](#importing-both-safe-and-unsafe) |
| 14 | + * [Migrating from Variant to MySQLVal](#migrating-from-variant-to-mysqlval) |
| 15 | + * [Row and ResultRange](#row-and-resultrange) |
| 16 | + * [Prepared](#prepared) |
| 17 | + * [Connection](#connection) |
| 18 | + * [MySQLPool](#mysqlpool) |
| 19 | + * [The commands module](#the-commands-module) |
| 20 | +* [Recommended Transition Method](#recommended-transition-method) |
| 21 | + |
6 | 22 |
|
7 | 23 | ## Why Safe?
|
8 | 24 |
|
@@ -34,18 +50,18 @@ In some cases, fixing memory safety in mysql-native was as simple as adding a `@
|
34 | 50 |
|
35 | 51 | But for the rest, to achieve full backwards compatibility, we have divided the API into two major sections -- safe and unsafe. The package `mysql.safe` will import all the safe versions of the API, the package `mysql.unsafe` will import the unsafe versions. If you import `mysql`, it will currently point at the unsafe version for backwards compatibility (see [Roadmap](#Roadmap) for details on how this will change).
|
36 | 52 |
|
37 |
| -The following modules have been split into mysql.safe.*modname* and mysql.unsafe.*modname*. Importing mysql.*modname* will currently import the unsafe version for backwards compatibility. |
38 |
| -* `mysql.commands` |
39 |
| -* `mysql.pool` |
40 |
| -* `mysql.result` |
41 |
| -* `mysql.prepared` |
42 |
| -* `mysql.connection` |
| 53 | +The following modules have been split into mysql.safe.*modname* and mysql.unsafe.*modname*. Importing mysql.*modname* will currently import the unsafe version for backwards compatibility. In a future major version, the default will be to import the safe api. |
| 54 | +* `mysql.[safe|unsafe].commands` |
| 55 | +* `mysql.[safe|unsafe].pool` |
| 56 | +* `mysql.[safe|unsafe].result` |
| 57 | +* `mysql.[safe|unsafe].prepared` |
| 58 | +* `mysql.[safe|unsafe].connection` |
43 | 59 |
|
44 |
| -Each of these modules in unsafe mode provides the same API as the previous version of mysql. The safe version provides aliases to the original type names for the safe versions of types, and also provides the same functions as before that can be called via safe code. The one exception is in `mysql.safe.commands`, where some functions were for the deprecated `BackwardCompatPrepared`, which will eventually be removed. |
| 60 | +Each of these modules in unsafe mode provides the same API as the previous version of mysql. The safe version provides aliases to the original type names for the safe versions of types, and also provides the same functions as before that can be called via safe code. The one exception is in `mysql.safe.commands`, where some functions were for the deprecated `BackwardCompatPrepared`, which will be removed in the next major revision. |
45 | 61 |
|
46 | 62 | If you are currently importing any of the above modules directly, or importing the `mysql` package, a first step to migration is to use the `mysql.safe` package. From there you will find that almost everything works exactly the same.
|
47 | 63 |
|
48 |
| -In addition to these two new packages, we have introduced a package called `mysql.impl`. This package contains the common implementations of the `safe` and `unsafe` modules, and should NOT be directly imported ever. These modules are documented simply because that is where the code lives. But in the version of mysql that removes the `unsafe` API, this package will be removed. You should always use the `unsafe` or `safe` packages instead, which generally publicly import the `impl` modules anyway. |
| 64 | +In addition to these two new packages, we have introduced a package called `mysql.impl` (for internal use). This package contains the common implementations of the `safe` and `unsafe` modules, and should NEVER be directly imported. These modules are documented simply because that is where the code lives. But in a future version of mysql, this package will be removed. You should always use the `unsafe` or `safe` packages instead of trying to import the `mysql.impl` package. |
49 | 65 |
|
50 | 66 | #### Importing both safe and unsafe
|
51 | 67 |
|
@@ -158,7 +174,7 @@ The `mysql.commands` module has been factored into 2 versions, a safe and unsafe
|
158 | 174 |
|
159 | 175 | Even in cases where you elect to defer updating code, you can still import the `safe` API, and use `unsafe` conversion functions to keep existing code working. In most cases, this will not be necessary as the API is kept as similar as possible.
|
160 | 176 |
|
161 |
| -## Rcommended Transition Method |
| 177 | +## Recommended Transition Method |
162 | 178 |
|
163 | 179 | We recommend following these steps to transition. In most cases, you should see very little breakage of code:
|
164 | 180 |
|
|
0 commit comments