Skip to content

Commit 42c36a3

Browse files
committed
check the datestyle before setting it, if it is different than ISO change it, otherwise leave it as is
1 parent c00b3d2 commit 42c36a3

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

connection.c

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,29 @@ LIBPQ_CC_connect(ConnectionClass *self, char *salt_para)
10941094

10951095
if (ret = LIBPQ_connect(self), ret <= 0)
10961096
return ret;
1097-
res = CC_send_query(self, "SET DateStyle = 'ISO';SET extra_float_digits = 2;" ISOLATION_SHOW_QUERY, NULL, READ_ONLY_QUERY, NULL);
1097+
1098+
/* Check current DateStyle first */
1099+
res = CC_send_query(self, "SHOW DateStyle;", NULL, READ_ONLY_QUERY, NULL);
1100+
if (QR_command_maybe_successful(res))
1101+
{
1102+
1103+
if (res->command && (stricmp(res->command, "SHOW") == 0)
1104+
&& (strcmp(QR_get_fieldname(res, 0), "DateStyle") == 0)){
1105+
const char * datestyle = QR_get_value_backend_text(res, 0, 0);
1106+
/* Only set DateStyle if it's not already ISO */
1107+
if (datestyle && (strncmp(datestyle, "ISO", 3) != 0))
1108+
{
1109+
QR_Destructor(res);
1110+
res = CC_send_query(self, "SET DateStyle = 'ISO';" ISOLATION_SHOW_QUERY, NULL, READ_ONLY_QUERY, NULL);
1111+
}
1112+
else
1113+
{
1114+
QR_Destructor(res);
1115+
res = CC_send_query(self, ISOLATION_SHOW_QUERY, NULL, READ_ONLY_QUERY, NULL);
1116+
}
1117+
}
1118+
}
1119+
10981120
if (QR_command_maybe_successful(res))
10991121
{
11001122
handle_show_results(res);

0 commit comments

Comments
 (0)