On Wed, Jan 19, 2011 at 04:39:24PM +0100, Peter Bex wrote:
> diff -r 491a9039ec03 common/libraries/php/database/database.class.php
> --- a/common/libraries/php/database/database.class.php Wed Jan 19 12:08:42
> 2011 +0100
> +++ b/common/libraries/php/database/database.class.php Wed Jan 19 15:02:44
> 2011 +0100
> @@ -890,7 +890,7 @@
> return $this->connection->escape($text, $escape_wildcards);
> }
>
> - function query($query, $types = null, $result_class = true,
> $result_wrap_class = false)
> + function query($query, $types = true, $result_class = true,
> $result_wrap_class = false)
> {
> $result = $this->connection->query($query, $types, $result_class,
> $result_wrap_class);
> if (MDB2::isError($result))
>
>
> This fixes a lot, but it also introduces new problems: Some tables have
> 'text' fields with no limit set. MDB2 maps those to 'clobs'; character large
> objects. These are represented as a "resource", which is like a type of
> stream from which you can read bytes like you would from a file.
The attached patch makes it work. It's a bit of a workaround but without
support in MDB2 to do it differently I don't see how this can be improved.
If you want to try this patch you'll need to apply a bugfix patch for
MDB2 as well; https://pear.php.net/bugs/bug.php?id=18203
or you can use changeset ba7dc72fa8b1 from my postgres repository at
http://dev.solide-ict.nl/hg-pub/chamilo2-pgsql
Asides from this patch there are over a hundred different places in the
code where fetchRow() is still directly used. I think those would need
to be refactored to go through the Chamilo database abstraction layer
instead of directly using MDB2.
Comments? Opinions?
Cheers,
Peter Bex
Solide ICT - http://www.solide-ict.nl
diff -r ba7dc72fa8b1 common/libraries/php/database/database.class.php
--- a/common/libraries/php/database/database.class.php Thu Jan 20 13:59:42
2011 +0100
+++ b/common/libraries/php/database/database.class.php Thu Jan 20 14:22:31
2011 +0100
@@ -758,6 +758,15 @@
$this->mdb2_error_to_exception($record);
}
+ foreach($record as &$field) {
+ if (is_resource($field)) {
+ $data = '';
+ while(!feof($field))
+ $data .= fread($field, 1024);
+ $field = $data;
+ }
+ }
+
if ($record)
{
return $record;
@@ -890,7 +899,7 @@
return $this->connection->escape($text, $escape_wildcards);
}
- function query($query, $types = null, $result_class = true,
$result_wrap_class = false)
+ function query($query, $types = true, $result_class = true,
$result_wrap_class = false)
{
$result = $this->connection->query($query, $types, $result_class,
$result_wrap_class);
if (MDB2::isError($result))
diff -r ba7dc72fa8b1 common/libraries/php/database/object_result_set.class.php
--- a/common/libraries/php/database/object_result_set.class.php Thu Jan 20
13:59:42 2011 +0100
+++ b/common/libraries/php/database/object_result_set.class.php Thu Jan 20
14:22:31 2011 +0100
@@ -50,6 +50,14 @@
if ($record = $this->get_handle()->fetchRow(MDB2_FETCHMODE_ASSOC))
{
$this->increment_current();
+ foreach($record as &$field) {
+ if (is_resource($field)) {
+ $data = '';
+ while(!feof($field))
+ $data .= fread($field, 1024);
+ $field = $data;
+ }
+ }
return $this->data_manager->record_to_object($record,
$this->class_name);
}
else
_______________________________________________
Dev mailing list
[email protected]
http://lists.chamilo.org/listinfo/dev