Skip to content

Commit 870b7e5

Browse files
committed
Add sqlsrv fix
1 parent e4ce6f9 commit 870b7e5

File tree

6 files changed

+55
-15
lines changed

6 files changed

+55
-15
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 & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@
3030
#include <vector>
3131

3232
#ifndef _WIN32
33-
#include <sys/utsname.h>
34-
#include <odbcinst.h>
35-
#else
33+
#ifdef PDO_SQLSRV
3634
extern "C" {
3735
#include "php_pdo_sqlsrv.h"
3836
}
3937
#include "php_pdo_sqlsrv_int.h"
38+
#elif SQLSRV
39+
extern "C" {
40+
#include "php_sqlsrv.h"
41+
}
42+
#include "php_sqlsrv_int.h"
43+
#endif
4044
#endif
4145

4246
// *** internal variables and constants ***
@@ -1158,7 +1162,17 @@ size_t core_str_zval_is_true(_Inout_ zval* value_z)
11581162
return 0; // false
11591163
}
11601164

1161-
void access_token_set_func::func( _In_ connection_option const* option, _In_ zval* value, _Inout_ sqlsrv_conn* conn, _Inout_ std::string& conn_str )
1165+
#ifdef _WIN32
1166+
ACCESSTOKEN** get_access_tokens() {
1167+
#ifdef PDO_SQLSRV
1168+
return PDO_SQLSRV_G(access_tokens);
1169+
#elif SQLSRV
1170+
return SQLSRV_G(access_tokens);
1171+
#endif
1172+
}
1173+
#endif
1174+
1175+
void access_token_set_func::func(_In_ connection_option const* option, _In_ zval* value, _Inout_ sqlsrv_conn* conn, _Inout_ std::string& conn_str)
11621176
{
11631177
SQLSRV_ASSERT(Z_TYPE_P(value) == IS_STRING, "An access token must be a byte string.");
11641178

@@ -1190,16 +1204,21 @@ void access_token_set_func::func( _In_ connection_option const* option, _In_ zva
11901204
#ifdef _WIN32
11911205
size_t next_token_position = 0;
11921206
bool same_token_used = false;
1207+
#ifdef PDO_SQLSRV
1208+
unsigned int& access_tokens_size = PDO_SQLSRV_G(access_tokens_size);
1209+
#elif SQLSRV
1210+
unsigned int& access_tokens_size = SQLSRV_G(access_tokens_size);
1211+
#endif
11931212

1194-
for (size_t current_token_index = 0; current_token_index < PDO_SQLSRV_G(access_tokens_size); current_token_index++) {
1213+
for (size_t current_token_index = 0; current_token_index < access_tokens_size; current_token_index++) {
11951214
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]);
1215+
for (size_t i = 0; i < get_access_tokens()[current_token_index]->dataSize; i += 2) {
1216+
string_token.push_back(get_access_tokens()[current_token_index]->data[i]);
11981217
}
11991218
if (string_token == std::string(value_str)) {
12001219
// 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]);
1220+
memset(get_access_tokens()[current_token_index]->data, 0, get_access_tokens()[current_token_index]->dataSize);
1221+
sqlsrv_free(get_access_tokens()[current_token_index]);
12031222
next_token_position = current_token_index;
12041223
same_token_used = true;
12051224
break;
@@ -1208,7 +1227,6 @@ void access_token_set_func::func( _In_ connection_option const* option, _In_ zva
12081227
#endif
12091228

12101229
size_t dataSize = 2 * value_len;
1211-
12121230
sqlsrv_malloc_auto_ptr<ACCESSTOKEN> accToken;
12131231
accToken = reinterpret_cast<ACCESSTOKEN*>(sqlsrv_malloc(sizeof(ACCESSTOKEN) + dataSize));
12141232

@@ -1230,10 +1248,14 @@ void access_token_set_func::func( _In_ connection_option const* option, _In_ zva
12301248
accToken.transferred();
12311249
#ifdef _WIN32
12321250
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)));
1251+
next_token_position = access_tokens_size;
1252+
access_tokens_size++;
1253+
#ifdef PDO_SQLSRV
1254+
PDO_SQLSRV_G(access_tokens) = reinterpret_cast<ACCESSTOKEN**>(sqlsrv_realloc(PDO_SQLSRV_G(access_tokens), access_tokens_size * sizeof(ACCESSTOKEN)));
1255+
#elif SQLSRV
1256+
SQLSRV_G(access_tokens) = reinterpret_cast<ACCESSTOKEN**>(sqlsrv_realloc(SQLSRV_G(access_tokens), access_tokens_size * sizeof(ACCESSTOKEN)));
1257+
#endif
12361258
}
1237-
PDO_SQLSRV_G(access_tokens)[next_token_position] = conn->azure_ad_access_token;
1259+
get_access_tokens()[next_token_position] = conn->azure_ad_access_token;
12381260
#endif
12391261
}

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)