PGROUTING  3.2
get_check_data.c File Reference
#include <stdbool.h>
#include "c_common/postgres_connection.h"
#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

◆ column_found()

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 36 of file get_check_data.c.

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

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

◆ fetch_column_info()

static bool fetch_column_info ( Column_info_t info)
static

Definition at line 45 of file get_check_data.c.

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

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().

◆ pgr_check_any_integer_type()

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 127 of file get_check_data.c.

127  {
128  if (!(info.type == INT2OID
129  || info.type == INT4OID
130  || info.type == INT8OID)) {
131  elog(ERROR,
132  "Unexpected Column '%s' type. Expected ANY-INTEGER",
133  info.name);
134  }
135 }

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

Referenced by pgr_fetch_column_info().

◆ pgr_check_any_integerarray_type()

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 138 of file get_check_data.c.

138  {
139  if (!(info.type == INT2ARRAYOID
140  || info.type == INT4ARRAYOID
141  || info.type == 1016)) {
142  elog(ERROR,
143  "Unexpected Column '%s' type. Expected ANY-INTEGER-ARRAY",
144  info.name);
145  }
146 }

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

Referenced by pgr_fetch_column_info().

◆ pgr_check_any_numerical_type()

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 148 of file get_check_data.c.

148  {
149  if (!(info.type == INT2OID
150  || info.type == INT4OID
151  || info.type == INT8OID
152  || info.type == FLOAT4OID
153  || info.type == FLOAT8OID
154  || info.type == NUMERICOID)) {
155  elog(ERROR,
156  "Unexpected Column '%s' type. Expected ANY-NUMERICAL",
157  info.name);
158  }
159 }

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

Referenced by pgr_fetch_column_info().

◆ pgr_check_char_type()

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 113 of file get_check_data.c.

113  {
114  if (!(info.type == BPCHAROID)) {
115  elog(ERROR, "Unexpected Column '%s' type. Expected CHAR", info.name);
116  }
117 }

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

Referenced by pgr_fetch_column_info().

◆ pgr_check_text_type()

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 120 of file get_check_data.c.

120  {
121  if (!(info.type == TEXTOID)) {
122  elog(ERROR, "Unexpected Column '%s' type. Expected TEXT", info.name);
123  }
124 }

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

Referenced by pgr_fetch_column_info().

◆ 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.

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 78 of file get_check_data.c.

80  {
81  int i;
82  for (i = 0; i < info_size; ++i) {
83  if (fetch_column_info(&info[i])) {
84  switch (info[i].eType) {
85  case ANY_INTEGER:
87  break;
88  case ANY_NUMERICAL:
90  break;
91  case TEXT:
92  pgr_check_text_type(info[i]);
93  break;
94  case CHAR1:
95  pgr_check_char_type(info[i]);
96  break;
97  case ANY_INTEGER_ARRAY:
99  break;
100  default:
101  elog(ERROR, "Unknown type of column %s", info[i].name);
102  }
103  }
104  }
105 }

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_combinations_2_columns(), get_edges_5_columns(), get_edges_9_columns(), get_edges_basic(), get_edges_costFlow(), get_edges_flow(), pgr_get_coordinates(), pgr_get_delauny(), pgr_get_matrixRows(), pgr_get_pd_orders_general(), pgr_get_points(), pgr_get_restrictions(), pgr_get_vehicles_general(), and pgr_point_input().

◆ pgr_SPI_getBigInt()

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 216 of file get_check_data.c.

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

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

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

◆ pgr_SPI_getBigIntArr()

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 196 of file get_check_data.c.

200  {
201  bool is_null = false;
202 
203  Datum raw_array = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &is_null);
204  /*
205  * [DatumGetArrayTypeP](https://doxygen.postgresql.org/array_8h.html#aa1b8e77c103863862e06a7b7c07ec532)
206  * [pgr_get_bigIntArray](http://docs.pgrouting.org/doxy/2.2/arrays__input_8c_source.html)
207  */
208  ArrayType *pg_array = DatumGetArrayTypeP(raw_array);
209 
210  return pgr_get_bigIntArray((size_t*)the_size, pg_array);
211 }

