Skip to content

Commit 77ca045

Browse files
author
Michael Meskes
committed
Fixed bug in %s handling.
1 parent 5e21197 commit 77ca045

File tree

6 files changed

+29
-14
lines changed

6 files changed

+29
-14
lines changed

src/interfaces/ecpg/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2405,6 +2405,10 @@ Wed, 17 Dec 2008 17:49:11 +0100
24052405

24062406
- Applied patch by ITAGAKI Takahiro <itagaki.takahiro@oss.ntt.co.jp> to
24072407
fix segfault on non-glibc systems.
2408+
2409+
Mon, 02 Feb 2009 16:34:53 +0100
2410+
2411+
- Fixed bug in handling of "%s" pattern in PGTYPEStimestamp_defmt_asc().
24082412
- Set pgtypes library version to 3.1.
24092413
- Set compat library version to 3.1.
24102414
- Set ecpg library version to 6.2.

src/interfaces/ecpg/pgtypeslib/dt_common.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.44 2007/11/15 21:14:45 momjian Exp $ */
1+
/* $PostgreSQL: pgsql/src/interfaces/ecpg/pgtypeslib/dt_common.c,v 1.45 2009/02/02 15:35:28 meskes Exp $ */
22

33
#include "postgres_fe.h"
44

@@ -990,17 +990,13 @@ GetEpochTime(struct tm * tm)
990990

991991
t0 = gmtime(&epoch);
992992

993-
tm->tm_year = t0->tm_year;
994-
tm->tm_mon = t0->tm_mon;
993+
tm->tm_year = t0->tm_year + 1900;
994+
tm->tm_mon = t0->tm_mon + 1;
995995
tm->tm_mday = t0->tm_mday;
996996
tm->tm_hour = t0->tm_hour;
997997
tm->tm_min = t0->tm_min;
998998
tm->tm_sec = t0->tm_sec;
999999

1000-
if (tm->tm_year < 1900)
1001-
tm->tm_year += 1900;
1002-
tm->tm_mon++;
1003-
10041000
return;
10051001
} /* GetEpochTime() */
10061002

@@ -2856,8 +2852,8 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp * d,
28562852
time_t et = (time_t) scan_val.luint_val;
28572853

28582854
tms = gmtime(&et);
2859-
*year = tms->tm_year;
2860-
*month = tms->tm_mon;
2855+
*year = tms->tm_year + 1900;
2856+
*month = tms->tm_mon + 1;
28612857
*day = tms->tm_mday;
28622858
*hour = tms->tm_hour;
28632859
*minute = tms->tm_min;

src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,17 +422,24 @@ if (sqlca.sqlcode < 0) sqlprint ( );}
422422
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
423423
free(text);
424424

425+
in = "1234567890";
426+
fmt = "%s";
427+
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
428+
text = PGTYPEStimestamp_to_asc(ts1);
429+
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
430+
free(text);
431+
425432
{ ECPGtrans(__LINE__, NULL, "rollback");
426-
#line 351 "dt_test.pgc"
433+
#line 358 "dt_test.pgc"
427434

428435
if (sqlca.sqlcode < 0) sqlprint ( );}
429-
#line 351 "dt_test.pgc"
436+
#line 358 "dt_test.pgc"
430437

431438
{ ECPGdisconnect(__LINE__, "CURRENT");
432-
#line 352 "dt_test.pgc"
439+
#line 359 "dt_test.pgc"
433440

434441
if (sqlca.sqlcode < 0) sqlprint ( );}
435-
#line 352 "dt_test.pgc"
442+
#line 359 "dt_test.pgc"
436443

437444

438445
return (0);

src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
[NO_PID]: sqlca: code: 0, state: 00000
4343
[NO_PID]: ecpg_get_data on line 38: RESULT: 2000-07-12 17:34:29 offset: -1; array: yes
4444
[NO_PID]: sqlca: code: 0, state: 00000
45-
[NO_PID]: ECPGtrans on line 351: action "rollback"; connection "regress1"
45+
[NO_PID]: ECPGtrans on line 358: action "rollback"; connection "regress1"
4646
[NO_PID]: sqlca: code: 0, state: 00000
4747
[NO_PID]: ecpg_finish: connection regress1 closed
4848
[NO_PID]: sqlca: code: 0, state: 00000

src/interfaces/ecpg/test/expected/pgtypeslib-dt_test.stdout

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,4 @@ timestamp_defmt_asc(September 6 at 01:30 pm in the year 1983, %B %d at %I:%M %p
4646
timestamp_defmt_asc( 1976, July 14. Time: 9:15am, %Y, %B %d. Time: %I:%M %p) = 1976-07-14 09:15:00, error: 0
4747
timestamp_defmt_asc( 1976, July 14. Time: 9:15 am, %Y, %B %d. Time: %I:%M%p) = 1976-07-14 09:15:00, error: 0
4848
timestamp_defmt_asc( 1976, P.M. July 14. Time: 9:15, %Y, %P %B %d. Time: %I:%M) = 1976-07-14 21:15:00, error: 0
49+
timestamp_defmt_asc(1234567890, %s) = 2009-02-13 23:31:30, error: 0

src/interfaces/ecpg/test/pgtypeslib/dt_test.pgc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,13 @@ main(void)
348348
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
349349
free(text);
350350

351+
in = "1234567890";
352+
fmt = "%s";
353+
i = PGTYPEStimestamp_defmt_asc(in, fmt, &ts1);
354+
text = PGTYPEStimestamp_to_asc(ts1);
355+
printf("timestamp_defmt_asc(%s, %s) = %s, error: %d\n", in, fmt, text, i);
356+
free(text);
357+
351358
exec sql rollback;
352359
exec sql disconnect;
353360

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy