Re: ECPG - how to fetch then sort strings - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: ECPG - how to fetch then sort strings
Date
Msg-id 20060908154759.GJ5479@svana.org
Whole thread Raw
In response to ECPG - how to fetch then sort strings  (Poul Jensen <flyvholm@gfy.ku.dk>)
Responses Re: ECPG - how to fetch then sort strings  (Poul Jensen <flyvholm@gfy.ku.dk>)
List pgsql-general
Please don't use "reply" to start new thread, thanks.

On Fri, Sep 08, 2006 at 05:55:44AM -0800, Poul Jensen wrote:
> I need to fetch strings from a database with ECPG and then sort them in
> C. Here is one of my failed attempts:

<snip>
>  varchar filenms[][maxlen]=NULL;

I think you need to reread the C manual as to the difference between
arrays and pointers. I'm don't know about ECPG, but I think your other
attempt, using "char**" was much closer to the mark.

> It compiles ok, but I get garbage in variable filenms. If I change the
> declaration of filenms to:
>  char **filenms=NULL;
> the SQL query returns strings ok. But the strings have variable length,
> and I need to specify one length in qsort, so it won't work. Another

Since you're declaring a array of pointers to char, the width you have
to specify to qsort would be sizeof(char*). I think you can just use
the normal strcmp() function with qsort then.

Ofcourse, you could get the database to sort them for you...

Hope this helps,
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

Attachment

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Query performance inconsistant.
Next
From: "Michael Schmidt"
Date:
Subject: Re: PostgreSQL books for beginner