| 500 | } |
| 501 | |
| 502 | static Datum |
| 503 | pg_logdir_ls_internal(FunctionCallInfo fcinfo) |
| 504 | { |
| 505 | ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo; |
| 506 | bool randomAccess; |
| 507 | TupleDesc tupdesc; |
| 508 | Tuplestorestate *tupstore; |
| 509 | AttInMetadata *attinmeta; |
| 510 | DIR *dirdesc; |
| 511 | struct dirent *de; |
| 512 | MemoryContext oldcontext; |
| 513 | |
| 514 | if (strcmp(Log_filename, "postgresql-%Y-%m-%d_%H%M%S.log") != 0) |
| 515 | ereport(ERROR, |
| 516 | (errcode(ERRCODE_INVALID_PARAMETER_VALUE), |
| 517 | errmsg("the log_filename parameter must equal 'postgresql-%%Y-%%m-%%d_%%H%%M%%S.log'"))); |
| 518 | |
| 519 | /* check to see if caller supports us returning a tuplestore */ |
| 520 | if (rsinfo == NULL || !IsA(rsinfo, ReturnSetInfo)) |
| 521 | ereport(ERROR, |
| 522 | (errcode(ERRCODE_FEATURE_NOT_SUPPORTED), |
| 523 | errmsg("set-valued function called in context that cannot accept a set"))); |
| 524 | if (!(rsinfo->allowedModes & SFRM_Materialize)) |
| 525 | ereport(ERROR, |
| 526 | (errcode(ERRCODE_SYNTAX_ERROR), |
| 527 | errmsg("materialize mode required, but it is not allowed in this context"))); |
| 528 | |
| 529 | /* The tupdesc and tuplestore must be created in ecxt_per_query_memory */ |
| 530 | oldcontext = MemoryContextSwitchTo(rsinfo->econtext->ecxt_per_query_memory); |
| 531 | |
| 532 | tupdesc = CreateTemplateTupleDesc(2); |
| 533 | TupleDescInitEntry(tupdesc, (AttrNumber) 1, "starttime", |
| 534 | TIMESTAMPOID, -1, 0); |
| 535 | TupleDescInitEntry(tupdesc, (AttrNumber) 2, "filename", |
| 536 | TEXTOID, -1, 0); |
| 537 | |
| 538 | randomAccess = (rsinfo->allowedModes & SFRM_Materialize_Random) != 0; |
| 539 | tupstore = tuplestore_begin_heap(randomAccess, false, work_mem); |
| 540 | rsinfo->returnMode = SFRM_Materialize; |
| 541 | rsinfo->setResult = tupstore; |
| 542 | rsinfo->setDesc = tupdesc; |
| 543 | |
| 544 | MemoryContextSwitchTo(oldcontext); |
| 545 | |
| 546 | attinmeta = TupleDescGetAttInMetadata(tupdesc); |
| 547 | |
| 548 | dirdesc = AllocateDir(Log_directory); |
| 549 | while ((de = ReadDir(dirdesc, Log_directory)) != NULL) |
| 550 | { |
| 551 | char *values[2]; |
| 552 | HeapTuple tuple; |
| 553 | char timestampbuf[32]; |
| 554 | char *field[MAXDATEFIELDS]; |
| 555 | char lowstr[MAXDATELEN + 1]; |
| 556 | int dtype; |
| 557 | int nf, |
| 558 | ftype[MAXDATEFIELDS]; |
| 559 | fsec_t fsec; |
no test coverage detected