Skip to content

Commit 460d9aa

Browse files
authored
Removed wrappers for Zend APIs (#1161)
1 parent bba1f18 commit 460d9aa

File tree

10 files changed

+107
-287
lines changed

10 files changed

+107
-287
lines changed

source/pdo_sqlsrv/pdo_dbh.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,8 +1230,7 @@ int pdo_sqlsrv_dbh_get_attr( _Inout_ pdo_dbh_t *dbh, _In_ zend_long attr, _Inout
12301230
//Declarations below eliminate compiler warnings about string constant to char* conversions
12311231
const char* extver = "ExtensionVer";
12321232
std::string filever = VER_FILEVERSION_STR;
1233-
core::sqlsrv_add_assoc_string( *driver_dbh, return_value, extver, &filever[0], 1 /*duplicate*/
1234-
);
1233+
add_assoc_string(return_value, extver, &filever[0]);
12351234
break;
12361235
}
12371236

source/pdo_sqlsrv/pdo_init.cpp

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -279,22 +279,15 @@ namespace {
279279
zend_class_entry* zend_class = php_pdo_get_dbh_ce();
280280

281281
SQLSRV_ASSERT( zend_class != NULL, "REGISTER_PDO_SQLSRV_CLASS_CONST_LONG: php_pdo_get_dbh_ce failed");
282-
int zr = zend_declare_class_constant_long( zend_class, const_cast<char*>( name ), strlen( name ), value );
283-
if( zr == FAILURE ) {
284-
throw core::CoreException();
285-
}
282+
zend_declare_class_constant_long(zend_class, const_cast<char*>(name), strlen(name), value);
286283
}
287284

288285
void REGISTER_PDO_SQLSRV_CLASS_CONST_STRING( _In_z_ char const* name, _In_z_ char const* value )
289286
{
290287
zend_class_entry* zend_class = php_pdo_get_dbh_ce();
291288

292289
SQLSRV_ASSERT( zend_class != NULL, "REGISTER_PDO_SQLSRV_CLASS_CONST_STRING: php_pdo_get_dbh_ce failed");
293-
int zr = zend_declare_class_constant_string( zend_class, const_cast<char*>( name ), strlen( name ), const_cast<char*>( value ) );
294-
if( zr == FAILURE ) {
295-
296-
throw core::CoreException();
297-
}
290+
zend_declare_class_constant_string(zend_class, const_cast<char*>(name), strlen(name), const_cast<char*>(value));
298291
}
299292

300293
// array of pdo constants.

source/pdo_sqlsrv/pdo_stmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ int pdo_sqlsrv_stmt_get_col_meta( _Inout_ pdo_stmt_t *stmt, _In_ zend_long colno
10651065
}
10661066

10671067
// initialize the array to nothing, as PDO requires us to create it
1068-
core::sqlsrv_array_init( *driver_stmt, return_value );
1068+
array_init(return_value);
10691069

10701070
field_meta_data* core_meta_data;
10711071

@@ -1080,7 +1080,7 @@ int pdo_sqlsrv_stmt_get_col_meta( _Inout_ pdo_stmt_t *stmt, _In_ zend_long colno
10801080
// initialize the column data classification array
10811081
zval data_classification;
10821082
ZVAL_UNDEF(&data_classification);
1083-
core::sqlsrv_array_init(*driver_stmt, &data_classification );
1083+
array_init(&data_classification);
10841084

10851085
data_classification::fill_column_sensitivity_array(driver_stmt, (SQLSMALLINT)colno, &data_classification);
10861086

source/shared/core_conn.cpp

Lines changed: 20 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ void build_connection_string_and_set_conn_attr( _Inout_ sqlsrv_conn* conn, _Inou
7171
void* driver,_Inout_ std::string& connection_string );
7272
void determine_server_version( _Inout_ sqlsrv_conn* conn );
7373
const char* get_processor_arch( void );
74-
void get_server_version( _Inout_ sqlsrv_conn* conn, _Outptr_result_buffer_(len) char** server_version, _Out_ SQLSMALLINT& len );
7574
connection_option const* get_connection_option( sqlsrv_conn* conn, _In_ const char* key, _In_ SQLULEN key_len );
7675
void common_conn_str_append_func( _In_z_ const char* odbc_name, _In_reads_(val_len) const char* val, _Inout_ size_t val_len, _Inout_ std::string& conn_str );
7776
void load_azure_key_vault( _Inout_ sqlsrv_conn* conn );
@@ -590,19 +589,11 @@ void core_sqlsrv_prepare( _Inout_ sqlsrv_stmt* stmt, _In_reads_bytes_(sql_len) c
590589
void core_sqlsrv_get_server_version( _Inout_ sqlsrv_conn* conn, _Inout_ zval* server_version )
591590
{
592591
try {
593-
594-
sqlsrv_malloc_auto_ptr<char> buffer;
592+
char buffer[INFO_BUFFER_LEN] = "";
595593
SQLSMALLINT buffer_len = 0;
596-
597-
get_server_version( conn, &buffer, buffer_len );
598-
core::sqlsrv_zval_stringl( server_version, buffer, buffer_len );
599-
if ( buffer != 0 ) {
600-
sqlsrv_free( buffer );
601-
}
602-
buffer.transferred();
603-
}
604-
605-
catch( core::CoreException& ) {
594+
core::SQLGetInfo(conn, SQL_DBMS_VER, buffer, INFO_BUFFER_LEN, &buffer_len);
595+
core::sqlsrv_zval_stringl(server_version, buffer, buffer_len);
596+
} catch( core::CoreException& ) {
606597
throw;
607598
}
608599
}
@@ -617,33 +608,25 @@ void core_sqlsrv_get_server_version( _Inout_ sqlsrv_conn* conn, _Inout_ zval* se
617608
void core_sqlsrv_get_server_info( _Inout_ sqlsrv_conn* conn, _Out_ zval *server_info )
618609
{
619610
try {
620-
621-
sqlsrv_malloc_auto_ptr<char> buffer;
611+
char buffer[INFO_BUFFER_LEN] = "";
622612
SQLSMALLINT buffer_len = 0;
623613

624614
// Get the database name
625-
buffer = static_cast<char*>( sqlsrv_malloc( INFO_BUFFER_LEN ));
626-
core::SQLGetInfo( conn, SQL_DATABASE_NAME, buffer, INFO_BUFFER_LEN, &buffer_len );
615+
core::SQLGetInfo(conn, SQL_DATABASE_NAME, buffer, INFO_BUFFER_LEN, &buffer_len);
627616

628617
// initialize the array
629-
core::sqlsrv_array_init( *conn, server_info );
618+
array_init(server_info);
630619

631-
core::sqlsrv_add_assoc_string( *conn, server_info, "CurrentDatabase", buffer, 0 /*duplicate*/ );
632-
buffer.transferred();
620+
add_assoc_string(server_info, "CurrentDatabase", buffer);
633621

634622
// Get the server version
635-
get_server_version( conn, &buffer, buffer_len );
636-
core::sqlsrv_add_assoc_string( *conn, server_info, "SQLServerVersion", buffer, 0 /*duplicate*/ );
637-
buffer.transferred();
623+
core::SQLGetInfo(conn, SQL_DBMS_VER, buffer, INFO_BUFFER_LEN, &buffer_len);
624+
add_assoc_string(server_info, "SQLServerVersion", buffer);
638625

639626
// Get the server name
640-
buffer = static_cast<char*>( sqlsrv_malloc( INFO_BUFFER_LEN ));
641-
core::SQLGetInfo( conn, SQL_SERVER_NAME, buffer, INFO_BUFFER_LEN, &buffer_len );
642-
core::sqlsrv_add_assoc_string( *conn, server_info, "SQLServerName", buffer, 0 /*duplicate*/ );
643-
buffer.transferred();
644-
}
645-
646-
catch( core::CoreException& ) {
627+
core::SQLGetInfo(conn, SQL_SERVER_NAME, buffer, INFO_BUFFER_LEN, &buffer_len);
628+
add_assoc_string(server_info, "SQLServerName", buffer);
629+
} catch (core::CoreException&) {
647630
throw;
648631
}
649632
}
@@ -657,39 +640,29 @@ void core_sqlsrv_get_server_info( _Inout_ sqlsrv_conn* conn, _Out_ zval *server_
657640
void core_sqlsrv_get_client_info( _Inout_ sqlsrv_conn* conn, _Out_ zval *client_info )
658641
{
659642
try {
660-
661-
sqlsrv_malloc_auto_ptr<char> buffer;
643+
char buffer[INFO_BUFFER_LEN] = "";
662644
SQLSMALLINT buffer_len = 0;
663645

664646
// Get the ODBC driver's dll name
665-
buffer = static_cast<char*>( sqlsrv_malloc( INFO_BUFFER_LEN ));
666647
core::SQLGetInfo( conn, SQL_DRIVER_NAME, buffer, INFO_BUFFER_LEN, &buffer_len );
667648

668649
// initialize the array
669-
core::sqlsrv_array_init( *conn, client_info );
650+
array_init(client_info);
670651

671652
#ifndef _WIN32
672-
core::sqlsrv_add_assoc_string( *conn, client_info, "DriverName", buffer, 0 /*duplicate*/ );
653+
add_assoc_string(client_info, "DriverName", buffer);
673654
#else
674-
core::sqlsrv_add_assoc_string( *conn, client_info, "DriverDllName", buffer, 0 /*duplicate*/ );
655+
add_assoc_string(client_info, "DriverDllName", buffer);
675656
#endif // !_WIN32
676-
buffer.transferred();
677657

678658
// Get the ODBC driver's ODBC version
679-
buffer = static_cast<char*>( sqlsrv_malloc( INFO_BUFFER_LEN ));
680659
core::SQLGetInfo( conn, SQL_DRIVER_ODBC_VER, buffer, INFO_BUFFER_LEN, &buffer_len );
681-
core::sqlsrv_add_assoc_string( *conn, client_info, "DriverODBCVer", buffer, 0 /*duplicate*/ );
682-
buffer.transferred();
660+
add_assoc_string(client_info, "DriverODBCVer", buffer);
683661

684662
// Get the OBDC driver's version
685-
buffer = static_cast<char*>( sqlsrv_malloc( INFO_BUFFER_LEN ));
686663
core::SQLGetInfo( conn, SQL_DRIVER_VER, buffer, INFO_BUFFER_LEN, &buffer_len );
687-
core::sqlsrv_add_assoc_string( *conn, client_info, "DriverVer", buffer, 0 /*duplicate*/ );
688-
buffer.transferred();
689-
690-
}
691-
692-
catch( core::CoreException& ) {
664+
add_assoc_string(client_info, "DriverVer", buffer);
665+
} catch( core::CoreException& ) {
693666
throw;
694667
}
695668
}
@@ -918,30 +891,6 @@ void build_connection_string_and_set_conn_attr( _Inout_ sqlsrv_conn* conn, _Inou
918891
}
919892
}
920893

921-
922-
// get_server_version
923-
// Helper function which returns the version of the SQL Server we are connected to.
924-
925-
void get_server_version( _Inout_ sqlsrv_conn* conn, _Outptr_result_buffer_(len) char** server_version, _Out_ SQLSMALLINT& len )
926-
{
927-
try {
928-
929-
sqlsrv_malloc_auto_ptr<char> buffer;
930-
SQLSMALLINT buffer_len = 0;
931-
932-
buffer = static_cast<char*>( sqlsrv_malloc( INFO_BUFFER_LEN ));
933-
core::SQLGetInfo( conn, SQL_DBMS_VER, buffer, INFO_BUFFER_LEN, &buffer_len );
934-
*server_version = buffer;
935-
len = buffer_len;
936-
buffer.transferred();
937-
}
938-
939-
catch( core::CoreException& ) {
940-
throw;
941-
}
942-
}
943-
944-
945894
// get_processor_arch
946895
// Calls GetSystemInfo to verify the what architecture of the processor is supported
947896
// and return the string of the processor name.

source/shared/core_sqlsrv.h

Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -2498,77 +2498,6 @@ namespace core {
24982498
}
24992499
}
25002500

2501-
2502-
// exception thrown when a zend function wrapped here fails.
2503-
2504-
// wrappers for the zend functions called by our driver. These functions hook into the error reporting of our driver and throw
2505-
// exceptions when an error occurs. They are prefaced with sqlsrv_<zend_function_name> because many of the zend functions are
2506-
// actually macros that call other functions, so the sqlsrv_ is necessary to differentiate them from the macro system.
2507-
// If there is a zend function in the source that isn't found here, it is because it returns void and there is no error
2508-
// that can be thrown from it.
2509-
2510-
inline void sqlsrv_add_index_zval( _Inout_ sqlsrv_context& ctx, _Inout_ zval* array, _In_ zend_ulong index, _In_ zval* value)
2511-
{
2512-
int zr = add_index_zval( array, index, value );
2513-
CHECK_ZEND_ERROR( zr, ctx, SQLSRV_ERROR_ZEND_HASH ) {
2514-
throw CoreException();
2515-
}
2516-
}
2517-
2518-
inline void sqlsrv_add_next_index_zval( _Inout_ sqlsrv_context& ctx, _Inout_ zval* array, _In_ zval* value)
2519-
{
2520-
int zr = add_next_index_zval( array, value );
2521-
CHECK_ZEND_ERROR( zr, ctx, SQLSRV_ERROR_ZEND_HASH ) {
2522-
throw CoreException();
2523-
}
2524-
}
2525-
2526-
inline void sqlsrv_add_assoc_null( _Inout_ sqlsrv_context& ctx, _Inout_ zval* array_z, _In_ const char* key )
2527-
{
2528-
int zr = ::add_assoc_null( array_z, key );
2529-
CHECK_ZEND_ERROR (zr, ctx, SQLSRV_ERROR_ZEND_HASH ) {
2530-
throw CoreException();
2531-
}
2532-
}
2533-
2534-
inline void sqlsrv_add_assoc_long( _Inout_ sqlsrv_context& ctx, _Inout_ zval* array_z, _In_ const char* key, _In_ zend_long val )
2535-
{
2536-
int zr = ::add_assoc_long( array_z, key, val );
2537-
CHECK_ZEND_ERROR (zr, ctx, SQLSRV_ERROR_ZEND_HASH ) {
2538-
throw CoreException();
2539-
}
2540-
}
2541-
2542-
inline void sqlsrv_add_assoc_string( _Inout_ sqlsrv_context& ctx, _Inout_ zval* array_z, _In_ const char* key, _Inout_z_ char* val, _In_ bool duplicate )
2543-
{
2544-
int zr = ::add_assoc_string(array_z, key, val);
2545-
CHECK_ZEND_ERROR (zr, ctx, SQLSRV_ERROR_ZEND_HASH ) {
2546-
throw CoreException();
2547-
}
2548-
if (duplicate == 0) {
2549-
sqlsrv_free(val);
2550-
}
2551-
}
2552-
2553-
inline void sqlsrv_add_assoc_zval( _Inout_ sqlsrv_context& ctx, _Inout_ zval* array_z, _In_ const char* key, _In_ zval* val )
2554-
{
2555-
int zr = ::add_assoc_zval(array_z, key, val);
2556-
CHECK_ZEND_ERROR (zr, ctx, SQLSRV_ERROR_ZEND_HASH ) {
2557-
throw CoreException();
2558-
}
2559-
}
2560-
2561-
inline void sqlsrv_array_init( _Inout_ sqlsrv_context& ctx, _Out_ zval* new_array)
2562-
{
2563-
#if PHP_VERSION_ID < 70300
2564-
CHECK_ZEND_ERROR(::array_init(new_array), ctx, SQLSRV_ERROR_ZEND_HASH) {
2565-
throw CoreException();
2566-
}
2567-
#else
2568-
array_init(new_array);
2569-
#endif
2570-
}
2571-
25722501
inline void sqlsrv_php_stream_from_zval_no_verify( _Inout_ sqlsrv_context& ctx, _Outref_result_maybenull_ php_stream*& stream, _In_opt_ zval* stream_z )
25732502
{
25742503
// this duplicates the macro php_stream_from_zval_no_verify, which we can't use because it has an assignment

source/shared/core_stmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ sqlsrv_stmt::sqlsrv_stmt( _In_ sqlsrv_conn* c, _In_ SQLHANDLE handle, _In_ error
159159
{
160160
ZVAL_UNDEF( &active_stream );
161161
// initialize the input string parameters array (which holds zvals)
162-
core::sqlsrv_array_init( *conn, &param_input_strings );
162+
array_init(&param_input_strings);
163163

164164
// initialize the (input only) stream parameters (which holds sqlsrv_stream structures)
165165
ZVAL_NEW_ARR( &param_streams );
@@ -574,7 +574,7 @@ void core_sqlsrv_bind_param( _Inout_ sqlsrv_stmt* stmt, _In_ SQLUSMALLINT param_
574574
}
575575
buffer = Z_STRVAL_P( &wbuffer_z );
576576
buffer_len = Z_STRLEN_P( &wbuffer_z );
577-
core::sqlsrv_add_index_zval( *stmt, &( stmt->param_input_strings ), param_num, &wbuffer_z );
577+
add_index_zval(&(stmt->param_input_strings), param_num, &wbuffer_z);
578578
}
579579
ind_ptr = buffer_len;
580580
if( direction != SQL_PARAM_INPUT ){

source/shared/core_util.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -617,27 +617,27 @@ namespace data_classification {
617617

618618
zval data_classification;
619619
ZVAL_UNDEF(&data_classification);
620-
core::sqlsrv_array_init(*stmt, &data_classification );
620+
array_init(&data_classification);
621621

622622
USHORT num_pairs = meta->columns_sensitivity[colno].num_pairs;
623623

624624
if (num_pairs == 0) {
625-
core::sqlsrv_add_assoc_zval(*stmt, return_array, DATA_CLASS, &data_classification);
625+
add_assoc_zval(return_array, DATA_CLASS, &data_classification);
626626

627627
return 0;
628628
}
629629

630630
zval sensitivity_properties;
631631
ZVAL_UNDEF(&sensitivity_properties);
632-
core::sqlsrv_array_init(*stmt, &sensitivity_properties);
632+
array_init(&sensitivity_properties);
633633

634634
for (USHORT j = 0; j < num_pairs; j++) {
635635
zval label_array, infotype_array;
636636
ZVAL_UNDEF(&label_array);
637637
ZVAL_UNDEF(&infotype_array);
638638

639-
core::sqlsrv_array_init(*stmt, &label_array);
640-
core::sqlsrv_array_init(*stmt, &infotype_array);
639+
array_init(&label_array);
640+
array_init(&infotype_array);
641641

642642
USHORT labelidx = meta->columns_sensitivity[colno].label_info_pairs[j].label_idx;
643643
USHORT typeidx = meta->columns_sensitivity[colno].label_info_pairs[j].infotype_idx;
@@ -647,22 +647,22 @@ namespace data_classification {
647647
char *infotype = meta->infotypes[typeidx]->name;
648648
char *infotype_id = meta->infotypes[typeidx]->id;
649649

650-
core::sqlsrv_add_assoc_string(*stmt, &label_array, NAME, label, 1);
651-
core::sqlsrv_add_assoc_string(*stmt, &label_array, ID, label_id, 1);
650+
add_assoc_string(&label_array, NAME, label);
651+
add_assoc_string(&label_array, ID, label_id);
652652

653-
core::sqlsrv_add_assoc_zval(*stmt, &sensitivity_properties, LABEL, &label_array);
653+
add_assoc_zval(&sensitivity_properties, LABEL, &label_array);
654654

655-
core::sqlsrv_add_assoc_string(*stmt, &infotype_array, NAME, infotype, 1);
656-
core::sqlsrv_add_assoc_string(*stmt, &infotype_array, ID, infotype_id, 1);
655+
add_assoc_string(&infotype_array, NAME, infotype);
656+
add_assoc_string(&infotype_array, ID, infotype_id);
657657

658-
core::sqlsrv_add_assoc_zval(*stmt, &sensitivity_properties, INFOTYPE, &infotype_array);
658+
add_assoc_zval(&sensitivity_properties, INFOTYPE, &infotype_array);
659659

660660
// add the pair of sensitivity properties to data_classification
661-
core::sqlsrv_add_next_index_zval(*stmt, &data_classification, &sensitivity_properties );
661+
add_next_index_zval(&data_classification, &sensitivity_properties);
662662
}
663663

664664
// add data classfication as associative array
665-
core::sqlsrv_add_assoc_zval(*stmt, return_array, DATA_CLASS, &data_classification);
665+
add_assoc_zval(return_array, DATA_CLASS, &data_classification);
666666

667667
return num_pairs;
668668
}

0 commit comments

Comments
 (0)