improve infrastructure for LOB support.
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
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;
# define FALSE 0
#endif
-#define PDO_DRIVER_API 20051002
+#define PDO_DRIVER_API 20051031
enum pdo_param_type {
PDO_PARAM_NULL,
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:
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"
+ }
+}
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) {
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);