From: Date: February 1 2008 6:03pm Subject: PHP mysqlnd svn commit: r1245 - trunk/tests/ext/pdo List-Archive: http://lists.mysql.com/commits/41575 Message-Id: <200802011703.m11H3Olb028777@bk-internal.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Author: uwendel Date: 2008-02-01 18:03:24 +0100 (Fri, 01 Feb 2008) New Revision: 1245 Added: trunk/tests/ext/pdo/pdo_stmt_bindcolumn.phpt Log: I'd appreciate it if PDO would complain about invalid offsets for bind columns, but I'm happy its not crashing... Added: trunk/tests/ext/pdo/pdo_stmt_bindcolumn.phpt =================================================================== --- trunk/tests/ext/pdo/pdo_stmt_bindcolumn.phpt (rev 0) +++ trunk/tests/ext/pdo/pdo_stmt_bindcolumn.phpt 2008-02-01 17:03:24 UTC (rev 1245) @@ -0,0 +1,133 @@ +--TEST-- +PDO Common: PDOStatement->bindColumn() +--SKIPIF-- + +--FILE-- +exec('CREATE TABLE test(id int NOT NULL PRIMARY KEY, val VARCHAR(10), grp VARCHAR(10))'); +$db->exec('INSERT INTO test VALUES(1, \'A\', \'Group1\')'); +$db->exec('INSERT INTO test VALUES(2, \'B\', \'Group2\')'); + +try { + + $stmt = $db->prepare('SELECT id FROM test ORDER BY id ASC'); + + if (false !== ($tmp = @$stmt->bindColumn())) + printf("[001] Expecting boolean false got %s\n", var_export($tmp, true)); + + if (false !== ($tmp = @$stmt->bindColumn(1))) + printf("[002] Expecting boolean false got %s\n", var_export($tmp, true)); + + if (false !== ($tmp = @$stmt->bindColumn(array()))) + printf("[003] Expecting boolean false got %s\n", var_export($tmp, true)); + + $stmt = $db->prepare('SELECT id FROM test ORDER BY id ASC'); + $stmt->execute(); + $out = 1; + + if (true !== ($tmp = $stmt->bindColumn(1, $out))) + printf("[004] Expecting boolean false got %s\n", var_export($tmp, true)); + + if (false !== ($tmp = @$stmt->bindColumn(0, $out))) + printf("[005] Expecting boolean false got %s\n", var_export($tmp, true)); + + // Invalid offset + if (false !== ($tmp = @$stmt->bindColumn(PHP_INT_MAX, $out))) + printf("[006] Expecting boolean false got %s\n", var_export($tmp, true)); + + // Invalid data type + $valid = array(PDO::PARAM_BOOL, PDO::PARAM_NULL, + PDO::PARAM_INT, PDO::PARAM_STR, PDO::PARAM_LOB); + do { + $invalid = mt_rand(-1 * PHP_INT_MAX + 1, PHP_INT_MAX); + } while (in_array($invalid, $valid)); + + if (false !== ($tmp = @$stmt->bindColumn(1, $out, $invalid))) + printf("[007] Expecting boolean false got %s\n", var_export($tmp, true)); + + // plain vanilla bind + $stmt = $db->prepare('SELECT id FROM test ORDER BY id ASC'); + $stmt->execute(); + $out1 = $out2 = null; + if (!$stmt->bindColumn(1, $out1)) + printf("[008] Cannot bind output column, %s %s\n", + var_export($stmt->errorCode(), true), var_export($stmt->errorInfo(), true)); + + while ($stmt->fetch(PDO::FETCH_BOUND)) + printf("id = %s (%s)\n", var_export($out1, true), gettype($out1)); + + // binding two variables to the same column + $stmt = $db->prepare('SELECT id FROM test ORDER BY id ASC'); + $stmt->execute(); + $out1 = $out2 = null; + if (!$stmt->bindColumn(1, $out1) || !$stmt->bindColumn(1, $out2)) + printf("[009] Cannot bind output column, %s %s\n", + var_export($stmt->errorCode(), true), var_export($stmt->errorInfo(), true)); + + while ($stmt->fetch(PDO::FETCH_BOUND)) + printf("id = %s (%s) / %s (%s)\n", + var_export($out1, true), gettype($out1), + var_export($out2, true), gettype($out2)); + + // binding two variables to the same column + $stmt = $db->prepare('SELECT id, val FROM test ORDER BY id ASC'); + $stmt->execute(); + $out1 = $out2 = null; + if (!$stmt->bindColumn(1, $out1) || !$stmt->bindColumn('id', $out2)) + printf("[010] Cannot bind output column, %s %s\n", + var_export($stmt->errorCode(), true), var_export($stmt->errorInfo(), true)); + + while ($stmt->fetch(PDO::FETCH_BOUND)) + printf("id = %s (%s) / %s (%s)\n", + var_export($out1, true), gettype($out1), + var_export($out2, true), gettype($out2)); + + // binding two variables to the same column + $stmt = $db->prepare('SELECT id, val FROM test ORDER BY id ASC'); + $stmt->execute(); + $out1 = $out2 = null; + if (!$stmt->bindColumn('id', $out1) || !$stmt->bindColumn('id', $out2)) + printf("[010] Cannot bind output column, %s %s\n", + var_export($stmt->errorCode(), true), var_export($stmt->errorInfo(), true)); + + while ($stmt->fetch(PDO::FETCH_BOUND)) + printf("id = %s (%s) / %s (%s)\n", + var_export($out1, true), gettype($out1), + var_export($out2, true), gettype($out2)); + +} catch (PDOException $e) { + // we should never get here, we use warnings, but never trust a system...s + printf("[001] %s, [%s} %s\n", + $e->getMessage(), $db->errorCode(), implode(' ', $db->errorInfo())); +} +print "done!"; +?> +--EXPECTF-- +id = '1' (string) +id = '2' (string) + +Error on wrong binding + +id = NULL (NULL) / '1' (string) +id = NULL (NULL) / '2' (string) + +Error on wrong binding + +id = NULL (NULL) / '1' (string) +id = NULL (NULL) / '2' (string) + +Error on wrong binding + +id = NULL (NULL) / '1' (string) +id = NULL (NULL) / '2' (string) +done! \ No newline at end of file