PGROUTING  2.6-dev
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)
 
static bool fetch_column_info (Column_info_t *info)
 
void pgr_check_any_integer_type (Column_info_t info)
 
void pgr_check_any_integerarray_type (Column_info_t info)
 
void pgr_check_any_numerical_type (Column_info_t info)
 
void pgr_check_char_type (Column_info_t info)
 
void pgr_check_text_type (Column_info_t info)
 
void pgr_fetch_column_info (Column_info_t info[], int info_size)
 
int64_t pgr_SPI_getBigInt (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
 
int64_t * pgr_SPI_getBigIntArr (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, uint64_t *the_size)
 
char pgr_SPI_getChar (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info, bool strict, char default_value)
 
double pgr_SPI_getFloat8 (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
 
char * pgr_SPI_getText (HeapTuple *tuple, TupleDesc *tupdesc, Column_info_t info)
 under development More...
 

Function Documentation

bool column_found ( int  colNumber)

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  return !(colNumber == SPI_ERROR_NOATTRIBUTE);
36 }

Here is the caller graph for this function:

static bool fetch_column_info ( Column_info_t info)
static

Definition at line 40 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().

41  {
42 #if 0
43  PGR_DBG("Fetching column info of %s", info->name);
44 #endif
45  info->colNumber = SPI_fnumber(SPI_tuptable->tupdesc, info->name);
46  if (info->strict && !column_found(info->colNumber)) {
47  elog(ERROR, "Column '%s' not Found", info->name);
48  }
49 
50  if (column_found(info->colNumber)) {
51  (info->type) = SPI_gettypeid(SPI_tuptable->tupdesc, (info->colNumber));
52  if (SPI_result == SPI_ERROR_NOATTRIBUTE) {
53  elog(ERROR, "Type of column '%s' not Found", info->name);
54  }
55 #if 0
56  PGR_DBG("Column %s found: %lu", info->name, info->type);
57 #endif
58  return true;
59  }
60  PGR_DBG("Column %s not found", info->name);
61  return false;
62 }
#define PGR_DBG(...)
Definition: debug_macro.h:34
uint64_t type
Definition: column_info_t.h:73
bool column_found(int colNumber)

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)

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 == INT2OID
113  || info.type == INT4OID
114  || info.type == INT8OID)) {
115  elog(ERROR,
116  "Unexpected Column '%s' type. Expected ANY-INTEGER",
117  info.name);
118  }
119 }
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)

Definition at line 122 of file get_check_data.c.

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

Referenced by pgr_fetch_column_info().

122  {
123  if (!(info.type == INT2ARRAYOID
124  || info.type == INT4ARRAYOID
125  || info.type == 1016)) {
126  elog(ERROR,
127  "Unexpected Column '%s' type. Expected ANY-INTEGER-ARRAY",
128  info.name);
129  }
130 }
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)

Definition at line 132 of file get_check_data.c.

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

Referenced by pgr_fetch_column_info().

132  {
133  if (!(info.type == INT2OID
134  || info.type == INT4OID
135  || info.type == INT8OID
136  || info.type == FLOAT4OID
137  || info.type == FLOAT8OID)) {
138  elog(ERROR,
139  "Unexpected Column '%s' type. Expected ANY-NUMERICAL",
140  info.name);
141  }
142 }
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)

Definition at line 97 of file get_check_data.c.

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

Referenced by pgr_fetch_column_info().

97  {
98  if (!(info.type == BPCHAROID)) {
99  elog(ERROR, "Unexpected Column '%s' type. Expected CHAR", info.name);
100  }
101 }
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)

Definition at line 104 of file get_check_data.c.

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

Referenced by pgr_fetch_column_info().

104  {
105  if (!(info.type == TEXTOID)) {
106  elog(ERROR, "Unexpected Column '%s' type. Expected TEXT", info.name);
107  }
108 }
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 
)

Definition at line 65 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().

