pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedNewbie Q: How to deal with date/time with libpq or ecpg?
2+ messages / 2 participants
[nested] [flat]
* Newbie Q: How to deal with date/time with libpq or ecpg?
@ 1999-02-24 15:38 Michael Zhang <mzhang@ifscorp.com>
1999-02-24 20:36 ` Re: [INTERFACES] Newbie Q: How to deal with date/time with libpq or ecpg? Michael Meskes <Michael_Meskes@topmail.de>
0 siblings, 1 reply; 2+ messages in thread
From: Michael Zhang @ 1999-02-24 15:38 UTC (permalink / raw)
To: pgsql-interfaces
Hi, I am new to the postgreSQL.
I would like to set up my own WWW server using linux/postgreSQL. Some of
my web applications use many date/time manipulations. For example, I
would like to dynamicly display a date of birth column with specified
format. I could do it on Oracle like this:
SELECT to_char(DateofBirth, 'MM-DD-YYYY') from Employee_tbl where
First_nm = 'Mike';
Then I could use Pro*C to retrive the result into a char[] array.
But how can I receiver this kind of information with specified format in
postgreSQL by using libpq or ecpg?
Thanks in advance!
Mike
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: [INTERFACES] Newbie Q: How to deal with date/time with libpq or ecpg?
1999-02-24 15:38 Newbie Q: How to deal with date/time with libpq or ecpg? Michael Zhang <mzhang@ifscorp.com>
@ 1999-02-24 20:36 ` Michael Meskes <Michael_Meskes@topmail.de>
0 siblings, 0 replies; 2+ messages in thread
From: Michael Meskes @ 1999-02-24 20:36 UTC (permalink / raw)
To: pgsql-interfaces
On Wed, Feb 24, 1999 at 10:38:42AM -0500, Michael Zhang wrote:
> my web applications use many date/time manipulations. For example, I
> would like to dynamicly display a date of birth column with specified
> format. I could do it on Oracle like this:
I'm not sure about format changing but libpq returns all data as string and
ecpg does put it into a char array without a problem.
I attach an example.
Michael
--
Michael Meskes | Go SF 49ers!
Th.-Heuss-Str. 61, D-41812 Erkelenz | Go Rhein Fire!
Tel.: (+49) 2431/72651 | Use Debian GNU/Linux!
Email: Michael.Meskes@gmx.net | Use PostgreSQL!
Attachments:
test2.pgc (text/plain, 3.3K) download
#include <stdio.h>
exec sql include header_test;
exec sql type c is char reference;
typedef char* c;
exec sql type ind is union { int integer; short smallinteger; };
typedef union { int integer; short smallinteger; } ind;
int
main ()
{
typedef struct { long born; short age; } birthinfo;
exec sql type birthinfo is struct { long born; short age; };
exec sql begin declare section;
struct personal_struct { varchar name[8];
birthinfo birth;
} personal;
struct personal_indicator { int ind_name;
birthinfo ind_birth;
} ind_personal;
int ind_married;
ind children;
ind ind_children;
char married[11];
c testname="Petra";
char *query="select name, born, age, married, children from meskes where name = :var1";
exec sql end declare section;
exec sql var ind_married is long;
exec sql declare cur cursor for
select name, born, age, married, children from meskes;
char msg[128], command[128];
FILE *dbgs;
if ((dbgs = fopen("log", "w")) != NULL)
ECPGdebug(1, dbgs);
strcpy(msg, "connect");
exec sql connect to unix:postgresql://localhost:5432/mm;
strcpy(msg, "create");
exec sql create table meskes(name char(8), born integer, age smallint, married date, children integer);
strcpy(msg, "insert");
exec sql insert into meskes(name, married, children) values ('Petra', '19900404', 3);
exec sql insert into meskes(name, born, age, married, children) values ('Michael', 19660117, 33, '19900404', 3);
exec sql insert into meskes(name, born, age) values ('Carsten', 19910103, 8);
exec sql insert into meskes(name, born, age) values ('Marc', 19930907, 5);
exec sql insert into meskes(name, born, age) values ('Chris', 19970923, 1);
strcpy(msg, "commit");
exec sql commit;
strcpy(msg, "open");
exec sql open cur;
exec sql whenever not found do break;
while (1) {
strcpy(msg, "fetch");
exec sql fetch in cur into :personal:ind_personal, :married:ind_married, :children.integer:ind_children.smallinteger;
printf("%8.8s", personal.name.arr);
if (ind_personal.ind_birth.born >= 0)
printf(", born %d", personal.birth.born);
if (ind_personal.ind_birth.age >= 0)
printf(", age = %d", personal.birth.age);
if (ind_married >= 0)
printf(", married %s", married);
if (ind_children.smallinteger >= 0)
printf(", children = %d", children.integer);
putchar('\n');
}
strcpy(msg, "close");
exec sql close cur;
/* and now the same query with prepare */
exec sql prepare MM from :query;
exec sql declare prep cursor for MM;
strcpy(msg, "open");
exec sql open prep using :testname;
exec sql whenever not found do break;
while (1) {
strcpy(msg, "fetch");
exec sql fetch in prep into :personal:ind_personal, :married:ind_married, :children.integer:ind_children.smallinteger;
printf("%8.8s", personal.name.arr);
if (ind_personal.ind_birth.born >= 0)
printf(", born %d", personal.birth.born);
if (ind_personal.ind_birth.age >= 0)
printf(", age = %d", personal.birth.age);
if (ind_married >= 0)
printf(", married %s", married);
if (ind_children.smallinteger >= 0)
printf(", children = %d", children.integer);
putchar('\n');
}
strcpy(msg, "close");
exec sql close prep;
strcpy(msg, "drop");
exec sql drop table meskes;
strcpy(msg, "commit");
exec sql commit;
strcpy(msg, "disconnect");
exec sql disconnect;
if (dbgs != NULL)
fclose(dbgs);
return (0);
}
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~1999-02-24 20:36 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
1999-02-24 15:38 Newbie Q: How to deal with date/time with libpq or ecpg? Michael Zhang <mzhang@ifscorp.com>
1999-02-24 20:36 ` Michael Meskes <Michael_Meskes@topmail.de>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox