Received: from minbar.arcamax.com (host-10.arcamax.com [206.246.240.138]) by hub.org (8.8.8/8.8.8) with ESMTP id JAA00418 for ; Wed, 30 Sep 1998 09:26:04 -0400 (EDT) (envelope-from bryan@arcamax.com) Received: from bryan.arcamax.com (bryan [206.246.240.163]) by minbar.arcamax.com (8.8.7/8.8.7) with SMTP id JAA09183; Wed, 30 Sep 1998 09:19:41 -0400 Message-ID: <001401bdec74$fb55af20$a3f0f6ce@bryan.arcamax.com> From: "Bryan White" To: "James Olin Oden" , "Bob Smither" Cc: "Glenn Sullivan" , Subject: Re: [SQL] Getting datatype before SELECT Date: Wed, 30 Sep 1998 09:19:40 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 4.72.3110.5 X-MimeOLE: Produced By Microsoft MimeOLE V4.72.3110.3 >> Not at all sure how to do this from C, but from perl I do something like >> this: >> >> $temp = `psql -d databasename -c "\\d tablename"` >> >> The item between the `s is executed and the result returned to the >> variable. $temp now has the full structure of the table and can be parsed >> to extract the column names and types. The double \\ is needed to prevent >> perl from thinking that \d is a meta character (I think). >> >> The output of the command between the `s could also be redirected to a >> file. > >In C he could do essentially the same thing. One approach is to use system as >so: > > system("psql -d databasename -c \"\\d tablename\" -o /tmp/somefile"); > >And then he could open the file /tmp/somefile and parse his way through it. >Also, he can do the what perl does to create pipes (perl is written in C) and >essentially do the same thing as you are doing. I personally would go with >the temp file, using my proccess id to as part of the tempfile name to make it >unique to my process, but it should not be to much work to make the proper >system calls to do the piping...james Is that not what popen/pclose are for. i.e FILE *f = popen("psql -d databasename -c \"\\d tablename\"","r"); ... pclose(f);