|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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')
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Nov 07 12:00:01 2025 UTC |
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;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