Raised the initial buffer size and modified tests as per review

This commit is contained in:
Jenny Tam 2017-11-10 15:04:07 -08:00
parent 52b612ece8
commit d633691b5b
3 changed files with 51 additions and 19 deletions

View file

@ -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
// *** internal functions ***

View file

@ -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
@ -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
@ -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
@ -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
@ -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
@ -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);
@ -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

View file

@ -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) {
@ -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) {
@ -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
@ -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
@ -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
@ -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
@ -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);
@ -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