Преглед на файлове

db lib: use G_asprintf

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@53079 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz преди 12 години
родител
ревизия
03cc5766fd
променени са 1 файла, в които са добавени 11 реда и са изтрити 8 реда
  1. 11 8
      lib/db/dbmi_client/select.c

+ 11 - 8
lib/db/dbmi_client/select.c

@@ -105,7 +105,7 @@ int db_select_int(dbDriver * driver, const char *tab, const char *col,
 {
 {
     int type, more, alloc, count;
     int type, more, alloc, count;
     int *val;
     int *val;
-    char buf[1024];
+    char *buf = NULL;
     const char *sval;
     const char *sval;
     dbString stmt;
     dbString stmt;
     dbCursor cursor;
     dbCursor cursor;
@@ -125,14 +125,15 @@ int db_select_int(dbDriver * driver, const char *tab, const char *col,
     val = (int *)G_malloc(alloc * sizeof(int));
     val = (int *)G_malloc(alloc * sizeof(int));
 
 
     if (where == NULL || strlen(where) == 0)
     if (where == NULL || strlen(where) == 0)
-	G_snprintf(buf, 1023, "SELECT %s FROM %s", col, tab);
+	G_asprintf(&buf, "SELECT %s FROM %s", col, tab);
     else
     else
-	G_snprintf(buf, 1023, "SELECT %s FROM %s WHERE %s", col, tab, where);
+	G_asprintf(&buf, "SELECT %s FROM %s WHERE %s", col, tab, where);
 
 
     G_debug(3, "  SQL: %s", buf);
     G_debug(3, "  SQL: %s", buf);
 
 
     db_init_string(&stmt);
     db_init_string(&stmt);
     db_set_string(&stmt, buf);
     db_set_string(&stmt, buf);
+    G_free(buf);
 
 
     if (db_open_select_cursor(driver, &stmt, &cursor, DB_SEQUENTIAL) != DB_OK)
     if (db_open_select_cursor(driver, &stmt, &cursor, DB_SEQUENTIAL) != DB_OK)
 	return (-1);
 	return (-1);
@@ -204,7 +205,7 @@ int db_select_value(dbDriver * driver, const char *tab, const char *key,
 		    int id, const char *col, dbValue * val)
 		    int id, const char *col, dbValue * val)
 {
 {
     int more, count;
     int more, count;
-    char buf[1024];
+    char *buf = NULL;
     dbString stmt;
     dbString stmt;
     dbCursor cursor;
     dbCursor cursor;
     dbColumn *column;
     dbColumn *column;
@@ -222,9 +223,10 @@ int db_select_value(dbDriver * driver, const char *tab, const char *key,
     }
     }
 
 
     G_zero(val, sizeof(dbValue));
     G_zero(val, sizeof(dbValue));
-    sprintf(buf, "SELECT %s FROM %s WHERE %s = %d\n", col, tab, key, id);
+    G_asprintf(&buf, "SELECT %s FROM %s WHERE %s = %d", col, tab, key, id);
     db_init_string(&stmt);
     db_init_string(&stmt);
     db_set_string(&stmt, buf);
     db_set_string(&stmt, buf);
+    G_free(buf);
 
 
     if (db_open_select_cursor(driver, &stmt, &cursor, DB_SEQUENTIAL) != DB_OK)
     if (db_open_select_cursor(driver, &stmt, &cursor, DB_SEQUENTIAL) != DB_OK)
 	return (-1);
 	return (-1);
@@ -268,7 +270,7 @@ int db_select_CatValArray(dbDriver * driver, const char *tab, const char *key,
 			  dbCatValArray * cvarr)
 			  dbCatValArray * cvarr)
 {
 {
     int i, type, more, nrows, ncols;
     int i, type, more, nrows, ncols;
-    char buf[1024];
+    char *buf = NULL;
     dbString stmt;
     dbString stmt;
     dbCursor cursor;
     dbCursor cursor;
     dbColumn *column;
     dbColumn *column;
@@ -290,13 +292,14 @@ int db_select_CatValArray(dbDriver * driver, const char *tab, const char *key,
 
 
     if (strcmp(key, col) == 0) {
     if (strcmp(key, col) == 0) {
 	ncols = 1;
 	ncols = 1;
-	sprintf(buf, "SELECT %s FROM %s", key, tab);
+	G_asprintf(&buf, "SELECT %s FROM %s", key, tab);
     }
     }
     else {
     else {
 	ncols = 2;
 	ncols = 2;
-	sprintf(buf, "SELECT %s, %s FROM %s", key, col, tab);
+	G_asprintf(&buf, "SELECT %s, %s FROM %s", key, col, tab);
     }
     }
     db_set_string(&stmt, buf);
     db_set_string(&stmt, buf);
+    G_free(buf);
 
 
     if (where != NULL && strlen(where) > 0) {
     if (where != NULL && strlen(where) > 0) {
 	db_append_string(&stmt, " WHERE ");
 	db_append_string(&stmt, " WHERE ");