GRASS Programmer's Manual  6.4.2(2012)
 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 }