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


In reply to SQLite (DBD) Sorting by fanticla

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.