PGROUTING  3.2
pgr_point_input.h File Reference
#include <stddef.h>
#include "c_types/pgr_point_t.h"
Include dependency graph for pgr_point_input.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void pgr_point_input (char *points_sql, Pgr_point_t **points, size_t *pointsTotal)
 pgr_point_input More...
 

Function Documentation

◆ pgr_point_input()

void pgr_point_input ( char *  points_sql,
Pgr_point_t **  points,
size_t *  pointsTotal 
)

pgr_point_input

For queries of the type:

SELECT x, y
FROM ...
Parameters
[in]points_sql
[out]points
[out]pointsTotalpgr_point_input

Definition at line 48 of file pgr_point_input.c.

51  {
52  clock_t start_t = clock();
53 
54  const int tuple_limit = 1000000;
55 
56  size_t total_tuples = 0;
57 
58  Column_info_t info[3];
59 
60  int i;
61  for (i = 0; i < 2; ++i) {
62  info[i].colNumber = -1;
63  info[i].type = 0;
64  info[i].strict = true;
65  info[i].eType = ANY_NUMERICAL;
66  }
67  info[0].name = "x";
68  info[1].name = "y";
69 
70 
71  void *SPIplan;
72  SPIplan = pgr_SPI_prepare(points_sql);
73 
74  Portal SPIportal;
75  SPIportal = pgr_SPI_cursor_open(SPIplan);
76 
77 
78  bool moredata = true;
79  (*pointsTotal) = total_tuples;
80 
81  while (moredata == true) {
82  SPI_cursor_fetch(SPIportal, true, tuple_limit);
83  if (total_tuples == 0)
84  pgr_fetch_column_info(info, 2);
85 
86  size_t ntuples = SPI_processed;
87  total_tuples += ntuples;
88 
89  if (ntuples > 0) {
90  if ((*points) == NULL)
91  (*points) = (Pgr_point_t *)
92  palloc0(total_tuples * sizeof(Pgr_point_t));
93  else
94  (*points) = (Pgr_point_t *)
95  repalloc((*points),
96  total_tuples * sizeof(Pgr_point_t));
97 
98  if ((*points) == NULL) {
99  elog(ERROR, "Out of memory");
100  }
101 
102  SPITupleTable *tuptable = SPI_tuptable;
103  TupleDesc tupdesc = SPI_tuptable->tupdesc;
104 
105  size_t t;
106  for (t = 0; t < ntuples; t++) {
107  HeapTuple tuple = tuptable->vals[t];
108  pgr_fetch_row(&tuple, &tupdesc, info,
109  &(*points)[total_tuples - ntuples + t]);
110  }
111  SPI_freetuptable(tuptable);
112  } else {
113  moredata = false;
114  }
115  }
116 
117  SPI_cursor_close(SPIportal);
118 
119 
120  if (total_tuples == 0) {
121  (*pointsTotal) = 0;
122  return;
123  }
124 
125  (*pointsTotal) = total_tuples;
126  time_msg(" reading points:", start_t, clock());
127 }

References ANY_NUMERICAL, Column_info_t::colNumber, Column_info_t::eType, Column_info_t::name, pgr_fetch_column_info(), pgr_fetch_row(), pgr_SPI_cursor_open(), pgr_SPI_prepare(), Column_info_t::strict, time_msg(), and Column_info_t::type.

Column_info_t::colNumber
int colNumber
Definition: column_info_t.h:51
pgr_fetch_row
static void pgr_fetch_row(HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info[2], Pgr_point_t *point)
Definition: pgr_point_input.c:34
Column_info_t::strict
bool strict
Definition: column_info_t.h:53
pgr_SPI_prepare
SPIPlanPtr pgr_SPI_prepare(char *sql)
Definition: postgres_connection.c:94
pgr_fetch_column_info
void pgr_fetch_column_info(Column_info_t info[], int info_size)
Function tells expected type of each column and then check the correspondence type of each column.
Definition: get_check_data.c:78
Column_info_t::name
char * name
Definition: column_info_t.h:54
pgr_SPI_cursor_open
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
Definition: postgres_connection.c:107
Column_info_t::eType
expectType eType
Definition: column_info_t.h:55
time_msg
void time_msg(char *msg, clock_t start_t, clock_t end_t)
Definition: time_msg.c:32
ANY_NUMERICAL
@ ANY_NUMERICAL
Definition: column_info_t.h:42
Pgr_point_t
Definition: pgr_point_t.h:30
Column_info_t::type
uint64_t type
Definition: column_info_t.h:52
Column_info_t
Definition: column_info_t.h:49