Catalyst

utf8 w bazie:

The fix depends on your database driver, but many of them have a magic attribute you can pass to the DBI->connect call to make them utf-8 safe. Some of them are listed below:

Driver Database Utf-8 attribute

DBD::Pg PostgreSQL pg_enable_utf8 => 1 DBD::mysql MySQL mysql_enable_utf8 => 1 DBD::SQLite SQLite sqlite_unicode => 1

(Warning: The MySQL option is currently “experimental and may change in future versions” and SQLite requires special handling of blobs with the unicode flag enabled.)

So for PostgreSQL you would do something like:

my $dbh = DBI->connect( $dsn, $user, $pass, { AutoCommit => 1, RaiseError => 0, pg_enable_utf8 => 1 } );

Bardziej zaawansowane wyszukiwanie

$rs->search({ age => 20 })                        # WHERE age = 20                   =
$rs->search({ age => {'>' => 20} })               # WHERE age > 20                   >
$rs->search({ age => undef })                     # WHERE age is NULL                NULL
$rs->search([{ age => 20 },{ age => 30 }])        # WHERE age = 20 OR age = 30       OR
$rs->search({ age => 20, name => 'taro })         # WHERE age = 20 AND name = 'taro' AND
$rs->search({ 'age' => { '>' => 10, '' => 20 }}) # WHERE age > 10 AND age  20      AND  ....
$rs->search_like({ name => '%taro%' })            # WHERE name LIKE '%taro%'         LIKE
$rs->search({id => {-in => \@ids}})               # WHERE id in (1,2,3..)            IN

np. wyrażenie OR można zrobić na 2 sposoby:

  $rs->search(
            {
              -or => [
                'nazwa' => {-ilike => "%$search%"},
                'klasa' => {-ilike => "$search%"}
                 ]
            },
            {order_by => 'miejscowosc', rows=>$pageRecords })->page($strona);

albo:

$rs->search(
    [
      {'nazwa' => {-ilike => "%$search%"}},
      {'klasa' => {-ilike => "$search%"}}
     ],
     {order_by => 'miejscowosc', rows=>$pageRecords })->page($strona);

Wyszukiwanie 'case insensitive' (działa w postgresie)

      my $lista = $c->model('DB::SzablonyView')->pokaz_wybrane($plikDanych)->search(
                           { 'nazwa' => {-ilike => "%$search%"}},
                           { rows=>$pageRecords }
                      )->page($strona);

select na wybranych kolumnach tabeli