forked from microsoft/mssql-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunix_utils.h
More file actions
39 lines (30 loc) · 1.36 KB
/
unix_utils.h
File metadata and controls
39 lines (30 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
// This header defines utility functions for safely handling SQLWCHAR-based
// wide-character data in ODBC operations on macOS. It includes conversions
// between SQLWCHAR, std::wstring, and UTF-8 strings to bridge encoding
// differences specific to macOS.
#pragma once
#include <string>
#include <vector>
#include <locale>
#include <codecvt>
#include <sql.h>
#include <sqlext.h>
#include <pybind11/pybind11.h>
namespace py = pybind11;
#if defined(__APPLE__) || defined(__linux__)
// Constants for character encoding
extern const char* kOdbcEncoding; // ODBC uses UTF-16LE for SQLWCHAR
extern const size_t kUcsLength; // SQLWCHAR is 2 bytes on all platforms
// Function to convert SQLWCHAR strings to std::wstring on macOS
// Removed default argument to avoid redefinition conflict
std::wstring SQLWCHARToWString(const SQLWCHAR* sqlwStr, size_t length);
// Function to convert std::wstring to SQLWCHAR array on macOS
std::vector<SQLWCHAR> WStringToSQLWCHAR(const std::wstring& str);
// This function can be used as a safe decoder for SQLWCHAR buffers
std::string SQLWCHARToUTF8String(const SQLWCHAR* buffer);
// Helper function to fix FetchBatchData for macOS
// This will process WCHAR data safely in SQLWCHARToUTF8String
void SafeProcessWCharData(SQLWCHAR* buffer, SQLLEN indicator, py::list& row);
#endif