Skip to content

Commit

Permalink
Cleaned up redundant code (#1260)
Browse files Browse the repository at this point in the history
  • Loading branch information
yitam authored May 18, 2021
1 parent 7313fa0 commit 5f2a14c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 60 deletions.
8 changes: 4 additions & 4 deletions source/pdo_sqlsrv/pdo_dbh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,7 +1049,7 @@ int pdo_sqlsrv_dbh_set_attr( _Inout_ pdo_dbh_t *dbh, _In_ zend_long attr, _Inout
break;

case SQLSRV_ATTR_DIRECT_QUERY:
driver_dbh->direct_query = ( zend_is_true( val ) ) ? true : false;
driver_dbh->direct_query = zend_is_true(val);
break;

case SQLSRV_ATTR_QUERY_TIMEOUT:
Expand All @@ -1069,15 +1069,15 @@ int pdo_sqlsrv_dbh_set_attr( _Inout_ pdo_dbh_t *dbh, _In_ zend_long attr, _Inout
break;

case SQLSRV_ATTR_FETCHES_NUMERIC_TYPE:
driver_dbh->fetch_numeric = (zend_is_true(val)) ? true : false;
driver_dbh->fetch_numeric = zend_is_true(val);
break;

case SQLSRV_ATTR_FETCHES_DATETIME_TYPE:
driver_dbh->fetch_datetime = (zend_is_true(val)) ? true : false;
driver_dbh->fetch_datetime = zend_is_true(val);
break;

case SQLSRV_ATTR_FORMAT_DECIMALS:
driver_dbh->format_decimals = (zend_is_true(val)) ? true : false;
driver_dbh->format_decimals = zend_is_true(val);
break;

case SQLSRV_ATTR_DECIMAL_PLACES:
Expand Down
14 changes: 7 additions & 7 deletions source/pdo_sqlsrv/pdo_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ void stmt_option_encoding:: operator()( _Inout_ sqlsrv_stmt* stmt, stmt_option c
void stmt_option_direct_query:: operator()( _Inout_ sqlsrv_stmt* stmt, stmt_option const* /*opt*/, _In_ zval* value_z )
{
pdo_sqlsrv_stmt *pdo_stmt = static_cast<pdo_sqlsrv_stmt*>( stmt );
pdo_stmt->direct_query = ( zend_is_true( value_z )) ? true : false;
pdo_stmt->direct_query = zend_is_true(value_z);
}

void stmt_option_cursor_scroll_type:: operator()( _Inout_ sqlsrv_stmt* stmt, stmt_option const* /*opt*/, _In_ zval* value_z )
Expand All @@ -332,13 +332,13 @@ void stmt_option_emulate_prepares:: operator()( _Inout_ sqlsrv_stmt* stmt, stmt_
void stmt_option_fetch_numeric:: operator()( _Inout_ sqlsrv_stmt* stmt, stmt_option const* /*opt*/, _In_ zval* value_z )
{
pdo_sqlsrv_stmt *pdo_stmt = static_cast<pdo_sqlsrv_stmt*>( stmt );
pdo_stmt->fetch_numeric = ( zend_is_true( value_z )) ? true : false;
pdo_stmt->fetch_numeric = zend_is_true(value_z);
}

void stmt_option_fetch_datetime:: operator()( _Inout_ sqlsrv_stmt* stmt, stmt_option const* /*opt*/, _In_ zval* value_z )
{
pdo_sqlsrv_stmt *pdo_stmt = static_cast<pdo_sqlsrv_stmt*>( stmt );
pdo_stmt->fetch_datetime = ( zend_is_true( value_z )) ? true : false;
pdo_stmt->fetch_datetime = zend_is_true(value_z);
}

// log a function entry point
Expand Down Expand Up @@ -880,23 +880,23 @@ int pdo_sqlsrv_stmt_set_attr( _Inout_ pdo_stmt_t *stmt, _In_ zend_long attr, _In
break;

case SQLSRV_ATTR_FETCHES_NUMERIC_TYPE:
driver_stmt->fetch_numeric = ( zend_is_true( val )) ? true : false;
driver_stmt->fetch_numeric = zend_is_true(val);
break;

case SQLSRV_ATTR_FETCHES_DATETIME_TYPE:
driver_stmt->fetch_datetime = ( zend_is_true( val )) ? true : false;
driver_stmt->fetch_datetime = zend_is_true(val);
break;

case SQLSRV_ATTR_FORMAT_DECIMALS:
driver_stmt->format_decimals = ( zend_is_true( val )) ? true : false;
driver_stmt->format_decimals = zend_is_true(val);
break;

case SQLSRV_ATTR_DECIMAL_PLACES:
core_sqlsrv_set_decimal_places(driver_stmt, val);
break;

case SQLSRV_ATTR_DATA_CLASSIFICATION:
driver_stmt->data_classification = (zend_is_true(val)) ? true : false;
driver_stmt->data_classification = zend_is_true(val);
break;

default:
Expand Down
21 changes: 3 additions & 18 deletions source/shared/core_stmt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1152,22 +1152,12 @@ void stmt_option_buffered_query_limit:: operator()( _Inout_ sqlsrv_stmt* stmt, s

void stmt_option_date_as_string:: operator()( _Inout_ sqlsrv_stmt* stmt, stmt_option const* /**/, _In_ zval* value_z )
{
if (zend_is_true(value_z)) {
stmt->date_as_string = true;
}
else {
stmt->date_as_string = false;
}
stmt->date_as_string = zend_is_true(value_z);
}

void stmt_option_format_decimals:: operator()( _Inout_ sqlsrv_stmt* stmt, stmt_option const* /**/, _In_ zval* value_z )
{
if (zend_is_true(value_z)) {
stmt->format_decimals = true;
}
else {
stmt->format_decimals = false;
}
stmt->format_decimals = zend_is_true(value_z);
}

void stmt_option_decimal_places:: operator()( _Inout_ sqlsrv_stmt* stmt, stmt_option const* /**/, _In_ zval* value_z )
Expand All @@ -1177,12 +1167,7 @@ void stmt_option_decimal_places:: operator()( _Inout_ sqlsrv_stmt* stmt, stmt_op

void stmt_option_data_classification:: operator()( _Inout_ sqlsrv_stmt* stmt, stmt_option const* /**/, _In_ zval* value_z )
{
if (zend_is_true(value_z)) {
stmt->data_classification = true;
}
else {
stmt->data_classification = false;
}
stmt->data_classification = zend_is_true(value_z);
}

// internal function to release the active stream. Called by each main API function
Expand Down
43 changes: 12 additions & 31 deletions source/sqlsrv/conn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ extern "C" {

namespace {

const int MAX_CONN_VALSTRING_LEN = 256;

// current subsytem. defined for the CHECK_SQL_{ERROR|WARNING} macros
unsigned int current_log_subsystem = LOG_CONN;

Expand All @@ -38,13 +40,7 @@ struct date_as_string_func {
static void func( connection_option const* /*option*/, _In_ zval* value, _Inout_ sqlsrv_conn* conn, std::string& /*conn_str*/ )
{
ss_sqlsrv_conn* ss_conn = static_cast<ss_sqlsrv_conn*>( conn );

if( zend_is_true( value )) {
ss_conn->date_as_string = true;
}
else {
ss_conn->date_as_string = false;
}
ss_conn->date_as_string = zend_is_true(value);
}
};

Expand All @@ -53,13 +49,7 @@ struct format_decimals_func
static void func(connection_option const* /*option*/, _In_ zval* value, _Inout_ sqlsrv_conn* conn, std::string& /*conn_str*/)
{
ss_sqlsrv_conn* ss_conn = static_cast<ss_sqlsrv_conn*>(conn);

if (zend_is_true(value)) {
ss_conn->format_decimals = true;
}
else {
ss_conn->format_decimals = false;
}
ss_conn->format_decimals = zend_is_true(value);
}
};

Expand Down Expand Up @@ -117,17 +107,10 @@ struct bool_conn_str_func {

static void func( _In_ connection_option const* option, _In_ zval* value, sqlsrv_conn* /*conn*/, _Out_ std::string& conn_str )
{
char const* val_str;
if( zend_is_true( value )) {
val_str = "yes";
}
else {
val_str = "no";
}
conn_str += option->odbc_name;
conn_str += "={";
conn_str += val_str;
conn_str += "};";
char temp_str[MAX_CONN_VALSTRING_LEN];

snprintf(temp_str, MAX_CONN_VALSTRING_LEN, "%s={%s};", option->odbc_name, (zend_is_true(value) ? "yes" : "no"));
conn_str += temp_str;
}
};

Expand All @@ -137,12 +120,10 @@ struct int_conn_str_func {
{
SQLSRV_ASSERT( Z_TYPE_P( value ) == IS_LONG, "An integer is expected for this keyword" )

std::string val_str = std::to_string( Z_LVAL_P( value ));

conn_str += option->odbc_name;
conn_str += "={";
conn_str += val_str;
conn_str += "};";
char temp_str[MAX_CONN_VALSTRING_LEN];

snprintf(temp_str, MAX_CONN_VALSTRING_LEN, "%s={%d};", option->odbc_name, Z_LVAL_P(value));
conn_str += temp_str;
}
};

Expand Down

0 comments on commit 5f2a14c

Please sign in to comment.