@@ -273,6 +273,52 @@ while (SQL_SUCCEEDED(SQLFetch(hstmt)))
273273}
274274```
275275
276+ #### Money/SmallMoney encryption
277+
278+ Starting with driver version 17.7 it is possible to use Always Encrypted
279+ with MONEY and SMALLMONEY. However there are some additional steps to take.
280+ When inserting into encrypted MONEY or SMALLMONEY columns, use one of the following C types:
281+ ```
282+ SQL_C_CHAR
283+ SQL_C_WCHAR
284+ SQL_C_SHORT
285+ SQL_C_LONG
286+ SQL_C_FLOAT
287+ SQL_C_DOUBLE
288+ SQL_C_BIT
289+ SQL_C_TINYINT
290+ SQL_C_SBIGINT
291+ SQL_C_NUMERIC
292+ ```
293+
294+ and a SQL type of either ` SQL_NUMERIC ` or ` SQL_DOUBLE ` (precision may be lost when using this type).
295+
296+ ##### Binding the variable
297+
298+ Whenever binding a MONEY/SMALLMONEY variable in an encrypted column the following
299+ descriptor field(s) must be set:
300+
301+ ```
302+ // n is the descriptor record of the MONEY/SMALLMONEY parameter
303+ // the type is assumed to be SMALLMONEY if isSmallMoney is true and MONEY otherwise
304+
305+ SQLHANDLE ipd = 0;
306+ SQLGetStmtAttr(hStmt, SQL_ATTR_IMP_PARAM_DESC, (SQLPOINTER)&ipd, SQL_IS_POINTER, NULL);
307+ SQLSetDescField(ipd, n, SQL_CA_SS_SERVER_TYPE, isSmallMoney ? (SQLPOINTER)SQL_SS_TYPE_SMALLMONEY :
308+ (SQLPOINTER)SQL_SS_TYPE_MONEY, SQL_IS_INTEGER);
309+
310+
311+ // If the variable is bound as SQL_NUMERIC, additional descriptor fields have to be set
312+ // var is SQL_NUMERIC_STRUCT containing the value to be inserted
313+
314+ SQLHDESC hdesc = NULL;
315+ SQLGetStmtAttr(hStmt, SQL_ATTR_APP_PARAM_DESC, &hdesc, 0, NULL);
316+ SQLSetDescField(hdesc, n, SQL_DESC_PRECISION, (SQLPOINTER)(var.precision), 0);
317+ SQLSetDescField(hdesc, n, SQL_DESC_SCALE, (SQLPOINTER)(var.scale), 0);
318+ SQLSetDescField(hdesc, n, SQL_DESC_DATA_PTR, &var, 0);
319+ ```
320+
321+
276322#### Avoiding Common Problems when Querying Encrypted Columns
277323
278324This section describes common categories of errors when querying encrypted columns from ODBC applications and a few guidelines on how to avoid them.
0 commit comments