Skip to content

Commit 72dd098

Browse files
committed
Add sqlsrv fix
1 parent e4ce6f9 commit 72dd098

File tree

6 files changed

+55
-12
lines changed

6 files changed

+55
-12
lines changed

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ build_script:
101101
- copy %APPVEYOR_BUILD_FOLDER%\buildscripts\*.py c:\projects
102102
- cd c:\projects
103103
- python -V
104-
- ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
105104
- python builddrivers.py --PHPVER=%PHP_VERSION% --ARCH=%BUILD_PLATFORM% --THREAD=%THREAD% --SOURCE=%APPVEYOR_BUILD_FOLDER%\source --TESTING --NO_RENAME
106105
- cd c:\projects\php-sdk\phpdev\%PHP_VC%\%BUILD_PLATFORM%\php-%PHP_VERSION%-src\
107106
- set PHP_SRC_DIR=%CD%\ext

source/pdo_sqlsrv/config.w32

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ if( PHP_PDO_SQLSRV != "no" ) {
3333
CHECK_HEADER_ADD_INCLUDE("sqlext.h", "CFLAGS_PDO_SQLSRV_ODBC");
3434
ADD_SOURCES( configure_module_dirname + "\\shared", shared_src_class, "pdo_sqlsrv" );
3535
ADD_FLAG( "LDFLAGS_PDO_SQLSRV", "/NXCOMPAT /DYNAMICBASE /debug /guard:cf" );
36+
ADD_FLAG( "CFLAGS_PDO_SQLSRV", "/D PDO_SQLSRV" );
3637
ADD_FLAG( "CFLAGS_PDO_SQLSRV", "/EHsc" );
3738
ADD_FLAG( "CFLAGS_PDO_SQLSRV", "/GS" );
3839
ADD_FLAG( "CFLAGS_PDO_SQLSRV", "/Zi" );

source/shared/core_conn.cpp

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,17 @@
3333
#include <sys/utsname.h>
3434
#include <odbcinst.h>
3535
#else
36+
#ifdef PDO_SQLSRV
3637
extern "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
}

source/sqlsrv/config.w32

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ if( PHP_SQLSRV != "no" ) {
3232
}
3333
CHECK_HEADER_ADD_INCLUDE("sql.h", "CFLAGS_SQLSRV_ODBC");
3434
CHECK_HEADER_ADD_INCLUDE("sqlext.h", "CFLAGS_SQLSRV_ODBC");
35+
CHECK_HEADER_ADD_INCLUDE("php_sqlsrv_int.h", "CFLAGS_SQLSRV", configure_module_dirname);
36+
CHECK_HEADER_ADD_INCLUDE("php_sqlsrv.h", "CFLAGS_SQLSRV", configure_module_dirname);
3537
ADD_FLAG( "LDFLAGS_SQLSRV", "/NXCOMPAT /DYNAMICBASE /debug /guard:cf" );
38+
ADD_FLAG( "CFLAGS_PDO_SQLSRV", "/D SQLSRV" );
3639
ADD_FLAG( "CFLAGS_SQLSRV", "/D ZEND_WIN32_FORCE_INLINE" );
3740
ADD_FLAG( "CFLAGS_SQLSRV", "/EHsc" );
3841
ADD_FLAG( "CFLAGS_SQLSRV", "/GS" );

source/sqlsrv/init.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,15 @@ PHP_RSHUTDOWN_FUNCTION(sqlsrv)
696696
// SQLSRV_UNUSED( type );
697697

698698
LOG_FUNCTION( "PHP_RSHUTDOWN for php_sqlsrv" );
699+
#ifdef _WIN32
700+
for (size_t current_token = 0; current_token < SQLSRV_G(access_tokens_size); current_token++) {
701+
if (SQLSRV_G(access_tokens)[current_token]) {
702+
memset(SQLSRV_G(access_tokens)[current_token]->data, 0, SQLSRV_G(access_tokens)[current_token]->dataSize);
703+
sqlsrv_free(SQLSRV_G(access_tokens)[current_token]);
704+
}
705+
}
706+
sqlsrv_free(SQLSRV_G(access_tokens));
707+
#endif
699708
reset_errors();
700709

701710
// destruction

source/sqlsrv/php_sqlsrv.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
#include "php.h"
2626

27+
#ifdef _WIN32
28+
#include "msodbcsql.h"
29+
#endif
2730
//*********************************************************************************************************************************
2831
// Global variables
2932
//*********************************************************************************************************************************
@@ -44,6 +47,9 @@ zend_long buffered_query_limit;
4447

4548
#ifndef _WIN32
4649
zend_long set_locale_info;
50+
#else
51+
ACCESSTOKEN** access_tokens;
52+
unsigned int access_tokens_size = 0;
4753
#endif
4854

4955
ZEND_END_MODULE_GLOBALS(sqlsrv)

0 commit comments

Comments
 (0)