PGROUTING  2.5
 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 
31 
32 
34 
35 #include "c_common/debug_macro.h"
37 
38 PGDLLEXPORT Datum test_matrixRows(PG_FUNCTION_ARGS);
39 
40 
41 /*******************************************************************************/
42 /* MODIFY AS NEEDED */
43 static
44 void
45 process(char* matrix_rows_sql,
46  bool *result_bool) {
48 
49  PGR_DBG("Load data");
50  Matrix_cell_t *matrix_rows = NULL;
51  size_t total_rows = 0;
52  pgr_get_matrixRows(matrix_rows_sql, &matrix_rows, &total_rows);
53 
54  if (total_rows == 0) {
55  PGR_DBG("No rows found");
56  (*result_bool) = true;
57  pfree(matrix_rows);
59  return;
60  }
61 
62  PGR_DBG("Total %ld rows in query:", total_rows);
63  size_t i;
64  for (i = 0; i < total_rows; ++i) {
65  PGR_DBG("start_vid = %li \t end_vid = %li agg_cost = %lf",
66  matrix_rows[i].from_vid, matrix_rows[i].to_vid, matrix_rows[i].cost);
67  }
68 
69 
70  PGR_DBG("Starting processing");
71  char *err_msg = NULL;
72  char *log_msg = NULL;
73  (*result_bool) = do_pgr_test_matrixRows(
74  matrix_rows,
75  total_rows,
76  &log_msg,
77  &err_msg);
78 
79  pfree(matrix_rows);
80  PGR_DBG("Returned log message = %s\n", log_msg);
81  if (log_msg) {
82  elog(DEBUG1, "%s", log_msg);
83  free(log_msg);
84  }
85  PGR_DBG("Returned error message = %s\n", err_msg);
86 
87  if (err_msg) {
89  elog(ERROR, "%s", err_msg);
90  free(err_msg);
91  }
92 
94 }
95 
96 
98 PGDLLEXPORT Datum
99 test_matrixRows(PG_FUNCTION_ARGS) {
100  bool result_bool = false;
101 
102  process(
103  text_to_cstring(PG_GETARG_TEXT_P(0)),
104  &result_bool);
105 
106  PG_RETURN_BOOL(result_bool);
107 }
PG_FUNCTION_INFO_V1(test_matrixRows)
#define PGR_DBG(...)
Definition: debug_macro.h:34
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,
bool do_pgr_test_matrixRows(Matrix_cell_t *matrix_rows, size_t total_rows, char **log_msg, char **err_msg)