|
@@ -23,6 +23,8 @@
|
|
|
#include <grass/vector.h>
|
|
|
#include <grass/dbmi.h>
|
|
|
|
|
|
+#define BUFF_MAX 2000
|
|
|
+
|
|
|
/*!
|
|
|
\brief Fetches list of DB column names of vector map attribute table
|
|
|
|
|
@@ -40,8 +42,8 @@ const char *Vect_get_column_names(const struct Map_info *Map, int field)
|
|
|
dbHandle handle;
|
|
|
dbString table_name;
|
|
|
dbTable *table;
|
|
|
- char buf[2000];
|
|
|
-
|
|
|
+ const char **col_names;
|
|
|
+ char *list;
|
|
|
|
|
|
num_dblinks = Vect_get_num_dblinks(Map);
|
|
|
if (num_dblinks <= 0)
|
|
@@ -65,21 +67,18 @@ const char *Vect_get_column_names(const struct Map_info *Map, int field)
|
|
|
return (NULL);
|
|
|
|
|
|
ncols = db_get_table_number_of_columns(table);
|
|
|
- sprintf(buf, " ");
|
|
|
- for (col = 0; col < ncols; col++) {
|
|
|
- if (col == 0)
|
|
|
- sprintf(buf, "%s",
|
|
|
- db_get_column_name(db_get_table_column(table, col)));
|
|
|
- else
|
|
|
- sprintf(buf, "%s,%s", buf,
|
|
|
- db_get_column_name(db_get_table_column(table, col)));
|
|
|
- }
|
|
|
- G_debug(3, "%s", buf);
|
|
|
+ col_names = G_malloc(ncols * sizeof(char *));
|
|
|
+ for (col = 0; col < ncols; col++)
|
|
|
+ col_names[col] = db_get_column_name(db_get_table_column(table, col));
|
|
|
+ if ((list = G_str_concat(col_names, ncols, ",", BUFF_MAX)) == NULL)
|
|
|
+ list = G_store("");
|
|
|
+ G_free(col_names);
|
|
|
+ G_debug(3, "%s", list);
|
|
|
|
|
|
db_close_database(driver);
|
|
|
db_shutdown_driver(driver);
|
|
|
|
|
|
- return G_store(G_chop(buf));
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
/*!
|
|
@@ -99,8 +98,8 @@ const char *Vect_get_column_types(const struct Map_info *Map, int field)
|
|
|
dbHandle handle;
|
|
|
dbString table_name;
|
|
|
dbTable *table;
|
|
|
- char buf[2000];
|
|
|
-
|
|
|
+ const char **sqltype_names;
|
|
|
+ char *list;
|
|
|
|
|
|
num_dblinks = Vect_get_num_dblinks(Map);
|
|
|
if (num_dblinks <= 0)
|
|
@@ -124,23 +123,20 @@ const char *Vect_get_column_types(const struct Map_info *Map, int field)
|
|
|
return (NULL);
|
|
|
|
|
|
ncols = db_get_table_number_of_columns(table);
|
|
|
- sprintf(buf, " ");
|
|
|
- for (col = 0; col < ncols; col++) {
|
|
|
- if (col == 0)
|
|
|
- sprintf(buf, "%s",
|
|
|
- db_sqltype_name(db_get_column_sqltype
|
|
|
- (db_get_table_column(table, col))));
|
|
|
- else
|
|
|
- sprintf(buf, "%s,%s", buf,
|
|
|
- db_sqltype_name(db_get_column_sqltype
|
|
|
- (db_get_table_column(table, col))));
|
|
|
- }
|
|
|
- G_debug(3, "%s", buf);
|
|
|
+ sqltype_names = G_malloc(ncols * sizeof(char *));
|
|
|
+ for (col = 0; col < ncols; col++)
|
|
|
+ sqltype_names[col] = db_sqltype_name(db_get_column_sqltype
|
|
|
+ (db_get_table_column
|
|
|
+ (table, col)));
|
|
|
+ if ((list = G_str_concat(sqltype_names, ncols, ",", BUFF_MAX)) == NULL)
|
|
|
+ list = G_store("");
|
|
|
+ G_free(sqltype_names);
|
|
|
+ G_debug(3, "%s", list);
|
|
|
|
|
|
db_close_database(driver);
|
|
|
db_shutdown_driver(driver);
|
|
|
|
|
|
- return G_store(G_chop(buf));
|
|
|
+ return list;
|
|
|
}
|
|
|
|
|
|
|
|
@@ -161,8 +157,8 @@ const char *Vect_get_column_names_types(const struct Map_info *Map, int field)
|
|
|
dbHandle handle;
|
|
|
dbString table_name;
|
|
|
dbTable *table;
|
|
|
- char buf[2000];
|
|
|
-
|
|
|
+ const char **col_type_names;
|
|
|
+ char *list;
|
|
|
|
|
|
num_dblinks = Vect_get_num_dblinks(Map);
|
|
|
if (num_dblinks <= 0)
|
|
@@ -186,23 +182,23 @@ const char *Vect_get_column_names_types(const struct Map_info *Map, int field)
|
|
|
return (NULL);
|
|
|
|
|
|
ncols = db_get_table_number_of_columns(table);
|
|
|
- sprintf(buf, " ");
|
|
|
+ col_type_names = G_malloc(ncols * sizeof(char *));
|
|
|
for (col = 0; col < ncols; col++) {
|
|
|
- if (col == 0)
|
|
|
- sprintf(buf, "%s(%s)",
|
|
|
- db_get_column_name(db_get_table_column(table, col)),
|
|
|
- db_sqltype_name(db_get_column_sqltype
|
|
|
- (db_get_table_column(table, col))));
|
|
|
- else
|
|
|
- sprintf(buf, "%s,%s(%s)", buf,
|
|
|
- db_get_column_name(db_get_table_column(table, col)),
|
|
|
- db_sqltype_name(db_get_column_sqltype
|
|
|
- (db_get_table_column(table, col))));
|
|
|
+ char buf[256];
|
|
|
+
|
|
|
+ sprintf(buf, "%s(%s)",
|
|
|
+ db_get_column_name(db_get_table_column(table, col)),
|
|
|
+ db_sqltype_name(db_get_column_sqltype
|
|
|
+ (db_get_table_column(table, col))));
|
|
|
+ col_type_names[col] = buf;
|
|
|
}
|
|
|
- G_debug(3, "%s", buf);
|
|
|
+ if ((list = G_str_concat(col_type_names, ncols, ",", BUFF_MAX)) == NULL)
|
|
|
+ list = G_store("");
|
|
|
+ G_free(col_type_names);
|
|
|
+ G_debug(3, "%s", list);
|
|
|
|
|
|
db_close_database(driver);
|
|
|
db_shutdown_driver(driver);
|
|
|
|
|
|
- return G_store(G_chop(buf));
|
|
|
+ return list;
|
|
|
}
|