PGROUTING  3.2
bridges.c File Reference
Include dependency graph for bridges.c:

Go to the source code of this file.

Functions

PGDLLEXPORT Datum _pgr_bridges (PG_FUNCTION_ARGS)
 
 PG_FUNCTION_INFO_V1 (_pgr_bridges)
 
static void process (char *edges_sql, int64_t **result_tuples, size_t *result_count)
 

Function Documentation

◆ _pgr_bridges()

PGDLLEXPORT Datum _pgr_bridges ( PG_FUNCTION_ARGS  )

Definition at line 98 of file bridges.c.

98  {
99  FuncCallContext *funcctx;
100  TupleDesc tuple_desc;
101 
102  int64_t *result_tuples = NULL;
103  size_t result_count = 0;
104 
105  if (SRF_IS_FIRSTCALL()) {
106  MemoryContext oldcontext;
107  funcctx = SRF_FIRSTCALL_INIT();
108  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
109 
110  process(
111  text_to_cstring(PG_GETARG_TEXT_P(0)),
112  &result_tuples,
113  &result_count);
114 
115 
116 #if PGSQL_VERSION > 94
117  funcctx->max_calls = (uint32_t)result_count;
118 #else
119  funcctx->max_calls = (uint32_t)result_count;
120 #endif
121  funcctx->user_fctx = result_tuples;
122  if (get_call_result_type(fcinfo, NULL, &tuple_desc)
123  != TYPEFUNC_COMPOSITE) {
124  ereport(ERROR,
125  (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
126  errmsg("function returning record called in context "
127  "that cannot accept type record")));
128  }
129 
130  funcctx->tuple_desc = tuple_desc;
131  MemoryContextSwitchTo(oldcontext);
132  }
133 
134  funcctx = SRF_PERCALL_SETUP();
135  tuple_desc = funcctx->tuple_desc;
136  result_tuples = (int64_t*) funcctx->user_fctx;
137 
138  if (funcctx->call_cntr < funcctx->max_calls) {
139  HeapTuple tuple;
140  Datum result;
141  Datum *values;
142  bool* nulls;
143 
144 
145  values = palloc(2 * sizeof(Datum));
146  nulls = palloc(2 * sizeof(bool));
147 
148 
149  size_t i;
150  for (i = 0; i < 2; ++i) {
151  nulls[i] = false;
152  }
153 
154  values[0] = Int32GetDatum(funcctx->call_cntr + 1);
155  values[1] = Int64GetDatum(result_tuples[funcctx->call_cntr]);
156 
157  tuple = heap_form_tuple(tuple_desc, values, nulls);
158  result = HeapTupleGetDatum(tuple);
159  SRF_RETURN_NEXT(funcctx, result);
160  } else {
161  SRF_RETURN_DONE(funcctx);
162  }
163 }

References if(), and process().

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( _pgr_bridges  )

◆ process()

static void process ( char *  edges_sql,
int64_t **  result_tuples,
size_t *  result_count 
)
static

Definition at line 50 of file bridges.c.

53  {
55 
56  (*result_tuples) = NULL;
57  (*result_count) = 0;
58 
59  pgr_edge_t *edges = NULL;
60  size_t total_edges = 0;
61 
62  pgr_get_edges(edges_sql, &edges, &total_edges);
63 
64  if (total_edges == 0) {
66  return;
67  }
68 
69  clock_t start_t = clock();
70  char *log_msg = NULL;
71  char *notice_msg = NULL;
72  char *err_msg = NULL;
74  edges,
75  total_edges,
76 
77  result_tuples,
78  result_count,
79  &log_msg,
80  &notice_msg,
81  &err_msg);
82 
83  time_msg(" processing pgr_bridges", start_t, clock());
84 
85  if (err_msg) {
86  if (*result_tuples) pfree(*result_tuples);
87  }
88  pgr_global_report(log_msg, notice_msg, err_msg);
89 
90  if (edges) pfree(edges);
91  if (log_msg) pfree(log_msg);
92  if (notice_msg) pfree(notice_msg);
93  if (err_msg) pfree(err_msg);
94 
96 }

References do_pgr_bridges(), pgr_get_edges(), pgr_global_report(), pgr_SPI_connect(), pgr_SPI_finish(), and time_msg().

Referenced by _pgr_bridges().

pgr_edge_t
Definition: pgr_edge_t.h:37
pgr_SPI_connect
void pgr_SPI_connect(void)
Definition: postgres_connection.c:82
pgr_SPI_finish
void pgr_SPI_finish(void)
Definition: postgres_connection.c:71
do_pgr_bridges
void do_pgr_bridges(pgr_edge_t *data_edges, size_t total_edges, int64_t **return_tuples, size_t *return_count, char **log_msg, char **notice_msg, char **err_msg)
Definition: bridges_driver.cpp:44
pgr_get_edges
void pgr_get_edges(char *edges_sql, pgr_edge_t **edges, size_t *total_edges)
basic edge_sql
Definition: edges_input.c:711
process
static void process(char *edges_sql, int64_t **result_tuples, size_t *result_count)
Definition: bridges.c:50
if
if(DOXYGEN_FOUND) configure_file($
Definition: doxygen/CMakeLists.txt:13
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
pgr_global_report
void pgr_global_report(char *log, char *notice, char *err)
notice & error
Definition: e_report.c:93