Eugen Konkov
Eugen Konkov

Reputation: 25153

Fatal: Illegal use of top-level '-ident' at

I have two boolean columns and I want to generate query: WHERE f1 or f2

I try to do at DBIx::Class searching for f1 OR f2. I tried:

->search([{ -bool => 'f1' }, { -bool => 'f2' }])

But I get error: Fatal: Illegal use of top-level '-ident' at

What I do wrong?

DBIx::Class uses SQL::Abstract. But I still do not understand from the documentation how to write search correctly.

I use PostgreSQL as database

SQLA version is '2.000001' DBIx::Class v0.082841

Upvotes: 2

Views: 186

Answers (4)

Eugen Konkov
Eugen Konkov

Reputation: 25153

Upgrading DBIx::Class from v0.082841 to v0.082842 Resolves problem

https://metacpan.org/release/RIBASUSHI/DBIx-Class-0.082842/source/Changes#L28

New version of DBIx::Class does not depend on SQL::Abstract any more

Upvotes: 1

Eugen Konkov
Eugen Konkov

Reputation: 25153

Downgrading SQL::Abstract to 1.86 from 2.000001 resolves problem

Successfully installed SQL-Abstract-1.86 (downgraded from 2.000001)

Upvotes: 0

Eugen Konkov
Eugen Konkov

Reputation: 25153

Example from ilmari@irc#dbix-class

$ psql myschema

myschema=# create table bools (f1 bool, f2 bool);
CREATE TABLE

$ cat lib/MySchema/Result/Bool.pm
package MySchema::Result::Bool;

use DBIx::Class::Candy (
    -autotable => v1,
);

column f1 => {
    data_type => 'boolean',
};

column f2 => {
    data_type => 'boolean',
};

1;

$ reply -l
0> my $s = MySchema->connect('dbi:Pg:dbname=myschema', undef, undef, { quote_names => 1 }); undef
$res[0] = undef

1> $s->storage->debug(1)
$res[1] = 1

2> $s->resultset('Bool')->search([{ -bool => 'f1' }, { -bool => 'f2' }])
SELECT "me"."f1", "me"."f2" FROM "bools" "me" WHERE ( ( "f1" OR "f2" ) ): 

Upvotes: 1

Anton Petrusevich
Anton Petrusevich

Reputation: 172

My proposal is to use "literals". This is very DB-specific, as this syntax is not supported by SQL Server or Oracle.

->where([\["f1"], \["f2"]]);

$ perl -MSQL::Abstract -E '$s=SQL::Abstract->new; ($w, @b) = $s->where([\["f1"], \["f2"]]); say $w'

WHERE ( ( f1 OR f2 ) )

Upvotes: 0

Related Questions