67  {
68  int i;
69  for (i = 0; i < info_size; ++i) {
70  if (fetch_column_info(&info[i])) {
71  switch (info[i].eType) {
72  case ANY_INTEGER:
74  break;
75  case ANY_NUMERICAL:
77  break;
78  case TEXT:
79  pgr_check_text_type(info[i]);
80  break;
81  case CHAR1:
82  pgr_check_char_type(info[i]);
83  break;
84  case ANY_INTEGER_ARRAY:
86  break;
87  default:
88  elog(ERROR, "Unknown type of column %s", info[i].name);
89  }
90  }
91  }
92 }
void pgr_check_text_type(Column_info_t info)
void pgr_check_any_numerical_type(Column_info_t info)
void pgr_check_any_integer_type(Column_info_t info)
void pgr_check_char_type(Column_info_t info)
static bool fetch_column_info(Column_info_t *info)
void pgr_check_any_integerarray_type(Column_info_t info)

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 
)

Definition at line 191 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().

191  {
192  Datum binval;
193  bool isnull;
194  int64_t value = 0;
195  binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isnull);
196  if (isnull)
197  elog(ERROR, "Unexpected Null value in column %s", info.name);
198  switch (info.type) {
199  case INT2OID:
200  value = (int64_t) DatumGetInt16(binval);
201  break;
202  case INT4OID:
203  value = (int64_t) DatumGetInt32(binval);
204  break;
205  case INT8OID:
206  value = DatumGetInt64(binval);
207  break;
208  default:
209  elog(ERROR,
210  "Unexpected Column type of %s. Expected ANY-INTEGER",
211  info.name);
212  }
213 #if 0
214  PGR_DBG("Variable: %s Value: %ld", info.name, value);
215 #endif
216  return value;
217 }
#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 
)

Definition at line 175 of file get_check_data.c.

References Column_info_t::colNumber, and pgr_get_bigIntArray().

Referenced by fetch_restriction().

179  {
180  bool is_null = false;
181 
182  Datum raw_array = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &is_null);
183  ArrayType *pg_array = DatumGetArrayTypeP(raw_array);
184 
185  return (int64_t*) pgr_get_bigIntArray(the_size, pg_array);
186 }
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 
)

Definition at line 149 of file get_check_data.c.

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

Referenced by fetch_point().

151  {
152  Datum binval;
153  bool isNull;
154  char value = default_value;
155 
156  binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isNull);
157  if (!(info.type == BPCHAROID)) {
158  elog(ERROR, "Unexpected Column type of %s. Expected CHAR", info.name);
159  }
160  if (!isNull) {
161  value = ((char*)binval)[1];
162  } else {
163  if (strict) {
164  elog(ERROR, "Unexpected Null value in column %s", info.name);
165  }
166  value = default_value;
167  }
168  return value;
169 }
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 
)

Definition at line 220 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().

220  {
221  Datum binval;
222  bool isnull = false;
223  double value = 0.0;
224  binval = SPI_getbinval(*tuple, *tupdesc, info.colNumber, &isnull);
225  if (isnull)
226  elog(ERROR, "Unexpected Null value in column %s", info.name);
227 
228  switch (info.type) {
229  case INT2OID:
230  value = (double) DatumGetInt16(binval);
231  break;
232  case INT4OID:
233  value = (double) DatumGetInt32(binval);
234  break;
235  case INT8OID:
236  value = (double) DatumGetInt64(binval);
237  break;
238  case FLOAT4OID:
239  value = (double) DatumGetFloat4(binval);
240  break;
241  case FLOAT8OID:
242  value = DatumGetFloat8(binval);
243  break;
244  default:
245  elog(ERROR,
246  "Unexpected Column type of %s. Expected ANY-NUMERICAL",
247  info.name);
248  }
249 #if 0
250  PGR_DBG("Variable: %s Value: %lf", info.name, value);
251 #endif
252  return value;
253 }
#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

Definition at line 259 of file get_check_data.c.

References Column_info_t::colNumber.

259  {
260  return DatumGetCString(SPI_getvalue(*tuple, *tupdesc, info.colNumber));
261 }