SQL error under 0.08108 or higher

2 messages Options
Embed this post
Permalink
Carl Franks

SQL error under 0.08108 or higher

Reply Threaded More More options
Print post
Permalink
I've got some code that's started throwing an exception after
ugprading DBIx-Class from 0.08107 to 0.08108 or higher.

The error only occurs under MySQL (v3.23.49) - it runs without error
using SQLite.

Under 0.08107, the generated SQL used an explicit LEFT JOIN:
SELECT COUNT( * ) FROM group_rel me LEFT JOIN groups groups ON
groups.id = me.group_id WHERE ( me.parent_id = ? ): '1'

Under 0.08108 and above, the type of join isn't specified, causing the
following error:
DBIx::Class::ResultSet::count(): DBI Exception: DBD::mysql::st execute
failed: You have an error in your SQL syntax near 'ON groups.id =
me.group_id WHERE ( me.parent_id = '1' )' at line 1 [for Statement
"SELECT COUNT( * ) FROM group_rel me JOIN groups groups ON groups.id =
me.group_id WHERE ( me.parent_id = ? )" with ParamValues: 0='1']

The code I am running is:

$group->search_related( 'child_rel' )
    ->search_related( 'groups' )
    ->count;

Is there a problem with the relationships I have defined?
My two relevant package definitions are:

package CMS::Schema::Group;

__PACKAGE__->add_columns(
    "id",
    {
        data_type     => "INTEGER",
        is_nullable   => 0,
        is_auto_increment => 1,
    },
    "name",
    {   data_type     => "VARCHAR",
        is_nullable   => 0,
    },
);

__PACKAGE__->has_many( child_rel => 'CMS::Schema::GroupRel', 'parent_id' );

###

package CMS::Schema::GroupRel;

__PACKAGE__->add_columns(
    "group_id",
    {
        data_type     => "INTEGER",
        is_nullable   => 0,
    },
    "parent_id",
    {
        data_type     => "INTEGER",
        is_nullable   => 0,
    },
);

__PACKAGE__->has_many( groups => 'CMS::Schema::Group', 'id' );

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Carl Franks

Re: SQL error under 0.08108 or higher

Reply Threaded More More options
Print post
Permalink
After some discussion on irc, ribasushi++ has applied a fix for this in svn.

Thanks,
Carl

2009/8/31 Carl Franks <[hidden email]>:

> I've got some code that's started throwing an exception after
> ugprading DBIx-Class from 0.08107 to 0.08108 or higher.
>
> The error only occurs under MySQL (v3.23.49) - it runs without error
> using SQLite.
>
> Under 0.08107, the generated SQL used an explicit LEFT JOIN:
> SELECT COUNT( * ) FROM group_rel me LEFT JOIN groups groups ON
> groups.id = me.group_id WHERE ( me.parent_id = ? ): '1'
>
> Under 0.08108 and above, the type of join isn't specified, causing the
> following error:
> DBIx::Class::ResultSet::count(): DBI Exception: DBD::mysql::st execute
> failed: You have an error in your SQL syntax near 'ON groups.id =
> me.group_id WHERE ( me.parent_id = '1' )' at line 1 [for Statement
> "SELECT COUNT( * ) FROM group_rel me JOIN groups groups ON groups.id =
> me.group_id WHERE ( me.parent_id = ? )" with ParamValues: 0='1']
>
> The code I am running is:
>
> $group->search_related( 'child_rel' )
>    ->search_related( 'groups' )
>    ->count;
>
> Is there a problem with the relationships I have defined?
> My two relevant package definitions are:
>
> package CMS::Schema::Group;
>
> __PACKAGE__->add_columns(
>    "id",
>    {
>        data_type     => "INTEGER",
>        is_nullable   => 0,
>        is_auto_increment => 1,
>    },
>    "name",
>    {   data_type     => "VARCHAR",
>        is_nullable   => 0,
>    },
> );
>
> __PACKAGE__->has_many( child_rel => 'CMS::Schema::GroupRel', 'parent_id' );
>
> ###
>
> package CMS::Schema::GroupRel;
>
> __PACKAGE__->add_columns(
>    "group_id",
>    {
>        data_type     => "INTEGER",
>        is_nullable   => 0,
>    },
>    "parent_id",
>    {
>        data_type     => "INTEGER",
>        is_nullable   => 0,
>    },
> );
>
> __PACKAGE__->has_many( groups => 'CMS::Schema::Group', 'id' );
>

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...