PGROUTING  2.6
get_check_data.c File Reference
#include "c_common/get_check_data.h"
#include "c_common/arrays_input.h"
#include "catalog/pg_type.h"
#include "c_common/debug_macro.h"
Include dependency graph for get_check_data.c:

Go to the source code of this file.

Functions

bool column_found (int colNumber)
 Function will check whether the colNumber represent any specific column or NULL (SPI_ERROR_NOATTRIBUTE). More...
 
static bool fetch_column_info (Column_info_t *info)
 
void pgr_check_any_integer_type (Column_info_t info)
 The function check whether column type is ANY-INTEGER or not. More...
 
void pgr_check_any_integerarray_type (Column_info_t info)
 The function check whether column type is ANY-INTEGER-ARRAY or not. More...
 
void pgr_check_any_numerical_type (Column_info_t info)
 The function check whether column type is ANY-NUMERICAL. More...
 
void pgr_check_char_type (Column_info_t info)
 The function check whether column type is CHAR or not. More...
 
void pgr_check_text_type (Column_info_t info)
 The function check whether column type is TEXT or not. More...
 
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. More...
 
int64_t pgr_SPI_getBigInt (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
 Function returns the value of specified column in integer type. More...
 
int64_t * pgr_SPI_getBigIntArr (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, uint64_t *the_size)
 Function returns the values of specified columns in array. More...
 
char pgr_SPI_getChar (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, bool strict, char default_value)
 Function return the value of specified column in char type. More...
 
double pgr_SPI_getFloat8 (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
 Function returns the value of specified column in double type. More...
 
char * pgr_SPI_getText (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
 under development More...
 

Function Documentation

bool column_found ( int  colNumber)

Function will check whether the colNumber represent any specific column or NULL (SPI_ERROR_NOATTRIBUTE).

Parameters
[in]colNumberColumn number (count starts at 1).
Returns
TRUE when colNumber exist. FALSE when colNumber was not found.

Definition at line 34 of file get_check_data.c.

Referenced by fetch_basic_edge(), fetch_column_info(), fetch_edge(), fetch_edge_with_xy(), fetch_pd_orders(), fetch_point(), fetch_vehicles(), and pgr_fetch_row().

34  {
35  /*
36  * [SPI_ERROR_NOATTRIBUTE](https://doxygen.postgresql.org/spi_8h.html#ac1512d8aaa23c2d57bb0d1eb8f453ee2)
37  */
38  return !(colNumber == SPI_ERROR_NOATTRIBUTE);
39 }

Here is the caller graph for this function:

static bool fetch_column_info ( Column_info_t info)
static

Definition at line 43 of file get_check_data.c.

References Column_info_t::colNumber, column_found(), Column_info_t::name, PGR_DBG, Column_info_t::strict, and Column_info_t::type.

Referenced by pgr_fetch_column_info().

44  {
45 /* TODO(vicky) Remove unused code */
46 #if 0
47  PGR_DBG("Fetching column info of %s", info->name);
48 #endif
49  /*
50  * [SPI_fnumber](https://www.postgresql.org/docs/8.2/static/spi-spi-fnumber.html)
51  */
52  info->colNumber = SPI_fnumber(SPI_tuptable->tupdesc, info->name);
53  if (info->strict && !column_found(info->colNumber)) {
54  elog(ERROR, "Column '%s' not Found", info->name);
55  }
56 
57  if (column_found(info->colNumber)) {
58  /*
59  * [SPI_gettypeid](https://www.postgresql.org/docs/9.1/static/spi-spi-gettypeid.html)
60  */
61  (info->type) = SPI_gettypeid(SPI_tuptable->tupdesc, (info->colNumber));
62  if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
63  elog(ERROR, "Type of column '%s' not Found", info->name);
64  }
65 /* TODO(vicky) Remove unused code */
66 #if 0
67  PGR_DBG("Column %s found: %lu", info->name, info->type);
68 #endif
69  return true;
70  }
71  PGR_DBG("Column %s not found", info->name);
72  return false;
73 }
#define PGR_DBG(...)
Definition: debug_macro.h:34
uint64_t type
Definition: column_info_t.h:73
bool column_found(int colNumber)
Function will check whether the colNumber represent any specific column or NULL (SPI_ERROR_NOATTRIBUT...

Here is the call graph for this function:

Here is the caller graph for this function:

void pgr_check_any_integer_type ( Column_info_t  info)

The function check whether column type is ANY-INTEGER or not.

Where ANY-INTEGER is SQL type: SMALLINT, INTEGER, BIGINT

Parameters
[in]infocontain column information.
Exceptions
ERRORUnexpected Column type. Expected column type is ANY-INTEGER.

Definition at line 125 of file get_check_data.c.

References Column_info_t::name, and Column_info_t::type.

Referenced by pgr_fetch_column_info().

125  {
126  if (!(info.type == INT2OID
127  || info.type == INT4OID
128  || info.type == INT8OID)) {
129  elog(ERROR,
130  "Unexpected Column '%s' type. Expected ANY-INTEGER",
131  info.name);
132  }
133 }
uint64_t type
Definition: column_info_t.h:73

Here is the caller graph for this function:

void pgr_check_any_integerarray_type ( Column_info_t  info)

The function check whether column type is ANY-INTEGER-ARRAY or not.

Where ANY-INTEGER-ARRAY is SQL type: SMALLINT[], INTEGER[], BIGINT[]

Parameters
[in]infocontain column information.
Exceptions
ERRORUnexpected Column type. Expected column type is ANY-INTEGER-ARRAY.

Definition at line 136 of file get_check_data.c.

References Column_info_t::name, and Column_info_t::type.

Referenced by pgr_fetch_column_info().

136  {
137  if (!(info.type == INT2ARRAYOID
138  || info.type == INT4ARRAYOID
139  || info.type == 1016)) {
140  elog(ERROR,
141  "Unexpected Column '%s' type. Expected ANY-INTEGER-ARRAY",
142  info.name);
143  }
144 }
uint64_t type
Definition: column_info_t.h:73

Here is the caller graph for this function:

void pgr_check_any_numerical_type ( Column_info_t  info)

The function check whether column type is ANY-NUMERICAL.

Where ANY-NUMERICAL is SQL type: SMALLINT, INTEGER, BIGINT, REAL, FLOAT

Parameters
[in]infocontain column information.
Exceptions
ERRORUnexpected Column type. Expected column type is ANY-NUMERICAL.

Definition at line 146 of file get_check_data.c.

References Column_info_t::name, and Column_info_t::type.

Referenced by pgr_fetch_column_info().

146  {
147  if (!(info.type == INT2OID
148  || info.type == INT4OID
149  || info.type == INT8OID
150  || info.type == FLOAT4OID
151  || info.type == FLOAT8OID)) {
152  elog(ERROR,
153  "Unexpected Column '%s' type. Expected ANY-NUMERICAL",
154  info.name);
155  }
156 }
uint64_t type
Definition: column_info_t.h:73

Here is the caller graph for this function:

void pgr_check_char_type ( Column_info_t  info)

The function check whether column type is CHAR or not.

Where CHAR is SQL type: CHARACTER

Parameters
[in]infocontain column information.
Exceptions
ERRORUnexpected Column type. Expected column type is CHAR.

Definition at line 111 of file get_check_data.c.

References Column_info_t::name, and Column_info_t::type.

Referenced by pgr_fetch_column_info().

111  {
112  if (!(info.type == BPCHAROID)) {
113  elog(ERROR, "Unexpected Column '%s' type. Expected CHAR", info.name);
114  }
115 }
uint64_t type
Definition: column_info_t.h:73

Here is the caller graph for this function:

void pgr_check_text_type ( Column_info_t  info)

The function check whether column type is TEXT or not.

Where TEXT is SQL type: TEXT

Parameters
[in]infocontain column information.
Exceptions
ERRORUnexpected Column type. Expected column type is TEXT.

Definition at line 118 of file get_check_data.c.

References Column_info_t::name, and Column_info_t::type.

Referenced by pgr_fetch_column_info().

118  {
119  if (!(info.type == TEXTOID)) {
120  elog(ERROR, "Unexpected Column '%s' type. Expected TEXT", info.name);
121  }
122 }
uint64_t type
Definition: column_info_t.h:73

Here is the caller graph for this function:

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.

Parameters
[in]info[]contain one or more column information.
[in]info_sizenumber of columns.
Exceptions
ERRORUnknown type of column.
Returns
NULL is always returned.

Definition at line 76 of file get_check_data.c.

References ANY_INTEGER, ANY_INTEGER_ARRAY, ANY_NUMERICAL, CHAR1, fetch_column_info(), pgr_check_any_integer_type(), pgr_check_any_integerarray_type(), pgr_check_any_numerical_type(), pgr_check_char_type(), pgr_check_text_type(), and TEXT.

Referenced by get_edges_5_columns(), get_edges_9_columns(), get_edges_basic(), get_edges_flow(), pgr_get_coordinates(), pgr_get_matrixRows(), pgr_get_pd_orders_general(), pgr_get_points(), pgr_get_restrictions(), and pgr_get_vehicles_general().

78  {
79  int i;
80  for (i = 0; i < info_size; ++i) {
81  if (fetch_column_info(&info[i])) {
82  switch (info[i].eType) {
83  case ANY_INTEGER:
85  break;
86  case ANY_NUMERICAL:
88  break;
89  case TEXT:
90  pgr_check_text_type(info[i]);
91  break;
92  case CHAR1:
93  pgr_check_char_type(info[i]);
94  break;
95  case ANY_INTEGER_ARRAY:
97  break;
98  default:
99  elog(ERROR, "Unknown type of column %s", info[i].name);
100  }
101  }
102  }
103 }
void pgr_check_text_type(Column_info_t info)
The function check whether column type is TEXT or not.
void pgr_check_any_numerical_type(Column_info_t info)
The function check whether column type is ANY-NUMERICAL.
void pgr_check_any_integer_type(Column_info_t info)
The function check whether column type is ANY-INTEGER or not.
void pgr_check_char_type(Column_info_t info)
The function check whether column type is CHAR or not.
static bool fetch_column_info(Column_info_t *info)
void pgr_check_any_integerarray_type(Column_info_t info)
The function check whether column type is ANY-INTEGER-ARRAY or not.

Here is the call graph for this function:

Here is the caller graph for this function:

int64_t pgr_SPI_getBigInt ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info 
)

Function returns the value of specified column in integer type.

Parameters
[in]tupleinput row to be examined.
[in]tupdescinput row description.
[in]infocontain column information.
Exceptions
ERRORUnexpected Column type. Expected column type is ANY-INTEGER.
ERRORWhen value of column is NULL.
Returns
Integer type of column value is returned.

Definition at line 213 of file get_check_data.c.

References Column_info_t::colNumber, Column_info_t::name, PGR_DBG, and Column_info_t::type.

Referenced by fetch_basic_edge(), fetch_edge(), fetch_edge_with_xy(), fetch_pd_orders(), fetch_point(), fetch_restriction(), fetch_vehicles(), and pgr_fetch_row().

213  {
214  Datum binval;
215  bool isnull;
216  int64_t value = 0;
217  binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isnull);
218  if (isnull)
219  elog(ERROR, "Unexpected Null value in column %s", info.name);
220  switch (info.type) {
221  case INT2OID:
222  value = (int64_t) DatumGetInt16(binval);
223  break;
224  case INT4OID:
225  value = (int64_t) DatumGetInt32(binval);
226  break;
227  case INT8OID:
228  value = DatumGetInt64(binval);
229  break;
230  default:
231  elog(ERROR,
232  "Unexpected Column type of %s. Expected ANY-INTEGER",
233  info.name);
234  }
235 /* TODO(vicky) Remove unused code */
236 #if 0
237  PGR_DBG("Variable: %s Value: %ld", info.name, value);
238 #endif
239  return value;
240 }
#define PGR_DBG(...)
Definition: debug_macro.h:34
uint64_t type
Definition: column_info_t.h:73

Here is the caller graph for this function:

int64_t* pgr_SPI_getBigIntArr ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info,
uint64_t *  the_size 
)

