php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #57781 blob / clob with strings and streams
Submitted: 2007-08-12 17:41 UTC Modified: 2007-08-12 17:54 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: adrian dot vasile at opennet dot ro Assigned:
Status: Open Package: PDO_OCI (PECL)
PHP Version: 5.2.1 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: adrian dot vasile at opennet dot ro
New email:
PHP Version: OS:

 

 [2007-08-12 17:41 UTC] adrian dot vasile at opennet dot ro
Description:
------------
Hi all,

Actually it's version php 5.2.3. 
I saw in the code (oci_statement.c) that there is support for writing strings to blobs but it never reached the point of the if (stm) { ... } else { // it's a string ... }.

I also inserted a way to support clobs in PDO which is less obtrusive than the last patch in http://pecl.php.net/bugs/bug.php?id=7943 although you still need to use the 'RETURNING INTO' clause.

Reproduce code:
---------------
Unfortunately I don't have an actual piece of code to reproduce this but it's quite easy. Make a statement for insert a clob/blob and bind (bindParam) a string and execute the statement.

Expected result:
----------------
a succesful insert into the table

Actual result:
--------------
I always got an exception (the bound var wasn't of type resource - which it shouldn't be as it is a $string = 'ana\'s apples are green')

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-12 17:42 UTC] adrian dot vasile at opennet dot ro
diff -ruN php-5.2.3/ext/pdo_oci/oci_statement.c php-5.2.3.test/ext/pdo_oci/oci_statement.c
--- php-5.2.3/ext/pdo_oci/oci_statement.c	2007-01-26 17:07:45.000000000 +0200
+++ php-5.2.3.test/ext/pdo_oci/oci_statement.c	2007-08-07 20:11:20.000000000 +0300
@@ -282,7 +282,8 @@
 
 					case PDO_PARAM_LOB:
 						/* P->thing is now an OCILobLocator * */
-						P->oci_type = SQLT_BLOB;
+						P->oci_type = (pdo_attr_lval(param->driver_params, SQLT_CLOB, 0 TSRMLS_CC) == 1) ? SQLT_CLOB : SQLT_BLOB;
+						//P->oci_type = SQLT_BLOB;
 						value_sz = sizeof(OCILobLocator*);
 						break;
 
@@ -366,6 +367,27 @@
 							php_stream_to_zval(stm, param->parameter);
 							P->thing = NULL;
 						}
+					} else if (Z_TYPE_P(param->parameter) == IS_STRING) {
+						/* stick the string into the LOB */
+						size_t n;
+						ub4 amt, offset = 1;
+						char *consume;
+
+						consume = Z_STRVAL_P(param->parameter);
+						n = Z_STRLEN_P(param->parameter);
+						if (n) {
+							OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE);
+							while (n) {
+								amt = n;
+								OCILobWrite(S->H->svc, S->err, (OCILobLocator*)P->thing,
+										&amt, offset, consume, n,
+										OCI_ONE_PIECE,
+										NULL, NULL, 0, SQLCS_IMPLICIT);
+								consume += amt;
+								n -= amt;
+							}
+							OCILobClose(S->H->svc, S->err, (OCILobLocator*)P->thing);
+						}
 					} else {
 						/* we're a LOB being used for insert; transfer the data now */
 						size_t n;
@@ -395,23 +417,6 @@
 							} while (1);
 							OCILobClose(S->H->svc, S->err, (OCILobLocator*)P->thing);
 							OCILobFlushBuffer(S->H->svc, S->err, (OCILobLocator*)P->thing, 0);
-						} else if (Z_TYPE_P(param->parameter) == IS_STRING) {
-							/* stick the string into the LOB */
-							consume = Z_STRVAL_P(param->parameter);
-							n = Z_STRLEN_P(param->parameter);
-							if (n) {
-								OCILobOpen(S->H->svc, S->err, (OCILobLocator*)P->thing, OCI_LOB_READWRITE);
-								while (n) {
-									amt = n;
-									OCILobWrite(S->H->svc, S->err, (OCILobLocator*)P->thing,
-											&amt, offset, consume, n,
-											OCI_ONE_PIECE,
-											NULL, NULL, 0, SQLCS_IMPLICIT);
-									consume += amt;
-									n -= amt;
-								}
-								OCILobClose(S->H->svc, S->err, (OCILobLocator*)P->thing);
-							}
 						}
 						OCIDescriptorFree(P->thing, OCI_DTYPE_LOB);
 						P->thing = NULL;
 [2007-08-12 17:54 UTC] adrian dot vasile at opennet dot ro
Usage:

$stmt->bindParam (':the_clob', $string_or_stream, PDO::PARAM_LOB, 0, array (SQLT_CLOB => true));

My patch tries to be as unobtrusive as possible thus I made use of predefined constants (OCI extension)

Reminder: If you want to use it remember to have the OCI extension enabled
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC