Skip Menu |

This queue is for tickets about the Rose-DB-Object CPAN distribution.

Report information
The Basics
Id: 98014
Status: resolved
Priority: 0/
Queue: Rose-DB-Object

People
Owner: siracusa [...] gmail.com
Requestors: TEMOON [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: 0.813



Subject: get_objects_from_sql extra prepare attr
There is no way to send extra to prepare statement when using Rose::DB::Object::Manager->get_objects_from_sql(). It is very important for PostgreSQL new JSONB type with operators like '?' and '?|' where the only way to execute query is made it by yourself and use get_objects_from_sql. But for this we need to send extra attributes to prepare: {pg_placeholder_dollaronly => 1}.
--- Manager.pm (revision 2313) +++ Manager.pm (working copy) @@ -3464,6 +3464,7 @@ my $methods = $args{'_methods'}; my $exec_args = $args{'args'} || []; + my $attr = $args{'attr'}; my $have_methods = ($args{'_methods'} && %{$args{'_methods'}}) ? 1 : 0; @@ -3499,8 +3500,8 @@ local $dbh->{'RaiseError'} = 1; $Debug && warn "$sql (", join(', ', @$exec_args), ")\n"; - my $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) : - $dbh->prepare($sql) or die $dbh->errstr; + my $sth = $prepare_cached ? $dbh->prepare_cached($sql, $attr, 3) : + $dbh->prepare($sql, $attr) or die $dbh->errstr; $sth->execute(@$exec_args); @@ -3591,6 +3592,7 @@ my $methods = $args{'_methods'}; my $exec_args = $args{'args'} || []; + my $attr = $args{'attr'}; my $have_methods = ($args{'_methods'} && %{$args{'_methods'}}) ? 1 : 0; @@ -3626,8 +3628,8 @@ local $dbh->{'RaiseError'} = 1; $Debug && warn "$sql (", join(', ', @$exec_args), ")\n"; - $sth = $prepare_cached ? $dbh->prepare_cached($sql, undef, 3) : - $dbh->prepare($sql) or die $dbh->errstr; + $sth = $prepare_cached ? $dbh->prepare_cached($sql, $attr, 3) : + $dbh->prepare($sql, $attr) or die $dbh->errstr; $sth->execute(@$exec_args); };
Subject: Manager.pm

Message body is not shown because it is too large.

Thanks for the patch. Do you also have documentation and tests?
There is tests path: --- db-object-manager.t (revision 2313) +++ db-object-manager.t (working copy) @@ -2331,13 +2331,27 @@ MyPgObjectManager->get_objects_from_sql( db => $db, args => [ 19 ], - sql => <<"EOF"); -SELECT * FROM rose_db_object_test WHERE id > ? ORDER BY id DESC + attr => { pg_placeholder_dollaronly => 1 }, + sql => <<'EOF'); +SELECT * FROM rose_db_object_test WHERE id > $1 ORDER BY id DESC EOF ok(scalar @$objs == 2, "get_objects_from_sql 9 - $db_type"); is($objs->[0]->id, 60, "get_objects_from_sql 10 - $db_type"); + $iterator = + MyPgObjectManager->get_objects_iterator_from_sql( + db => $db, + args => [ 19 ], + attr => { pg_placeholder_dollaronly => 1 }, + sql => <<'EOF'); +SELECT * FROM rose_db_object_test WHERE id > $1 ORDER BY id DESC +EOF + + $o = $iterator->next; + $o = $iterator->next; + is($o->id, 60, "get_objects_iterator_from_sql 11 - $db_type"); + my $method = MyPgObjectManager->make_manager_method_from_sql( get_em => <<"EOF");
Oops! Typo! The last three additions should be: $o = $iterator->next; is($o->id, 60, "get_objects_iterator_from_sql 11 - $db_type"); $iterator->finish();
I am not sure about documentation, because I am not fluent English speaker. @ -4684,6 +4686,10 @@ A reference to an array of arguments to be passed to L<DBI>'s L<execute|DBI/execute> method when the query is run. The number of items in this array must exactly match the number of placeholders in the SQL query. +=item B<attr HASHREF> + +A reference to a hash of attributes to be passed to L<DBI>'s L<prepare|DBI/prepare> or L<prepare_cached|DBI/prepare_cached> method when preparing the SQL statement. + =item B<db DB> A L<Rose::DB>-derived object used to access the database. If omitted, one will be created by calling the L<init_db|Rose::DB::Object/init_db> method of the C<object_class>.
OK, thanks. I may not be able to get to this for a while, but I will get to it.
Addressed in Rose::DB::Object 0.813, just uploaded to CPAN. Note that I changed the parameter name from "attr" to "prepare_options".