Function returns the values of specified columns in array.

Parameters
[in]tupleinput row to be examined.
[in]tupdescinput row description.
[in]infocontain column information.
[out]the_sizenumber of element in array.
Exceptions
ERRORNo elements found in ARRAY.
ERRORUnexpected Column type. Expected column type is ANY-INTEGER-ARRAY.
ERRORNULL value found in Array.
Returns
Array of columns value is returned.

Definition at line 193 of file get_check_data.c.

References Column_info_t::colNumber, and pgr_get_bigIntArray().

Referenced by fetch_restriction().

197  {
198  bool is_null = false;
199 
200  Datum raw_array = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &is_null);
201  /*
202  * [DatumGetArrayTypeP](https://doxygen.postgresql.org/array_8h.html#aa1b8e77c103863862e06a7b7c07ec532)
203  * [pgr_get_bigIntArray](http://docs.pgrouting.org/doxy/2.2/arrays__input_8c_source.html)
204  */
205  ArrayType *pg_array = DatumGetArrayTypeP(raw_array);
206 
207  return (int64_t*) pgr_get_bigIntArray(the_size, pg_array);
208 }
int64_t * pgr_get_bigIntArray(size_t *arrlen, ArrayType *input)
enforces the input array to be NOT empty
Definition: arrays_input.c:124

