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