PostgreSQL Source Code: src/backend/commands/variable.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
18
19#include <ctype.h>
20
36#include "utils/fmgrprotos.h"
43
44
45
46
47
48
49
50
51bool
53{
56 bool have_style = false;
57 bool have_order = false;
58 bool ok = true;
59 char *rawstring;
60 int *myextra;
61 char *result;
62 List *elemlist;
64
65
67
68
70 {
71
75 return false;
76 }
77
78 foreach(l, elemlist)
79 {
80 char *tok = (char *) lfirst(l);
81
82
83
85 {
87 ok = false;
89 have_style = true;
90 }
92 {
94 ok = false;
96 have_style = true;
97 }
99 {
101 ok = false;
103 have_style = true;
104 }
106 {
108 ok = false;
110 have_style = true;
111
112 if (!have_order)
114 }
116 {
118 ok = false;
120 have_order = true;
121 }
124 {
126 ok = false;
128 have_order = true;
129 }
133 {
135 ok = false;
137 have_order = true;
138 }
140 {
141
142
143
144
145
146
147
148 char *subval;
149 void *subextra = NULL;
150
152 if (!subval)
153 {
154 ok = false;
155 break;
156 }
158 {
160 ok = false;
161 break;
162 }
163 myextra = (int *) subextra;
164 if (!have_style)
165 newDateStyle = myextra[0];
166 if (!have_order)
167 newDateOrder = myextra[1];
170 }
171 else
172 {
174 pfree(rawstring);
176 return false;
177 }
178 }
179
180 pfree(rawstring);
182
183 if (!ok)
184 {
186 return false;
187 }
188
189
190
191
193 if (!result)
194 return false;
195
196 switch (newDateStyle)
197 {
199 strcpy(result, "ISO");
200 break;
202 strcpy(result, "SQL");
203 break;
205 strcpy(result, "German");
206 break;
207 default:
208 strcpy(result, "Postgres");
209 break;
210 }
211 switch (newDateOrder)
212 {
214 strcat(result, ", YMD");
215 break;
217 strcat(result, ", DMY");
218 break;
219 default:
220 strcat(result, ", MDY");
221 break;
222 }
223
226
227
228
229
230 myextra = (int *) guc_malloc(LOG, 2 * sizeof(int));
231 if (!myextra)
232 return false;
233 myextra[0] = newDateStyle;
234 myextra[1] = newDateOrder;
235 *extra = myextra;
236
237 return true;
238}
239
240
241
242
243void
245{
246 int *myextra = (int *) extra;
247
250}
251
252
253
254
255
256
257
258
259
260bool
262{
264 long gmtoffset;
265 char *endptr;
266 double hours;
267
269 {
270
271
272
273
274 const char *valueptr = *newval;
275 char *val;
277
278 valueptr += 8;
279 while (isspace((unsigned char) *valueptr))
280 valueptr++;
281 if (*valueptr++ != '\'')
282 return false;
284
285 endptr = strchr(val, '\'');
286 if (!endptr || endptr[1] != '\0')
287 {
289 return false;
290 }
291 *endptr = '\0';
292
293
294
295
296
297
298
303
306 {
309 return false;
310 }
312 {
315 return false;
316 }
317
318
321
323 }
324 else
325 {
326
327
328
329 hours = strtod(*newval, &endptr);
330 if (endptr != *newval && *endptr == '\0')
331 {
332
335 }
336 else
337 {
338
339
340
342
343 if (!new_tz)
344 {
345
346 return false;
347 }
348
350 {
351 GUC_check_errmsg("time zone \"%s\" appears to use leap seconds",
354 return false;
355 }
356 }
357 }
358
359
360 if (!new_tz)
361 {
363 return false;
364 }
365
366
367
368
370 if (!*extra)
371 return false;
372 *((pg_tz **) *extra) = new_tz;
373
374 return true;
375}
376
377
378
379
380void
382{
384
386}
387
388
389
390
391const char *
393{
394 const char *tzn;
395
396
398
399 if (tzn != NULL)
400 return tzn;
401
402 return "unknown";
403}
404
405
406
407
408
409
410
411
412
413
414
415
416
417bool
419{
421
422
423
424
426
427 if (!new_tz)
428 {
429
430 return false;
431 }
432
434 {
435 GUC_check_errmsg("time zone \"%s\" appears to use leap seconds",
438 return false;
439 }
440
441
442
443
445 if (!*extra)
446 return false;
447 *((pg_tz **) *extra) = new_tz;
448
449 return true;
450}
451
452
453
454
455void
457{
459}
460
461
462
463
464const char *
466{
467 const char *tzn;
468
469
471
472 if (tzn != NULL)
473 return tzn;
474
475 return "unknown";
476}
477
478
479
480
481
482
483
484
485
486bool
488{
489
490
491
492
493
494
495
496
497
498
500 {
502 return true;
503 }
504
505
507
508
509 if (!*extra)
510 return false;
511
512 return true;
513}
514
515
516
517
518void
520{
521
522 if (!extra)
523 return;
524
526}
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545bool
547{
549 {
550
552 {
554 GUC_check_errmsg("cannot set transaction read-write mode inside a read-only transaction");
555 return false;
556 }
557
559 {
561 GUC_check_errmsg("transaction read-write mode must be set before any query");
562 return false;
563 }
564
566 {
568 GUC_check_errmsg("cannot set transaction read-write mode during recovery");
569 return false;
570 }
571 }
572
573 return true;
574}
575
576
577
578
579
580
581
582
583
584
585bool
587{
588 int newXactIsoLevel = *newval;
589
592 {
594 {
596 GUC_check_errmsg("SET TRANSACTION ISOLATION LEVEL must be called before any query");
597 return false;
598 }
599
601 {
603 GUC_check_errmsg("SET TRANSACTION ISOLATION LEVEL must not be called in a subtransaction");
604 return false;
605 }
606
608 {
610 GUC_check_errmsg("cannot use serializable mode in a hot standby");
612 return false;
613 }
614 }
615
616 return true;
617}
618
619
620
621
622
623bool
625{
626
628 return true;
629
631 {
633 GUC_check_errmsg("SET TRANSACTION [NOT] DEFERRABLE cannot be called within a subtransaction");
634 return false;
635 }
637 {
639 GUC_check_errmsg("SET TRANSACTION [NOT] DEFERRABLE must be called before any query");
640 return false;
641 }
642
643 return true;
644}
645
646
647
648
649
650
651
652
653
654
655bool
657{
659 if (!*extra)
660 return false;
661
663
664 return true;
665}
666
667void
669{
670
671 if (*((int *) extra))
673 *((int *) extra) = 0;
674}
675
676const char *
678{
679 return "unavailable";
680}
681
682
683
684
685
686
687bool
689{
691 const char *canonical_name;
692
693
696 return false;
697
698
700
701
702
703
704
705
706
707
708
709
710
711
713 {
715 GUC_check_errdetail("Cannot change \"client_encoding\" during a parallel operation.");
716 return false;
717 }
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
738 {
740 {
741
744 canonical_name,
746 }
747 else
748 {
749
751 }
752 return false;
753 }
754
755
756
757
758
759
760
761
762
763
764
765 if (strcmp(*newval, canonical_name) != 0 &&
766 strcmp(*newval, "UNICODE") != 0)
767 {
771 return false;
772 }
773
774
775
776
778 if (!*extra)
779 return false;
780 *((int *) *extra) = encoding;
781
782 return true;
783}
784
785void
787{
788 int encoding = *((int *) extra);
789
790
791
792
793
795 return;
796
797
800}
801
802
803
804
805
806
807typedef struct
808{
809
813
814bool
816{
819 Oid roleid;
822
823
825 return true;
826
828 {
829
830
831
832
833
836 }
837 else
838 {
840 {
841
842
843
844
845
846
847 return false;
848 }
849
850
851
852
853
854
855
856
859 {
861 {
863 (errcode(ERRCODE_UNDEFINED_OBJECT),
864 errmsg("role \"%s\" does not exist", *newval)));
865 return true;
866 }
868 return false;
869 }
870
872 roleid = roleform->oid;
874
876
877
878
879
880
881
884 {
886 {
888 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
889 errmsg("permission will be denied to set session authorization \"%s\"",
891 return true;
892 }
894 GUC_check_errmsg("permission denied to set session authorization \"%s\"",
896 return false;
897 }
898 }
899
900
902 if (!myextra)
903 return false;
904 myextra->roleid = roleid;
906 *extra = myextra;
907
908 return true;
909}
910
911void
913{
915
916
917 if (!myextra)
918 return;
919
921}
922
923
924
925
926
927
928
929
930
931
932bool
934{
936 Oid roleid;
940
941 if (strcmp(*newval, "none") == 0)
942 {
943
946 }
948 {
949
950
951
952
953
956 }
957 else
958 {
960 {
961
962
963
964
965
966 return false;
967 }
968
969
970
971
972
973
974
975
978 {
980 {
982 (errcode(ERRCODE_UNDEFINED_OBJECT),
983 errmsg("role \"%s\" does not exist", *newval)));
984 return true;
985 }
987 return false;
988 }
989
991 roleid = roleform->oid;
993
995
996
998 {
1000 {
1002 (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
1003 errmsg("permission will be denied to set role \"%s\"",
1005 return true;
1006 }
1010 return false;
1011 }
1012 }
1013
1014
1016 if (!myextra)
1017 return false;
1018 myextra->roleid = roleid;
1020 *extra = myextra;
1021
1022 return true;
1023}
1024
1025void
1027{
1029
1031}
1032
1033const char *
1035{
1036
1037
1038
1039
1040
1041
1042
1044 return "none";
1045
1046
1048}
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058bool
1060{
1061
1062
1063
1064
1065
1068 return true;
1069}
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079bool
1081{
1082 char *clean;
1083 char *ret;
1084
1085
1087 if (!clean)
1088 return false;
1089
1091 if (!ret)
1092 {
1094 return false;
1095 }
1096
1098
1101 return true;
1102}
1103
1104
1105
1106
1107void
1109{
1110
1112}
1113
1114
1115
1116
1117bool
1119{
1120 char *clean;
1121 char *ret;
1122
1123
1125 if (!clean)
1126 return false;
1127
1129 if (!ret)
1130 {
1132 return false;
1133 }
1134
1136
1139 return true;
1140}
1141
1142
1143
1144
1145void
1147{
1148
1149
1150
1151
1155}
1156
1157
1158
1159
1160
1161
1162
1163void
1165{
1167}
1168void
1170{
1172}
1173
1174
1175
1176
1177
1178
1179
1180
1181const char *
1183{
1184 static char buf[12];
1185
1187 return buf;
1188}
1189
1190
1191
1192
1193const char *
1195{
1196 static char buf[12];
1197
1199 return buf;
1200}
1201
1202
1203
1204
1205const char *
1207{
1208 static char buf[12];
1209
1211 return buf;
1212}
1213
1214
1215
1216
1217
1218
1219
1220bool
1222{
1223#ifndef USE_BONJOUR
1225 {
1227 return false;
1228 }
1229#endif
1230 return true;
1231}
1232
1233bool
1235{
1237 {
1238
1240 GUC_check_errmsg("tables declared WITH OIDS are not supported");
1241
1242 return false;
1243 }
1244
1245 return true;
1246}
1247
1248bool
1250{
1251#ifndef USE_SSL
1253 {
1255 return false;
1256 }
1257#endif
1258 return true;
1259}
bool member_can_set_role(Oid member, Oid role)
bool InitializingParallelWorker
void assign_application_name(const char *newval, void *extra)
bool check_bonjour(bool *newval, void **extra, GucSource source)
void assign_io_combine_limit(int newval, void *extra)
void assign_session_authorization(const char *newval, void *extra)
bool check_transaction_deferrable(bool *newval, void **extra, GucSource source)
bool check_canonical_path(char **newval, void **extra, GucSource source)
bool check_transaction_isolation(int *newval, void **extra, GucSource source)
bool check_default_with_oids(bool *newval, void **extra, GucSource source)
void assign_timezone_abbreviations(const char *newval, void *extra)
bool check_application_name(char **newval, void **extra, GucSource source)
void assign_timezone(const char *newval, void *extra)
bool check_role(char **newval, void **extra, GucSource source)
bool check_cluster_name(char **newval, void **extra, GucSource source)
const char * show_random_seed(void)
void assign_io_max_combine_limit(int newval, void *extra)
bool check_session_authorization(char **newval, void **extra, GucSource source)
const char * show_log_file_mode(void)
bool check_transaction_read_only(bool *newval, void **extra, GucSource source)
void assign_maintenance_io_concurrency(int newval, void *extra)
bool check_timezone_abbreviations(char **newval, void **extra, GucSource source)
const char * show_log_timezone(void)
void assign_client_encoding(const char *newval, void *extra)
void assign_role(const char *newval, void *extra)
bool check_timezone(char **newval, void **extra, GucSource source)
bool check_ssl(bool *newval, void **extra, GucSource source)
void assign_datestyle(const char *newval, void *extra)
void assign_random_seed(double newval, void *extra)
const char * show_role(void)
bool check_log_timezone(char **newval, void **extra, GucSource source)
bool check_random_seed(double *newval, void **extra, GucSource source)
const char * show_unix_socket_permissions(void)
const char * show_timezone(void)
bool check_datestyle(char **newval, void **extra, GucSource source)
bool check_client_encoding(char **newval, void **extra, GucSource source)
const char * show_data_directory_mode(void)
void assign_log_timezone(const char *newval, void *extra)
void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl)
void ClearTimeZoneAbbrevCache(void)
Datum interval_in(PG_FUNCTION_ARGS)
void pgstat_report_appname(const char *appname)
int maintenance_io_concurrency
#define OidIsValid(objectId)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
int pg_valid_client_encoding(const char *name)
#define MCXT_ALLOC_NO_OOM
Datum Float8GetDatum(float8 X)
#define DirectFunctionCall1(func, arg1)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
void GUC_check_errcode(int sqlerrcode)
void * guc_malloc(int elevel, size_t size)
const char * GetConfigOptionResetString(const char *name)
char * guc_strdup(int elevel, const char *src)
#define GUC_check_errdetail
#define GUC_check_errhint
bool current_role_is_superuser
Assert(PointerIsAligned(start, uint64))
#define HeapTupleIsValid(tuple)
static void * GETSTRUCT(const HeapTupleData *tuple)
#define IsParallelWorker()
void list_free(List *list)
const char * GetDatabaseEncodingName(void)
int SetClientEncoding(int encoding)
int PrepareClientEncoding(int encoding)
char * pstrdup(const char *in)
void pfree(void *pointer)
#define AmStartupProcess()
#define USE_POSTGRES_DATES
void SetSessionAuthorization(Oid userid, bool is_superuser)
bool GetSessionUserIsSuperuser(void)
Oid GetSessionUserId(void)
void SetCurrentRoleId(Oid roleid, bool is_superuser)
Oid GetAuthenticatedUserId(void)
Oid GetCurrentRoleId(void)
FormData_pg_authid * Form_pg_authid
static bool is_superuser(Archive *fout)
static rewind_source * source
#define pg_encoding_to_char
pg_tz * pg_tzset_offset(long gmtoffset)
bool pg_tz_acceptable(pg_tz *tz)
const char * pg_get_timezone_name(pg_tz *tz)
pg_tz * pg_tzset(const char *tzname)
PGDLLIMPORT pg_tz * session_timezone
PGDLLIMPORT pg_tz * log_timezone
int pg_strcasecmp(const char *s1, const char *s2)
void canonicalize_path(char *path)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
static Datum PointerGetDatum(const void *X)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
int Unix_socket_permissions
Datum setseed(PG_FUNCTION_ARGS)
char * pg_clean_ascii(const char *str, int alloc_flags)
bool superuser_arg(Oid roleid)
void ReleaseSysCache(HeapTuple tuple)
HeapTuple SearchSysCache1(int cacheId, Datum key1)
TimeZoneAbbrevTable * load_tzoffsets(const char *filename)
static Interval * DatumGetIntervalP(Datum X)
bool SplitIdentifierString(char *rawstring, char separator, List **namelist)
bool IsTransactionState(void)
bool IsSubTransaction(void)
#define XACT_SERIALIZABLE
bool RecoveryInProgress(void)
void XLogPrefetchReconfigure(void)