Replaced vector with map for TVP constituent columns (#1281)
This commit is contained in:
parent
9f6ef12076
commit
277872619e
|
@ -1490,8 +1490,9 @@ struct sqlsrv_param_inout : public sqlsrv_param
|
||||||
// *** of this column in the corresponding table type.
|
// *** of this column in the corresponding table type.
|
||||||
struct sqlsrv_param_tvp : public sqlsrv_param
|
struct sqlsrv_param_tvp : public sqlsrv_param
|
||||||
{
|
{
|
||||||
|
std::map<SQLUSMALLINT, sqlsrv_param_tvp*> tvp_columns; // The constituent columns of the table-valued parameter
|
||||||
|
|
||||||
sqlsrv_param_tvp* parent_tvp; // For a TVP column to reference to the table-valued parameter. NULL if this is the TVP itself.
|
sqlsrv_param_tvp* parent_tvp; // For a TVP column to reference to the table-valued parameter. NULL if this is the TVP itself.
|
||||||
std::vector<sqlsrv_param_tvp*> tvp_columns; // The constituent columns of the table-valued parameter
|
|
||||||
int num_rows; // The total number of rows
|
int num_rows; // The total number of rows
|
||||||
int current_row; // A counter to keep track of which row is to be processed
|
int current_row; // A counter to keep track of which row is to be processed
|
||||||
|
|
||||||
|
|
|
@ -2075,9 +2075,11 @@ void sqlsrv_param::release_data()
|
||||||
{
|
{
|
||||||
if (Z_TYPE(placeholder_z) == IS_STRING) {
|
if (Z_TYPE(placeholder_z) == IS_STRING) {
|
||||||
zend_string_release(Z_STR(placeholder_z));
|
zend_string_release(Z_STR(placeholder_z));
|
||||||
ZVAL_UNDEF(&placeholder_z);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ZVAL_UNDEF(&placeholder_z);
|
||||||
|
|
||||||
|
buffer = NULL;
|
||||||
param_stream = NULL;
|
param_stream = NULL;
|
||||||
num_bytes_read = 0;
|
num_bytes_read = 0;
|
||||||
param_ptr_z = NULL;
|
param_ptr_z = NULL;
|
||||||
|
@ -3060,7 +3062,7 @@ void sqlsrv_param_tvp::get_tvp_metadata(_In_ sqlsrv_stmt* stmt, _In_ zend_string
|
||||||
param_ptr = new (sqlsrv_malloc(sizeof(sqlsrv_param_tvp))) sqlsrv_param_tvp(pos, column_encoding, data_type, col_size, dec_digits, this);
|
param_ptr = new (sqlsrv_malloc(sizeof(sqlsrv_param_tvp))) sqlsrv_param_tvp(pos, column_encoding, data_type, col_size, dec_digits, this);
|
||||||
param_ptr->num_rows = this->num_rows; // Each column inherits the number of rows from the TVP
|
param_ptr->num_rows = this->num_rows; // Each column inherits the number of rows from the TVP
|
||||||
|
|
||||||
tvp_columns.push_back(param_ptr);
|
tvp_columns[pos] = param_ptr.get();
|
||||||
param_ptr.transferred();
|
param_ptr.transferred();
|
||||||
|
|
||||||
pos++;
|
pos++;
|
||||||
|
@ -3075,11 +3077,16 @@ void sqlsrv_param_tvp::get_tvp_metadata(_In_ sqlsrv_stmt* stmt, _In_ zend_string
|
||||||
|
|
||||||
void sqlsrv_param_tvp::release_data()
|
void sqlsrv_param_tvp::release_data()
|
||||||
{
|
{
|
||||||
// Clean up tvp_columns as well
|
// Clean up tvp_columns
|
||||||
for (int i = 0; i < tvp_columns.size(); i++) {
|
std::map<SQLUSMALLINT, sqlsrv_param_tvp*>::iterator it;
|
||||||
tvp_columns[i]->release_data();
|
for (it = tvp_columns.begin(); it != tvp_columns.end(); ++it) {
|
||||||
sqlsrv_free(tvp_columns[i]);
|
sqlsrv_param_tvp* ptr = it->second;
|
||||||
|
if (ptr) {
|
||||||
|
ptr->release_data();
|
||||||
|
sqlsrv_free(ptr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
tvp_columns.clear();
|
||||||
|
|
||||||
sqlsrv_param::release_data();
|
sqlsrv_param::release_data();
|
||||||
}
|
}
|
||||||
|
@ -3315,7 +3322,6 @@ void sqlsrv_param_tvp::bind_param(_Inout_ sqlsrv_stmt* stmt)
|
||||||
core::SQLSetStmtAttr(stmt, SQL_SOPT_SS_PARAM_FOCUS, reinterpret_cast<SQLPOINTER>(ordinal), SQL_IS_INTEGER);
|
core::SQLSetStmtAttr(stmt, SQL_SOPT_SS_PARAM_FOCUS, reinterpret_cast<SQLPOINTER>(ordinal), SQL_IS_INTEGER);
|
||||||
|
|
||||||
// Bind the TVP columns
|
// Bind the TVP columns
|
||||||
SQLSRV_ENCODING stmt_encoding = (stmt->encoding() == SQLSRV_ENCODING_DEFAULT) ? stmt->conn->encoding() : stmt->encoding();
|
|
||||||
HashTable* rows_ht = Z_ARRVAL_P(param_ptr_z);
|
HashTable* rows_ht = Z_ARRVAL_P(param_ptr_z);
|
||||||
zval* row_z = zend_hash_index_find(rows_ht, 0);
|
zval* row_z = zend_hash_index_find(rows_ht, 0);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue