GRASS GIS 7 Programmer's Manual  7.5.svn(2018)-r73000
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
c_list_tabs.c
Go to the documentation of this file.
1 /*!
2  * \file db/dbmi_client/c_list_tabs.c
3  *
4  * \brief DBMI Library (client) - list tables
5  *
6  * (C) 1999-2008 by the GRASS Development Team
7  *
8  * This program is free software under the GNU General Public
9  * License (>=v2). Read the file COPYING that comes with GRASS
10  * for details.
11  *
12  * \author Joel Jones (CERL/UIUC), Radim Blazek
13  */
14 
15 #include <stdlib.h>
16 #include <string.h>
17 #include <grass/dbmi.h>
18 #include "macros.h"
19 
20 static int cmp_dbstr(const void *pa, const void *pb)
21 {
22  const char *a = db_get_string((dbString *) pa);
23  const char *b = db_get_string((dbString *) pb);
24 
25  return strcmp(a, b);
26 }
27 
28 /*!
29  \brief List available tables for given connection
30 
31  \param driver db driver
32  \param[out] names list of table names
33  \param[out] count number of items in the list
34  \param system ?
35 
36  \return DB_OK on success
37  \return DB_FAILED on failure
38  */
39 int db_list_tables(dbDriver * driver, dbString ** names, int *count, int system)
40 {
41  int ret_code;
42 
43  /* start the procedure call */
44  db__set_protocol_fds(driver->send, driver->recv);
46 
47  /* arguments */
48  DB_SEND_INT(system);
49 
50  /* get the return code for the procedure call */
51  DB_RECV_RETURN_CODE(&ret_code);
52 
53  if (ret_code != DB_OK)
54  return ret_code; /* ret_code SHOULD == DB_FAILED */
55 
56  /* results */
57  DB_RECV_STRING_ARRAY(names, count);
58 
59  qsort(*names, *count, sizeof(dbString), cmp_dbstr);
60 
61  return DB_OK;
62 }
#define DB_SEND_INT(x)
Definition: macros.h:37
int count
char * db_get_string(const dbString *x)
Get string.
Definition: string.c:140
#define DB_PROC_LIST_TABLES
Definition: dbmi.h:56
#define DB_START_PROCEDURE_CALL(x)
Definition: macros.h:2
double b
Definition: r_raster.c:39
#define DB_RECV_RETURN_CODE(x)
Definition: macros.h:4
Definition: driver.h:22
void db__set_protocol_fds(FILE *send, FILE *recv)
?
FILE * recv
Definition: dbmi.h:171
#define DB_RECV_STRING_ARRAY(x, n)
Definition: macros.h:20
int db_list_tables(dbDriver *driver, dbString **names, int *count, int system)
List available tables for given connection.
Definition: c_list_tabs.c:39
FILE * send
Definition: dbmi.h:171
#define DB_OK
Definition: dbmi.h:71