Here is the call graph for this function:

Here is the caller graph for this function:

char pgr_SPI_getChar ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info,
bool  strict,
char  default_value 
)

Function return the value of specified column in char type.

Parameters
[in]tupleinput row to be examined.
[in]tupdescinput row description.
[in]infocontain column information.
[in]strictboolean value of strict.
[in]default_valuereturned when column contain NULL value.
Exceptions
ERRORUnexpected Column type. Expected column type is CHAR.
ERRORWhen value of column is NULL.
Returns
Char type of column value is returned.

Definition at line 167 of file get_check_data.c.

References Column_info_t::colNumber, Column_info_t::name, and Column_info_t::type.

Referenced by fetch_point().

169  {
170  Datum binval;
171  bool isNull;
172  char value = default_value;
173 
174  binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isNull);
175  if (!(info.type == BPCHAROID)) {
176  elog(ERROR, "Unexpected Column type of %s. Expected CHAR", info.name);
177  }
178  if (!isNull) {
179  value = ((char*)binval)[1];
180  } else {
181  if (strict) {
182  elog(ERROR, "Unexpected Null value in column %s", info.name);
183  }
184  value = default_value;
185  }
186  return value;
187 }
uint64_t type
Definition: column_info_t.h:73

Here is the caller graph for this function:

