fanticla has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
I have a simple SQLite database. I read the content of the table and print it out (in a TK table). When printing it out, I need to sort the entries in an alphabetical order. Easy for English, but I have a small set of non-ASCII characters, such as german ä/ü/ö. I came up with:
order by column collate NOCASE
Result (orderd): a g x ä
Right order: a ä g x
My script:
$dbh = DBI->connect( "dbi:SQLite:files/database/data.db" ) || die "Can +not connect: $DBI::errstr"; $selected = $dbh->selectall_arrayref("SELECT ID,column1,column2 FROM +table order by column1 collate NOCASE"); foreach my $row_db (@$selected ) { my ($ID, $column1, $column2) = @$row_db; print "$column1\n"; }
One day of manuals and goole gave me no clue! (Mea culpa)!
I am not familiar with creating new collate in perl. Unfortunatelly I didn't find any example out there. I thought even about the posibility to substitute ä->a before performing SELECT. Or... maybe doing the sorting in perl at the stage of 'foreach' (@$selected), maybe not the best solution, but probably the easiest one.
Can any of you suggest a - possible easy - way to solve the problem?
THANXS Cla
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: SQLite (DBD) Sorting
by choroba (Cardinal) on Apr 29, 2010 at 15:41 UTC | |
|
Re: SQLite (DBD) Sorting
by thundergnat (Deacon) on Apr 29, 2010 at 17:00 UTC | |
by Anonymous Monk on Apr 29, 2010 at 18:19 UTC | |
by ikegami (Patriarch) on Apr 29, 2010 at 18:47 UTC | |
by thundergnat (Deacon) on Apr 29, 2010 at 18:48 UTC | |
by fanticla (Scribe) on Apr 30, 2010 at 09:02 UTC |