improve test portability.

improve infrastructure for LOB support.
This commit is contained in:
Wez Furlong 2005-10-31 02:07:38 +00:00
parent 138ad7d252
commit 40c24a65c4
5 changed files with 58 additions and 19 deletions

View File

@ -474,8 +474,16 @@ static inline void fetch_value(pdo_stmt_t *stmt, zval *dest, int colno, int *typ
if (value == NULL) {
ZVAL_NULL(dest);
} else if (value_len == 0) {
php_stream_to_zval((php_stream*)value, dest);
} else {
if (stmt->dbh->stringify) {
char *buf = NULL;
size_t len;
len = php_stream_copy_to_mem((php_stream*)value, &buf, PHP_STREAM_COPY_ALL, 0);
ZVAL_STRINGL(dest, buf, len, 0);
php_stream_close((php_stream*)value);
} else {
php_stream_to_zval((php_stream*)value, dest);
}
} else if (!stmt->dbh->stringify) {
/* they gave us a string, but LOBs are represented as streams in PDO */
php_stream *stm;
#ifdef TEMP_STREAM_TAKE_BUFFER
@ -2075,13 +2083,23 @@ static void free_statement(pdo_stmt_t *stmt TSRMLS_DC)
efree(stmt);
}
void pdo_dbstmt_free_storage(pdo_stmt_t *stmt TSRMLS_DC)
PDO_API void php_pdo_stmt_addref(pdo_stmt_t *stmt TSRMLS_DC)
{
stmt->refcount++;
}
PDO_API void php_pdo_stmt_delref(pdo_stmt_t *stmt TSRMLS_DC)
{
if (--stmt->refcount == 0) {
free_statement(stmt TSRMLS_CC);
}
}
void pdo_dbstmt_free_storage(pdo_stmt_t *stmt TSRMLS_DC)
{
php_pdo_stmt_delref(stmt TSRMLS_CC);
}
zend_object_value pdo_dbstmt_new(zend_class_entry *ce TSRMLS_DC)
{
zend_object_value retval;

View File

@ -44,7 +44,7 @@ PDO_API char *php_pdo_int64_to_str(pdo_int64_t i64 TSRMLS_DC);
# define FALSE 0
#endif
#define PDO_DRIVER_API 20051002
#define PDO_DRIVER_API 20051031
enum pdo_param_type {
PDO_PARAM_NULL,
@ -645,6 +645,10 @@ PDO_API int pdo_parse_params(pdo_stmt_t *stmt, char *inquery, int inquery_len,
PDO_API void pdo_raise_impl_error(pdo_dbh_t *dbh, pdo_stmt_t *stmt,
const char *sqlstate, const char *supp TSRMLS_DC);
PDO_API void php_pdo_stmt_addref(pdo_stmt_t *stmt TSRMLS_DC);
PDO_API void php_pdo_stmt_delref(pdo_stmt_t *stmt TSRMLS_DC);
#endif /* PHP_PDO_DRIVER_H */
/*
* Local variables:

View File

@ -13,27 +13,44 @@ PDOTest::skip();
if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
$db->exec('CREATE TABLE test (id int NOT NULL PRIMARY KEY, val VARCHAR(256))');
$is_oci = $db->getAttribute(PDO::ATTR_DRIVER_NAME) == 'oci';
if ($is_oci) {
$db->exec('CREATE TABLE test (id int NOT NULL PRIMARY KEY, val BLOB)');
} else {
$db->exec('CREATE TABLE test (id int NOT NULL PRIMARY KEY, val VARCHAR(256))');
}
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$fp = tmpfile();
fwrite($fp, "I am the LOB data");
rewind($fp);
$insert = $db->prepare("insert into test (id, val) values (1, ?)");
$insert->bindValue(1, $fp, PDO::PARAM_LOB);
if ($is_oci) {
/* oracle is a bit different; you need to initiate a transaction otherwise
* the empty blob will be committed implicitly when the statement is
* executed */
$db->beginTransaction();
$insert = $db->prepare("insert into test (id, val) values (1, EMPTY_BLOB()) RETURNING val INTO :blob");
} else {
$insert = $db->prepare("insert into test (id, val) values (1, :blob)");
}
$insert->bindValue(':blob', $fp, PDO::PARAM_LOB);
$insert->execute();
$insert = null;
print_r($db->query("SELECT * from test")->fetchAll(PDO::FETCH_ASSOC));
$db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, true);
var_dump($db->query("SELECT * from test")->fetchAll(PDO::FETCH_ASSOC));
?>
--EXPECT--
Array
(
[0] => Array
(
[id] => 1
[val] => I am the LOB data
)
)
array(1) {
[0]=>
array(2) {
["id"]=>
string(1) "1"
["val"]=>
string(17) "I am the LOB data"
}
}

View File

@ -14,7 +14,7 @@ if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE_
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
$db->exec("CREATE TABLE test (id int(10) NOT NULL, PRIMARY KEY (id))");
$db->exec("CREATE TABLE test (id int NOT NULL, PRIMARY KEY (id))");
$db->exec("INSERT INTO test (id) VALUES (1)");
function heLLO($row) {

View File

@ -14,7 +14,7 @@ if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE_
require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
$db = PDOTest::factory();
$db->exec("CREATE TABLE test (id int(10) NOT NULL, PRIMARY KEY (id))");
$db->exec("CREATE TABLE test (id int NOT NULL, PRIMARY KEY (id))");
$db->exec("INSERT INTO test (id) VALUES (1)");
$values = array(1);