pgRouting
pgRouting extends the PostGIS / PostgreSQL geospatial database to provide geospatial routing functionality.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_matrixRows.c
Go to the documentation of this file.
1 /*PGR-GNU*****************************************************************
2 File: testXYedges.c
3 
4 Generated with Template by:
5 Copyright (c) 2015 pgRouting developers
6 Mail: project@pgrouting.org
7 
8 Function's developer:
9 Copyright (c) 2015 Celia Virginia Vergara Castillo
10 Mail:
11 
12 ------
13 
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18 
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23 
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 
28 ********************************************************************PGR-GNU*/
29 
30 #include "postgres.h"
31 #include "executor/spi.h"
32 #include "funcapi.h"
33 #include "utils/array.h"
34 #include "catalog/pg_type.h"
35 #if PGSQL_VERSION > 92
36 #include "access/htup_details.h"
37 #endif
38 
39 /*
40  Uncomment when needed
41 */
42 // #define DEBUG
43 
44 #include "fmgr.h"
45 #include "./../../common/src/debug_macro.h"
46 #include "./../../common/src/pgr_types.h"
47 #include "./../../common/src/postgres_connection.h"
48 #include "./../../common/src/matrixRows_input.h"
49 
51 
52 PGDLLEXPORT Datum test_matrixRows(PG_FUNCTION_ARGS);
53 
54 
55 /*******************************************************************************/
56 /* MODIFY AS NEEDED */
57 static
58 void
59 process(char* matrix_rows_sql,
60  bool *result_bool) {
62 
63  PGR_DBG("Load data");
64  Matrix_cell_t *matrix_rows = NULL;
65  size_t total_rows = 0;
66  pgr_get_matrixRows(matrix_rows_sql, &matrix_rows, &total_rows);
67 
68  if (total_rows == 0) {
69  PGR_DBG("No rows found");
70  (*result_bool) = true;
71  pfree(matrix_rows);
73  return;
74  }
75 
76  PGR_DBG("Total %ld rows in query:", total_rows);
77  size_t i;
78  for (i = 0; i < total_rows; ++i) {
79  PGR_DBG("start_vid = %li \t end_vid = %li agg_cost = %lf",
80  matrix_rows[i].from_vid, matrix_rows[i].to_vid, matrix_rows[i].cost);
81  }
82 
83 
84  PGR_DBG("Starting processing");
85  char *err_msg = NULL;
86  char *log_msg = NULL;
87  (*result_bool) = do_pgr_test_matrixRows(
88  matrix_rows,
89  total_rows,
90  &log_msg,
91  &err_msg);
92 
93  pfree(matrix_rows);
94  PGR_DBG("Returned log message = %s\n", log_msg);
95  if (log_msg) {
96  elog(DEBUG1, "%s", log_msg);
97  free(log_msg);
98  }
99  PGR_DBG("Returned error message = %s\n", err_msg);
100 
101  if (err_msg) {
102  elog(ERROR, "%s", err_msg);
103  free(err_msg);
104  }
105 
106  pgr_SPI_finish();
107 }
108 
109 
111 PGDLLEXPORT Datum
112 test_matrixRows(PG_FUNCTION_ARGS) {
113  bool result_bool = false;
114 
115  process(
116  pgr_text2char(PG_GETARG_TEXT_P(0)),
117  &result_bool);
118 
119  PG_RETURN_BOOL(result_bool);
120 }
PG_FUNCTION_INFO_V1(test_matrixRows)
#define PGR_DBG(...)
Definition: debug_macro.h:33
void pgr_SPI_finish(void)
PGDLLEXPORT Datum test_matrixRows(PG_FUNCTION_ARGS)
void pgr_SPI_connect(void)
static void process(char *matrix_rows_sql, bool *result_bool)
void pgr_get_matrixRows(char *sql, Matrix_cell_t **rows, size_t *total_rows)
bigint start_vid, bigint end_vid, float agg_cost,
char * err_msg
Definition: BDATester.cpp:50
bool do_pgr_test_matrixRows(Matrix_cell_t *matrix_rows, size_t total_rows, char **log_msg, char **err_msg)
char * pgr_text2char(text *in)