double pgr_SPI_getFloat8 ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info 
)

Function returns the value of specified column in double type.

Parameters
[in]tupleinput row to be examined.
[in]tupdescinput row description.
[in]infocontain column information.
Exceptions
ERRORUnexpected Column type. Expected column type is ANY-NUMERICAL.
ERRORWhen value of column is NULL.
Returns
Double type of column value is returned.

Definition at line 243 of file get_check_data.c.

References Column_info_t::colNumber, Column_info_t::name, PGR_DBG, and Column_info_t::type.

Referenced by fetch_basic_edge(), fetch_edge(), fetch_edge_with_xy(), fetch_pd_orders(), fetch_point(), fetch_restriction(), fetch_vehicles(), and pgr_fetch_row().

243  {
244  Datum binval;
245  bool isnull = false;
246  double value = 0.0;
247  binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isnull);
248  if (isnull)
249  elog(ERROR, "Unexpected Null value in column %s", info.name);
250 
251  switch (info.type) {
252  case INT2OID:
253  value = (double) DatumGetInt16(binval);
254  break;
255  case INT4OID:
256  value = (double) DatumGetInt32(binval);
257  break;
258  case INT8OID:
259  value = (double) DatumGetInt64(binval);
260  break;
261  case FLOAT4OID:
262  value = (double) DatumGetFloat4(binval);
263  break;
264  case FLOAT8OID:
265  value = DatumGetFloat8(binval);
266  break;
267  default:
268  elog(ERROR,
269  "Unexpected Column type of %s. Expected ANY-NUMERICAL",
270  info.name);
271  }
272 /* TODO(vicky) Remove unused code */
273 #if 0
274  PGR_DBG("Variable: %s Value: %lf", info.name, value);
275 #endif
276  return value;
277 }
#define PGR_DBG(...)
Definition: debug_macro.h:34
uint64_t type
Definition: column_info_t.h:73

Here is the caller graph for this function:

char* pgr_SPI_getText ( HeapTuple *  tuple,
TupleDesc *  tupdesc,
Column_info_t  info 
)

under development

Function returns the string representation of the value of specified column.

Definition at line 286 of file get_check_data.c.

References Column_info_t::colNumber.

286  {
287  return DatumGetCString(SPI_getvalue(*tuple, *tupdesc, info.colNumber));
288 }