PGROUTING  3.2
postgres_connection.h File Reference
#include <postgres.h>
#include <executor/spi.h>
#include <funcapi.h>
#include <utils/builtins.h>
#include <access/htup_details.h>
#include <fmgr.h>
Include dependency graph for postgres_connection.h:

Go to the source code of this file.

Functions

char * pgr_cstring2char (const char *inStr)
 
void pgr_send_error (int errcode)
 
void pgr_SPI_connect (void)
 
Portal pgr_SPI_cursor_open (SPIPlanPtr SPIplan)
 
void pgr_SPI_finish (void)
 
SPIPlanPtr pgr_SPI_prepare (char *sql)
 

Function Documentation

◆ pgr_cstring2char()

char* pgr_cstring2char ( const char *  inStr)

Definition at line 53 of file postgres_connection.c.

53  {
54  if (!inStr) return NULL;
55 
56  char *outStr;
57  outStr = palloc(strlen(inStr));
58  if (!outStr) return NULL;
59 
60  memcpy(outStr, inStr, strlen(inStr));
61 
62  outStr[strlen(inStr)] = '\0';
63 
64  return outStr;
65 }

Referenced by pgr_error().

◆ pgr_send_error()

void pgr_send_error ( int  errcode)

Definition at line 36 of file postgres_connection.c.

36  {
37  switch (errcode) {
38  case 1:
39  elog(ERROR, "Unexpected point(s) with same pid but different"
40  " edge/fraction/side combination found.");
41  break;
42  case 2:
43  elog(ERROR, "Internal: Unexpected mismatch "
44  "count and sequence number on results");
45  break;
46  default:
47  elog(ERROR, "Unknown exception");
48  }
49 }

◆ pgr_SPI_connect()

void pgr_SPI_connect ( void  )

Definition at line 82 of file postgres_connection.c.

82  {
83 #if 0
84  PGR_DBG("Connecting to SPI");
85 #endif
86  int SPIcode;
87  SPIcode = SPI_connect();
88  if (SPIcode != SPI_OK_CONNECT) {
89  elog(ERROR, "Couldn't open a connection to SPI");
90  }
91 }

References PGR_DBG.

Referenced by compute(), compute_trsp(), process(), and process_combinations().

◆ pgr_SPI_cursor_open()

Portal pgr_SPI_cursor_open ( SPIPlanPtr  SPIplan)

Definition at line 107 of file postgres_connection.c.

107  {
108 #if 0
109  PGR_DBG("Opening Portal");
110 #endif
111  Portal SPIportal;
112  SPIportal = SPI_cursor_open(NULL, SPIplan, NULL, NULL, true);
113  if (SPIportal == NULL) {
114  elog(ERROR, "SPI_cursor_open returns NULL");
115  }
116  return SPIportal;
117 }

References PGR_DBG.

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

void pgr_SPI_finish ( void  )

Definition at line 71 of file postgres_connection.c.

71  {
72 #if 0
73  PGR_DBG("Disconnecting SPI");
74 #endif
75  int code = SPI_finish();
76  if (code != SPI_OK_FINISH) { // SPI_ERROR_UNCONNECTED
77  elog(ERROR, "There was no connection to SPI");
78  }
79 }

References PGR_DBG.

Referenced by compute(), compute_trsp(), process(), and process_combinations().

◆ pgr_SPI_prepare()

SPIPlanPtr pgr_SPI_prepare ( char *  sql)

Definition at line 94 of file postgres_connection.c.

94  {
95 #if 0
96  PGR_DBG("Preparing Plan");
97 #endif
98  SPIPlanPtr SPIplan;
99  SPIplan = SPI_prepare(sql, 0, NULL);
100  if (SPIplan == NULL) {
101  elog(ERROR, "Couldn't create query plan via SPI: %s", sql);
102  }
103  return SPIplan;
104 }

References PGR_DBG.

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_DBG
#define PGR_DBG(...)
Definition: debug_macro.h:34