GRASS Programmer's Manual 6.4.1(2011)
|
00001 00015 #include <stdlib.h> 00016 #include <string.h> 00017 #include <grass/dbmi.h> 00018 #include "macros.h" 00019 00020 static int cmp_dbstr(const void *pa, const void *pb) 00021 { 00022 const char *a = db_get_string((dbString *) pa); 00023 const char *b = db_get_string((dbString *) pb); 00024 00025 return strcmp(a, b); 00026 } 00027 00039 int db_list_tables(dbDriver * driver, dbString ** names, int *count, int system) 00040 { 00041 int ret_code; 00042 00043 /* start the procedure call */ 00044 db__set_protocol_fds(driver->send, driver->recv); 00045 DB_START_PROCEDURE_CALL(DB_PROC_LIST_TABLES); 00046 00047 /* arguments */ 00048 DB_SEND_INT(system); 00049 00050 /* get the return code for the procedure call */ 00051 DB_RECV_RETURN_CODE(&ret_code); 00052 00053 if (ret_code != DB_OK) 00054 return ret_code; /* ret_code SHOULD == DB_FAILED */ 00055 00056 /* results */ 00057 DB_RECV_STRING_ARRAY(names, count); 00058 00059 qsort(*names, *count, sizeof(dbString), cmp_dbstr); 00060 00061 return DB_OK; 00062 }