PGROUTING
3.2
postgres_connection.c
Go to the documentation of this file.
1
/*PGR-GNU*****************************************************************
2
File: postgres_connection.c
3
4
Copyright (c) 2015 Celia Virginia Vergara Castillo
5
[email protected]
6
7
------
8
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
13
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
18
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22
23
********************************************************************PGR-GNU*/
24
25
#include "
c_common/postgres_connection.h
"
26
27
#include <string.h>
28
#include "utils/builtins.h"
29
30
#include "catalog/pg_type.h"
31
32
33
#include "
c_common/debug_macro.h
"
34
35
void
36
pgr_send_error
(
int
errcode) {
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
}
50
51
52
char
*
53
pgr_cstring2char
(
const
char
*inStr) {
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
}
66
67
68
69
// http://www.postgresql.org/docs/9.4/static/spi-spi-finish.html
70
void
71
pgr_SPI_finish
(
void
) {
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
}
80
81
void
82
pgr_SPI_connect
(
void
) {
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
}
92
93
SPIPlanPtr
94
pgr_SPI_prepare
(
char
* sql) {
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
}
105
106
Portal
107
pgr_SPI_cursor_open
(SPIPlanPtr SPIplan) {
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
}
pgr_cstring2char
char * pgr_cstring2char(const char *inStr)
Definition:
postgres_connection.c:53
postgres_connection.h
pgr_SPI_prepare
SPIPlanPtr pgr_SPI_prepare(char *sql)
Definition:
postgres_connection.c:94
pgr_SPI_connect
void pgr_SPI_connect(void)
Definition:
postgres_connection.c:82
pgr_SPI_finish
void pgr_SPI_finish(void)
Definition:
postgres_connection.c:71
pgr_send_error
void pgr_send_error(int errcode)
Definition:
postgres_connection.c:36
debug_macro.h
pgr_SPI_cursor_open
Portal pgr_SPI_cursor_open(SPIPlanPtr SPIplan)
Definition:
postgres_connection.c:107
PGR_DBG
#define PGR_DBG(...)
Definition:
debug_macro.h:34
src
common
postgres_connection.c
Generated on Tue May 25 2021 15:09:48 for PGROUTING by
1.8.17