GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
c_list_tabs.c
Go to the documentation of this file.
1 
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 
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);
45  DB_START_PROCEDURE_CALL(DB_PROC_LIST_TABLES);
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 }
float b
Definition: named_colr.c:8
void db__set_protocol_fds(FILE *send, FILE *recv)
Definition: xdr.c:71
#define DB_SEND_INT(x)
Definition: macros.h:37
int count
#define DB_START_PROCEDURE_CALL(x)
Definition: macros.h:2
#define DB_RECV_RETURN_CODE(x)
Definition: macros.h:4
Definition: driver.h:25
char * db_get_string(dbString *x)
Definition: string.c:131
#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