update_objects with sort_by

15 views
Skip to first unread message

Scouarnec Erwan

unread,
Mar 14, 2013, 8:38:30 AM3/14/13
to rose-db...@googlegroups.com
Hello,

I want to produce this type of sql request :

update cc_configuration set version=version+1 where name='foo' order by version desc;

In RDBO :

Foo::DB::Configuration::Manager->update_configurations(

                                                  set =>

                                                  {

                                                   version => { sql => 'version + 1' },

                                                  },

                                                  where =>

                                                  [

                                                   name   => $self->name,

                                                  ],

                                                  sort_by => 'version DESC'

                                                 );

This produce bad SQL code (not in RDBO docs, i try ;) ) :

UPDATE cc_configuration
SET
version = version + 1
ORDER BY version DESC
WHERE
name = ?

Can I produce a sql update with order by with Rose::DB::Object FrameWork ?

Cheers,
ES

John Siracusa

unread,
Mar 14, 2013, 9:21:37 AM3/14/13
to rose-db...@googlegroups.com
On Thu, Mar 14, 2013 at 8:38 AM, Scouarnec Erwan
<scouarn...@gmail.com> wrote:
> I want to produce this type of sql request :
>
> update cc_configuration set version=version+1 where name='foo' order by
> version desc;

Why do you think you need the "order by" clause there?

> In RDBO :
>
> Foo::DB::Configuration::Manager->update_configurations(
...
> sort_by => 'version DESC'

sort_by is not a valid parameter to update_objects()

http://search.cpan.org/dist/Rose-DB-Object/lib/Rose/DB/Object/Manager.pm#update_objects

-John

Scouarnec Erwan

unread,
Mar 14, 2013, 9:44:10 AM3/14/13
to rose-db...@googlegroups.com
I have a table with the following fields:

    columns => [
        version        => { type => 'integer', not_null => 1 },
        name => { type => 'varchar', length => 20, not_null => 1 },
        tacacs         => { type => 'varchar', length => 30 },
        date           => { type => 'datetime' },
        stored_date    => { type => 'datetime' },
        path           => { type => 'varchar', default => '', length => 255 },
    ],

    primary_key_columns => [ 'version', 'name' ],


Version "0" indicates the current version, to store a new version i must update all old versions (version+1) and insert the new version (0).
I know there is no option in the documentation.
I just wanted to know if there is a workaround with RDBO.

I currently test migration from custom framework to RDBO.

ES

John Siracusa

unread,
Mar 14, 2013, 9:45:37 AM3/14/13
to rose-db...@googlegroups.com
On Thu, Mar 14, 2013 at 9:44 AM, Scouarnec Erwan
<scouarn...@gmail.com> wrote:
> Version "0" indicates the current version, to store a new version i must
> update all old versions (version+1) and insert the new version (0).
> I know there is no option in the documentation.I just wanted to know if
> there is a workaround with RDBO.

You can always just run the query you want to run directly using DBI.
RDBO has no good way to generate the SQL you want.

-John

Scouarnec Erwan

unread,
Mar 14, 2013, 11:00:31 AM3/14/13
to rose-db...@googlegroups.com
Thank you for the quick response and thank you for this wonderful ORM.

Cheers,

ES

Le jeudi 14 mars 2013 13:38:30 UTC+1, Scouarnec Erwan a écrit :
Reply all
Reply to author
Forward
0 new messages