References Column_info_t::colNumber, and pgr_get_bigIntArray().

Referenced by fetch_restriction().

◆ pgr_SPI_getChar()

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 170 of file get_check_data.c.

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

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

Referenced by fetch_point().

◆ pgr_SPI_getFloat8()

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 246 of file get_check_data.c.

246  {
247  Datum binval;
248  bool isnull = false;
249  double value = 0.0;
250  binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isnull);
251  if (isnull)
252  elog(ERROR, "Unexpected Null value in column %s", info.name);
253 
254  switch (info.type) {
255  case INT2OID:
256  value = (double) DatumGetInt16(binval);
257  break;
258  case INT4OID:
259  value = (double) DatumGetInt32(binval);
260  break;
261  case INT8OID:
262  value = (double) DatumGetInt64(binval);
263  break;
264  case FLOAT4OID:
265  value = (double) DatumGetFloat4(binval);
266  break;
267  case FLOAT8OID:
268  value = DatumGetFloat8(binval);
269  break;
270  case NUMERICOID:
271  /* Note: out-of-range values will be clamped to +-HUGE_VAL */
272  value = (double) DatumGetFloat8(DirectFunctionCall1(numeric_float8_no_overflow, binval));
273  break;
274  default:
275  elog(ERROR,
276  "Unexpected Column type of %s. Expected ANY-NUMERICAL",
277  info.name);
278  }
279 /* TODO(vicky) Remove unused code */
280 #if 0
281  PGR_DBG("Variable: %s Value: %.20f", info.name, value);
282 #endif
283  return value;
284 }

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

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

◆ pgr_SPI_getText()

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 293 of file get_check_data.c.

293  {
294  return DatumGetCString(SPI_getvalue(*tuple, *tupdesc, info.colNumber));
295 }

References Column_info_t::colNumber.

Column_info_t::colNumber
int colNumber
Definition: column_info_t.h:51
fetch_column_info
static bool fetch_column_info(Column_info_t *info)
Definition: get_check_data.c:45
pgr_check_any_integer_type
void pgr_check_any_integer_type(Column_info_t info)
The function check whether column type is ANY-INTEGER or not.
Definition: get_check_data.c:127
Column_info_t::strict
bool strict
Definition: column_info_t.h:53
TEXT
@ TEXT
Definition: column_info_t.h:43
pgr_check_char_type
void pgr_check_char_type(Column_info_t info)
The function check whether column type is CHAR or not.
Definition: get_check_data.c:113
pgr_get_bigIntArray
int64_t * pgr_get_bigIntArray(size_t *arrlen, ArrayType *input)
Enforces the input array to be NOT empty.
Definition: arrays_input.c:146
pgr_check_text_type
void pgr_check_text_type(Column_info_t info)
The function check whether column type is TEXT or not.
Definition: get_check_data.c:120
Column_info_t::name
char * name
Definition: column_info_t.h:54
PGR_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34
pgr_check_any_integerarray_type
void pgr_check_any_integerarray_type(Column_info_t info)
The function check whether column type is ANY-INTEGER-ARRAY or not.
Definition: get_check_data.c:138
ANY_INTEGER_ARRAY
@ ANY_INTEGER_ARRAY
Definition: column_info_t.h:45
pgr_check_any_numerical_type
void pgr_check_any_numerical_type(Column_info_t info)
The function check whether column type is ANY-NUMERICAL.
Definition: get_check_data.c:148
ANY_INTEGER
@ ANY_INTEGER
Definition: column_info_t.h:41
ANY_NUMERICAL
@ ANY_NUMERICAL
Definition: column_info_t.h:42
column_found
bool column_found(int colNumber)
Function will check whether the colNumber represent any specific column or NULL (SPI_ERROR_NOATTRIBUT...
Definition: get_check_data.c:36
Column_info_t::type
uint64_t type
Definition: column_info_t.h:52
CHAR1
@ CHAR1
Definition: column_info_t.h:44