3333#include < sys/utsname.h>
3434#include < odbcinst.h>
3535#else
36+ #ifdef PDO_SQLSRV
3637extern " C" {
3738#include " php_pdo_sqlsrv.h"
3839}
3940#include " php_pdo_sqlsrv_int.h"
41+ #elif SQLSRV
42+ extern " C" {
43+ #include " php_sqlsrv.h"
44+ }
45+ #include " php_sqlsrv_int.h"
46+ #endif
4047#endif
4148
4249// *** internal variables and constants ***
@@ -1158,7 +1165,17 @@ size_t core_str_zval_is_true(_Inout_ zval* value_z)
11581165 return 0 ; // false
11591166}
11601167
1161- void access_token_set_func::func ( _In_ connection_option const * option, _In_ zval* value, _Inout_ sqlsrv_conn* conn, _Inout_ std::string& conn_str )
1168+ #ifdef _WIN32
1169+ ACCESSTOKEN** get_access_tokens () {
1170+ #ifdef PDO_SQLSRV
1171+ return PDO_SQLSRV_G (access_tokens);
1172+ #elif SQLSRV
1173+ return SQLSRV_G (access_tokens);
1174+ #endif
1175+ }
1176+ #endif
1177+
1178+ void access_token_set_func::func (_In_ connection_option const * option, _In_ zval* value, _Inout_ sqlsrv_conn* conn, _Inout_ std::string& conn_str)
11621179{
11631180 SQLSRV_ASSERT (Z_TYPE_P (value) == IS_STRING, " An access token must be a byte string." );
11641181
@@ -1190,16 +1207,21 @@ void access_token_set_func::func( _In_ connection_option const* option, _In_ zva
11901207#ifdef _WIN32
11911208 size_t next_token_position = 0 ;
11921209 bool same_token_used = false ;
1210+ #ifdef PDO_SQLSRV
1211+ unsigned int & access_tokens_size = PDO_SQLSRV_G (access_tokens_size);
1212+ #elif SQLSRV
1213+ unsigned int & access_tokens_size = SQLSRV_G (access_tokens_size);
1214+ #endif
11931215
1194- for (size_t current_token_index = 0 ; current_token_index < PDO_SQLSRV_G ( access_tokens_size) ; current_token_index++) {
1216+ for (size_t current_token_index = 0 ; current_token_index < access_tokens_size; current_token_index++) {
11951217 std::string string_token;
1196- for (size_t i = 0 ; i < PDO_SQLSRV_G (access_tokens )[current_token_index]->dataSize ; i += 2 ) {
1197- string_token.push_back (PDO_SQLSRV_G (access_tokens )[current_token_index]->data [i]);
1218+ for (size_t i = 0 ; i < get_access_tokens ( )[current_token_index]->dataSize ; i += 2 ) {
1219+ string_token.push_back (get_access_tokens ( )[current_token_index]->data [i]);
11981220 }
11991221 if (string_token == std::string (value_str)) {
12001222 // Token already exists in access_toiens
1201- memset (PDO_SQLSRV_G (access_tokens )[current_token_index]->data , 0 , PDO_SQLSRV_G (access_tokens )[current_token_index]->dataSize );
1202- sqlsrv_free (PDO_SQLSRV_G (access_tokens )[current_token_index]);
1223+ memset (get_access_tokens ( )[current_token_index]->data , 0 , get_access_tokens ( )[current_token_index]->dataSize );
1224+ sqlsrv_free (get_access_tokens ( )[current_token_index]);
12031225 next_token_position = current_token_index;
12041226 same_token_used = true ;
12051227 break ;
@@ -1208,7 +1230,6 @@ void access_token_set_func::func( _In_ connection_option const* option, _In_ zva
12081230#endif
12091231
12101232 size_t dataSize = 2 * value_len;
1211-
12121233 sqlsrv_malloc_auto_ptr<ACCESSTOKEN> accToken;
12131234 accToken = reinterpret_cast <ACCESSTOKEN*>(sqlsrv_malloc (sizeof (ACCESSTOKEN) + dataSize));
12141235
@@ -1230,10 +1251,14 @@ void access_token_set_func::func( _In_ connection_option const* option, _In_ zva
12301251 accToken.transferred ();
12311252#ifdef _WIN32
12321253 if (!same_token_used) {
1233- next_token_position = PDO_SQLSRV_G (access_tokens_size);
1234- PDO_SQLSRV_G (access_tokens_size)++;
1235- PDO_SQLSRV_G (access_tokens) = reinterpret_cast <ACCESSTOKEN**>(sqlsrv_realloc (PDO_SQLSRV_G (access_tokens), PDO_SQLSRV_G (access_tokens_size) * sizeof (ACCESSTOKEN)));
1254+ next_token_position = access_tokens_size;
1255+ access_tokens_size++;
1256+ #ifdef PDO_SQLSRV
1257+ PDO_SQLSRV_G (access_tokens) = reinterpret_cast <ACCESSTOKEN**>(sqlsrv_realloc (PDO_SQLSRV_G (access_tokens), access_tokens_size * sizeof (ACCESSTOKEN)));
1258+ #elif SQLSRV
1259+ SQLSRV_G (access_tokens) = reinterpret_cast <ACCESSTOKEN**>(sqlsrv_realloc (SQLSRV_G (access_tokens), access_tokens_size * sizeof (ACCESSTOKEN)));
1260+ #endif
12361261 }
1237- PDO_SQLSRV_G (access_tokens )[next_token_position] = conn->azure_ad_access_token ;
1262+ get_access_tokens ( )[next_token_position] = conn->azure_ad_access_token ;
12381263#endif
12391264}
0 commit comments