Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to GitHub issues 574 and 580 #592

Merged
merged 3 commits into from
Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/shared/core_results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace {

// *** internal constants ***

const int INITIAL_FIELD_STRING_LEN = 1024; // base allocation size when retrieving a string field
const int INITIAL_FIELD_STRING_LEN = 8000; // base allocation size when retrieving a string field
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it, changing this value for non-AE may cause a breaking change. Say a user is trying to fetch a string that is 5000 bytes long. Before this change, the user needs to call sqlsrv_next_result + sqlsrv_get_field many times to retrieve the complete string. With this change however, the user only needs to call sqlsrv_get_field once the retrieve the entire string. This seems like a good thing. But if the user has multiple sqlsrv_next_result + sqlsrv_get_field in their code, error will be thrown telling the user there's no more result left. Therefore, I think it's best to only change the buffer size for if column encryption is enabled. It's impossible to change the constant here though, you may have to go through the code, check where INITIAL_FIELD_STRING_LEN is used and change it there.


// *** internal functions ***

Expand Down
34 changes: 25 additions & 9 deletions test/functional/pdo_sqlsrv/pdo_574_next_rowset.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ try {
createTable($conn, $tableName1, $columns);

// insert one row to each table
$phrase = str_repeat('This is a test ', 250);
$phrase = str_repeat('This is a test ', 25000);
$stmt = insertRow($conn, $tableName, array('col1' => $phrase));
unset($stmt);

$phrase = str_repeat('This is indeed very long ', 300);
$stmt = insertRow($conn, $tableName1, array('col1' => $phrase));
$phrase1 = str_repeat('This is indeed very long ', 30000);
$stmt = insertRow($conn, $tableName1, array('col1' => $phrase1));
unset($stmt);

// run queries in a batch
Expand All @@ -39,7 +39,11 @@ try {
// fetch from $tableName
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
echo(substr($row[0], 0, 15)) . PHP_EOL;
if ($row[0] === $phrase) {
echo(substr($row[0], 0, 15)) . PHP_EOL;
} else {
echo "Incorrect value substr($row[0], 0, 1000)...!" . PHP_EOL;
}
}

// fetch from cd_info
Expand All @@ -49,7 +53,7 @@ try {

$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
echo(substr($row[0], 0, 15)) . PHP_EOL;
echo $row[0] . PHP_EOL;
}

// fetch from $tableName1
Expand All @@ -59,7 +63,11 @@ try {

$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
echo(substr($row[0], 0, 25)) . PHP_EOL;
if ($row[0] === $phrase1) {
echo(substr($row[0], 0, 25)) . PHP_EOL;
} else {
echo "Incorrect value substr($row[0], 0, 1000)...!" . PHP_EOL;
}
}

// should be no more next results, first returns false second throws an exception
Expand Down Expand Up @@ -90,7 +98,7 @@ try {
// fetch from cd_info
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
echo(substr($row[0], 0, 15)) . PHP_EOL;
echo $row[0] . PHP_EOL;
}

// re-execute the statement, should return to the first query in the batch
Expand All @@ -99,7 +107,11 @@ try {
// fetch from $tableName1
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
echo(substr($row[0], 0, 25)) . PHP_EOL;
if ($row[0] === $phrase1) {
echo(substr($row[0], 0, 25)) . PHP_EOL;
} else {
echo "Incorrect value substr($row[0], 0, 1000)...!" . PHP_EOL;
}
}
unset($stmt);

Expand All @@ -109,7 +121,11 @@ try {
// fetch from $tableName
$row = $stmt->fetch(PDO::FETCH_NUM);
if ($row) {
echo(substr($row[0], 0, 15)) . PHP_EOL;
if ($row[0] === $phrase) {
echo(substr($row[0], 0, 15)) . PHP_EOL;
} else {
echo "Incorrect value substr($row[0], 0, 1000)...!" . PHP_EOL;
}
}

// should be no more next results, first returns false second throws an exception
Expand Down
34 changes: 25 additions & 9 deletions test/functional/sqlsrv/sqlsrv_574_next_result.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ if (!$stmt) {

// insert one row to each table
$sql = "insert into $tableName (col1) VALUES (?)";
$phrase = str_repeat('This is a test ', 250);
$phrase = str_repeat('This is a test ', 25000);

$stmt = sqlsrv_prepare($conn, $sql, array($phrase));
if ($stmt) {
Expand All @@ -40,9 +40,9 @@ if ($stmt) {
}
}

$phrase = str_repeat('This is indeed very long ', 300);
$phrase1 = str_repeat('This is indeed very long ', 30000);
$sql = "insert into $tableName1 (col1) VALUES (?)";
$stmt = sqlsrv_prepare($conn, $sql, array($phrase));
$stmt = sqlsrv_prepare($conn, $sql, array($phrase1));
if ($stmt) {
$r = sqlsrv_execute($stmt);
if (!$r) {
Expand All @@ -63,7 +63,11 @@ if ($stmt) {
$row = sqlsrv_fetch($stmt);
if ($row) {
$fld = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
echo(substr($fld, 0, 15)) . PHP_EOL;
if ($fld === $phrase) {
echo(substr($fld, 0, 15)) . PHP_EOL;
} else {
echo "Incorrect value substr($fld, 0, 1000)...!" . PHP_EOL;
}
}

// fetch from cd_info
Expand All @@ -74,7 +78,7 @@ var_dump($next);
$row = sqlsrv_fetch($stmt);
if ($row) {
$fld = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
echo(substr($fld, 0, 15)) . PHP_EOL;
echo $fld . PHP_EOL;
}

// fetch from $tableName1
Expand All @@ -85,7 +89,11 @@ var_dump($next);
$row = sqlsrv_fetch($stmt);
if ($row) {
$fld = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
echo(substr($fld, 0, 25)) . PHP_EOL;
if ($fld === $phrase1) {
echo(substr($fld, 0, 25)) . PHP_EOL;
} else {
echo "Incorrect value substr($fld, 0, 1000)...!" . PHP_EOL;
}
}

// should be no more next results, first returns NULL second returns false
Expand Down Expand Up @@ -119,7 +127,7 @@ sqlsrv_next_result($stmt);
$row = sqlsrv_fetch($stmt);
if ($row) {
$fld = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
echo(substr($fld, 0, 15)) . PHP_EOL;
echo $fld . PHP_EOL;
}

// re-execute the statement, should return to the first query in the batch
Expand All @@ -132,7 +140,11 @@ if (!$r) {
$row = sqlsrv_fetch($stmt);
if ($row) {
$fld = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
echo(substr($fld, 0, 25)) . PHP_EOL;
if ($fld === $phrase1) {
echo(substr($fld, 0, 25)) . PHP_EOL;
} else {
echo "Incorrect value substr($fld, 0, 1000)...!" . PHP_EOL;
}
}
sqlsrv_free_stmt($stmt);

Expand All @@ -149,7 +161,11 @@ if ($stmt) {
$row = sqlsrv_fetch($stmt);
if ($row) {
$fld = sqlsrv_get_field($stmt, 0, SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR));
echo(substr($fld, 0, 15)) . PHP_EOL;
if ($fld === $phrase) {
echo(substr($fld, 0, 15)) . PHP_EOL;
} else {
echo "Incorrect value substr($fld, 0, 1000)...!" . PHP_EOL;
}
}

// should be no more next results, first returns NULL second returns false
Expand Down