GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
field.c
Go to the documentation of this file.
1 
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <grass/glocale.h>
28 #include <grass/gis.h>
29 #include <grass/dbmi.h>
30 #include <grass/Vect.h>
31 
32 #include <gdal_version.h> /* needed for FID detection */
33 
34 #ifdef HAVE_OGR
35 #include <ogr_api.h>
36 #endif
37 
45 struct dblinks *Vect_new_dblinks_struct(void)
46 {
47  struct dblinks *p;
48 
49  p = (struct dblinks *)G_malloc(sizeof(struct dblinks));
50 
51  if (p) {
52  p->alloc_fields = p->n_fields = 0;
53  p->field = NULL;
54  }
55 
56  return p;
57 }
58 
66 void Vect_reset_dblinks(struct dblinks *p)
67 {
68  p->n_fields = 0;
69 }
70 
85 int
86 Vect_map_add_dblink(struct Map_info *Map, int number, const char *name,
87  const char *table, const char *key, const char *db,
88  const char *driver)
89 {
90  int ret;
91 
92  if (number == 0) {
93  G_warning(_("Layer number must be 1 or greater"));
94  return -1;
95  }
96 
97  if (Map->mode != GV_MODE_WRITE && Map->mode != GV_MODE_RW) {
98  G_warning(_("Unable to add database link, map is not opened in WRITE mode"));
99  return -1;
100  }
101 
102  ret = Vect_add_dblink(Map->dblnk, number, name, table, key, db, driver);
103  if (ret == -1) {
104  G_warning(_("Unable to add database link"));
105  return -1;
106  }
107  /* write it immediately otherwise it is lost if module crashes */
108  ret = Vect_write_dblinks(Map);
109  if (ret == -1) {
110  G_warning(_("Unable to write database links"));
111  return -1;
112  }
113  return 0;
114 }
115 
125 int Vect_map_del_dblink(struct Map_info *Map, int field)
126 {
127  int i, j, ret;
128  struct dblinks *links;
129 
130  G_debug(4, "Vect_map_del_dblink() field = %d", field);
131  links = Map->dblnk;
132 
133  ret = -1;
134  for (i = 0; i < links->n_fields; i++) {
135  if (links->field[i].number == field) { /* field found */
136  for (j = i; j < links->n_fields - 1; j++) {
137  links->field[j].number = links->field[j + 1].number;
138  links->field[j].name = links->field[j + 1].name;
139  links->field[j].table = links->field[j + 1].table;
140  links->field[j].key = links->field[j + 1].key;
141  links->field[j].database = links->field[j + 1].database;
142  links->field[j].driver = links->field[j + 1].driver;
143  }
144  ret = 0;
145  links->n_fields--;
146  }
147  }
148 
149  if (ret == -1)
150  return -1;
151 
152  /* write it immediately otherwise it is lost if module crashes */
153  ret = Vect_write_dblinks(Map);
154  if (ret == -1) {
155  G_warning(_("Unable to write database links"));
156  return -1;
157  }
158 
159  return 0;
160 }
161 
171 int Vect_map_check_dblink(struct Map_info *Map, int field)
172 {
173  return Vect_check_dblink(Map->dblnk, field);
174 }
175 
185 int Vect_check_dblink(struct dblinks *p, int field)
186 {
187  int i;
188 
189  G_debug(3, "Vect_check_dblink: field %d", field);
190 
191  for (i = 0; i < p->n_fields; i++) {
192  if (p->field[i].number == field) {
193  return 1;
194  }
195  }
196  return 0;
197 }
198 
199 
213 int
214 Vect_add_dblink(struct dblinks *p, int number, const char *name,
215  const char *table, const char *key, const char *db,
216  const char *driver)
217 {
218  int ret;
219 
220  G_debug(3, "Field number <%d>, name <%s>", number, name);
221  ret = Vect_check_dblink(p, number);
222  if (ret == 1) {
223  G_warning(_("Layer number %d or name <%s> already exists"), number,
224  name);
225  return -1;
226  }
227 
228  if (p->n_fields == p->alloc_fields) {
229  p->alloc_fields += 10;
230  p->field = (struct field_info *)G_realloc((void *)p->field,
231  p->alloc_fields *
232  sizeof(struct field_info));
233  }
234 
235  p->field[p->n_fields].number = number;
236 
237  if (name != NULL)
238  p->field[p->n_fields].name = G_store(name);
239  else
240  p->field[p->n_fields].name = NULL;
241 
242  if (table != NULL)
243  p->field[p->n_fields].table = G_store(table);
244  else
245  p->field[p->n_fields].table = NULL;
246 
247  if (key != NULL)
248  p->field[p->n_fields].key = G_store(key);
249  else
250  p->field[p->n_fields].key = NULL;
251 
252  if (db != NULL)
253  p->field[p->n_fields].database = G_store(db);
254  else
255  p->field[p->n_fields].database = NULL;
256 
257  if (driver != NULL)
258  p->field[p->n_fields].driver = G_store(driver);
259  else
260  p->field[p->n_fields].driver = NULL;
261 
262  p->n_fields++;
263 
264  return 0;
265 }
266 
277 struct field_info
278  *Vect_default_field_info(struct Map_info *Map,
279  int field, const char *field_name, int type)
280 {
281  struct field_info *fi;
282  char buf[1000], buf2[1000];
283  const char *schema;
284  const char *drv, *db;
285  dbConnection connection;
286 
287  G_debug(1, "Vect_default_field_info(): map = %s field = %d", Map->name,
288  field);
289 
290  db_get_connection(&connection);
291  drv = G__getenv2("DB_DRIVER", G_VAR_MAPSET);
292  db = G__getenv2("DB_DATABASE", G_VAR_MAPSET);
293 
294  G_debug(2, "drv = %s db = %s", drv, db);
295 
296 
297  if (!connection.driverName && !connection.databaseName) {
298  /* Set default values and create dbf db dir */
300  db_get_connection(&connection);
301 
302  G_warning(_("Default driver / database set to:\n"
303  "driver: %s\ndatabase: %s"), connection.driverName,
304  connection.databaseName);
305  }
306  /* they must be a matched pair, so if one is set but not the other
307  then give up and let the user figure it out */
308  else if (!connection.driverName) {
309  G_fatal_error(_("Default driver is not set"));
310  }
311  else if (!connection.databaseName) {
312  G_fatal_error(_("Default database is not set"));
313  }
314 
315  drv = connection.driverName;
316  db = connection.databaseName;
317 
318  fi = (struct field_info *)G_malloc(sizeof(struct field_info));
319 
320  fi->number = field;
321  if (field_name != NULL)
322  fi->name = G_store(field_name);
323  else
324  fi->name = NULL;
325 
326  /* Table name */
327  if (type == GV_1TABLE) {
328  sprintf(buf, "%s", Map->name);
329  }
330  else {
331  if (field_name != NULL && strlen(field_name) > 0)
332  sprintf(buf, "%s_%s", Map->name, field_name);
333  else
334  sprintf(buf, "%s_%d", Map->name, field);
335  }
336 
337  schema = connection.schemaName;
338  if (schema && strlen(schema) > 0) {
339  sprintf(buf2, "%s.%s", schema, buf);
340  fi->table = G_store(buf2);
341  }
342  else {
343  fi->table = G_store(buf);
344  }
345 
346  fi->key = G_store("cat"); /* Should be: id/fid/gfid/... ? */
347  fi->database = G_store(db);
348  fi->driver = G_store(drv);
349 
350  return (fi);
351 }
352 
364 struct field_info *Vect_get_dblink(struct Map_info *Map, int link)
365 {
366  struct field_info *fi;
367 
368  G_debug(1, "Vect_get_dblink(): link = %d", link);
369 
370  if (link >= Map->dblnk->n_fields) {
371  G_warning(_("Requested dblink %d, maximum link number %d"), link,
372  Map->dblnk->n_fields - 1);
373  return NULL;
374  }
375 
376  fi = (struct field_info *)malloc(sizeof(struct field_info));
377  fi->number = Map->dblnk->field[link].number;
378 
379  if (Map->dblnk->field[link].name != NULL)
380  fi->name = G_store(Map->dblnk->field[link].name);
381  else
382  fi->name = NULL;
383 
384  fi->table = G_store(Map->dblnk->field[link].table);
385  fi->key = G_store(Map->dblnk->field[link].key);
386  fi->database = Vect_subst_var(Map->dblnk->field[link].database, Map);
387  fi->driver = G_store(Map->dblnk->field[link].driver);
388 
389  return fi;
390 }
391 
404 struct field_info *Vect_get_field(struct Map_info *Map, int field)
405 {
406  int i;
407  struct field_info *fi = NULL;
408 
409  G_debug(1, "Vect_get_field(): field = %d", field);
410 
411  for (i = 0; i < Map->dblnk->n_fields; i++) {
412  if (Map->dblnk->field[i].number == field) {
413  fi = Vect_get_dblink(Map, i);
414  break;
415  }
416  }
417 
418  return fi;
419 }
420 
431 int Vect_read_dblinks(struct Map_info *Map)
432 {
433  FILE *fd;
434  char file[1024], buf[2001];
435  char tab[1024], col[1024], db[1024], drv[1024], fldstr[1024], *fldname;
436  int fld;
437  char *c;
438  int row, rule;
439  struct dblinks *dbl;
440  char **tokens;
441  int ntok, i;
442 
443  G_debug(1, "Vect_read_dblinks(): map = %s, mapset = %s", Map->name,
444  Map->mapset);
445 
446  dbl = Map->dblnk;
447  Vect_reset_dblinks(dbl);
448 
449  G_debug(3, "Searching for FID column in OGR DB");
450  if (Map->format == GV_FORMAT_OGR) {
451 
452 #if GDAL_VERSION_NUM > 1320 && HAVE_OGR /* seems to be fixed after 1320 release */
453  int layer, nLayers;
454  OGRDataSourceH Ogr_ds;
455  OGRLayerH Ogr_layer = NULL;
456  OGRFeatureDefnH Ogr_featuredefn;
457  char ogr_fid_col[1024];
458 
459 
460  G_debug(3, "GDAL_VERSION_NUM: %d", GDAL_VERSION_NUM);
461 
462  /* we open the connection to fetch the FID column name */
463  OGRRegisterAll();
464 
465  /*Data source handle */
466  Ogr_ds = OGROpen(Map->fInfo.ogr.dsn, FALSE, NULL);
467  if (Ogr_ds == NULL)
468  G_fatal_error("Cannot open OGR data source '%s'",
469  Map->fInfo.ogr.dsn);
470  Map->fInfo.ogr.ds = Ogr_ds;
471 
472  /* Layer number */
473  layer = -1;
474  nLayers = OGR_DS_GetLayerCount(Ogr_ds); /* Layers = Maps in OGR DB */
475 
476  G_debug(3, "%d layers (maps) found in data source", nLayers);
477 
478  G_debug(3, "Trying to open OGR layer: %s", Map->fInfo.ogr.layer_name);
479  Ogr_layer = OGR_DS_GetLayerByName(Ogr_ds, Map->fInfo.ogr.layer_name);
480  if (Ogr_layer == NULL) {
481  OGR_DS_Destroy(Ogr_ds);
482  G_fatal_error("Cannot open layer '%s'",
483  Map->fInfo.ogr.layer_name);
484  }
485  Ogr_featuredefn = OGR_L_GetLayerDefn(Ogr_layer);
486  G_debug(3, "layer %s, FID col name: %s",
487  OGR_FD_GetName(Ogr_featuredefn),
488  OGR_L_GetFIDColumn(Ogr_layer));
489  Map->fInfo.ogr.layer = Ogr_layer;
490  G_debug(3, "OGR Map->fInfo.ogr.layer %p opened",
491  Map->fInfo.ogr.layer);
492 
493  /* TODO what to do if OGR_L_GetFIDColumn() doesn't return FID name */
494  sprintf(ogr_fid_col, "%s", OGR_L_GetFIDColumn(Map->fInfo.ogr.layer));
495  G_debug(3, "Using FID column <%s> in OGR DB", ogr_fid_col);
496  Vect_add_dblink(dbl, 1, NULL, Map->fInfo.ogr.layer_name, ogr_fid_col,
497  Map->fInfo.ogr.dsn, "ogr");
498 #else
499  dbDriver *driver;
500  dbCursor cursor;
501  dbString sql;
502  int FID = 0, OGC_FID = 0, OGR_FID = 0, GID = 0;
503 
504  G_debug(3, "GDAL_VERSION_NUM: %d", GDAL_VERSION_NUM);
505 
506  /* FID is not available for all OGR drivers */
507  db_init_string(&sql);
508 
509  driver = db_start_driver_open_database("ogr", Map->fInfo.ogr.dsn);
510 
511  if (driver == NULL) {
512  G_warning(_("Unable to open OGR DBMI driver"));
513  return -1;
514  }
515 
516  /* this is a bit stupid, but above FID auto-detection doesn't work yet...: */
518  sprintf(buf, "select FID from %s where FID > 0",
519  Map->fInfo.ogr.layer_name);
520  db_set_string(&sql, buf);
521 
522  if (db_open_select_cursor(driver, &sql, &cursor, DB_SEQUENTIAL) !=
523  DB_OK) {
524  /* FID not available, so we try ogc_fid */
525  G_debug(3, "Failed. Now searching for ogc_fid column in OGR DB");
526  sprintf(buf, "select ogc_fid from %s where ogc_fid > 0",
527  Map->fInfo.ogr.layer_name);
528  db_set_string(&sql, buf);
529 
530  if (db_open_select_cursor(driver, &sql, &cursor, DB_SEQUENTIAL) !=
531  DB_OK) {
532  /* Neither FID nor ogc_fid available, so we try ogr_fid */
533  G_debug(3,
534  "Failed. Now searching for ogr_fid column in OGR DB");
535  sprintf(buf, "select ogr_fid from %s where ogr_fid > 0",
536  Map->fInfo.ogr.layer_name);
537  db_set_string(&sql, buf);
538 
540  (driver, &sql, &cursor, DB_SEQUENTIAL) != DB_OK) {
541  /* Neither FID nor ogc_fid available, so we try gid */
542  G_debug(3,
543  "Failed. Now searching for gid column in OGR DB");
544  sprintf(buf, "select gid from %s where gid > 0",
545  Map->fInfo.ogr.layer_name);
546  db_set_string(&sql, buf);
547 
549  (driver, &sql, &cursor, DB_SEQUENTIAL) != DB_OK) {
550  /* neither FID nor ogc_fid nor ogr_fid nor gid available */
551  G_warning(_("All FID tests failed. Neither 'FID' nor 'ogc_fid' "
552  "nor 'ogr_fid' nor 'gid' available in OGR DB table"));
554  return 0;
555  }
556  else
557  GID = 1;
558  }
559  else
560  OGR_FID = 1;
561  }
562  else
563  OGC_FID = 1;
564  }
565  else
566  FID = 1;
567 
568  G_debug(3, "FID: %d, OGC_FID: %d, OGR_FID: %d, GID: %d", FID, OGC_FID,
569  OGR_FID, GID);
570 
571  db_close_cursor(&cursor);
574 
575  if (FID) {
576  G_debug(3, "Using FID column in OGR DB");
577  Vect_add_dblink(dbl, 1, NULL, Map->fInfo.ogr.layer_name, "FID",
578  Map->fInfo.ogr.dsn, "ogr");
579  }
580  else {
581  if (OGC_FID) {
582  G_debug(3, "Using ogc_fid column in OGR DB");
583  Vect_add_dblink(dbl, 1, NULL, Map->fInfo.ogr.layer_name,
584  "ogc_fid", Map->fInfo.ogr.dsn, "ogr");
585  }
586  else {
587  if (OGR_FID) {
588  G_debug(3, "Using ogr_fid column in OGR DB");
589  Vect_add_dblink(dbl, 1, NULL, Map->fInfo.ogr.layer_name,
590  "ogr_fid", Map->fInfo.ogr.dsn, "ogr");
591  }
592  else {
593  if (GID) {
594  G_debug(3, "Using gid column in OGR DB");
595  Vect_add_dblink(dbl, 1, NULL,
596  Map->fInfo.ogr.layer_name, "gid",
597  Map->fInfo.ogr.dsn, "ogr");
598  }
599  }
600  }
601  }
602 #endif /* GDAL_VERSION_NUM > 1320 && HAVE_OGR */
603  return (1);
604  }
605  else if (Map->format != GV_FORMAT_NATIVE) {
606  G_fatal_error(_("Don't know how to read links for format %d"),
607  Map->format);
608  }
609 
610  sprintf(file, "%s/%s/%s/%s/%s/%s", Map->gisdbase, Map->location,
611  Map->mapset, GRASS_VECT_DIRECTORY, Map->name,
612  GRASS_VECT_DBLN_ELEMENT);
613  G_debug(1, "dbln file: %s", file);
614 
615  fd = fopen(file, "r");
616  if (fd == NULL) { /* This may be correct, no tables defined */
617  G_debug(1, "Cannot open vector database definition file");
618  return (-1);
619  }
620 
621  row = 0;
622  rule = 0;
623  while (G_getl2(buf, 2000, fd)) {
624  row++;
625  G_chop(buf);
626  G_debug(1, "dbln: %s", buf);
627 
628  c = (char *)strchr(buf, '#');
629  if (c != NULL)
630  *c = '\0';
631 
632  if (strlen(buf) == 0)
633  continue;
634 
635  tokens = G_tokenize(buf, " |");
636  ntok = G_number_of_tokens(tokens);
637 
638  if (ntok < 2 || (ntok < 5 && rule < 1)) {
639  G_warning(_("Error in rule on row %d in %s"), row, file);
640  continue;
641  }
642 
643  strcpy(fldstr, tokens[0]);
644  strcpy(tab, tokens[1]);
645  if (ntok > 2) {
646  strcpy(col, tokens[2]);
647  if (ntok > 3) {
648  strcpy(db, tokens[3]);
649  /* allow for spaces in path names */
650  for (i=4; i < ntok-1; i++) {
651  strcat(db, " ");
652  strcat(db, tokens[i]);
653  }
654 
655  strcpy(drv, tokens[ntok-1]);
656  }
657  }
658  G_free_tokens(tokens);
659 
660  /* get field and field name */
661  fldname = strchr(fldstr, '/');
662  if (fldname != NULL) { /* field has name */
663  fldname[0] = 0;
664  fldname++;
665  }
666  fld = atoi(fldstr);
667 
668  Vect_add_dblink(dbl, fld, fldname, tab, col, db, drv);
669 
670  G_debug(1,
671  "field = %d name = %s, table = %s, key = %s, database = %s, driver = %s",
672  fld, fldname, tab, col, db, drv);
673 
674  rule++;
675  }
676  fclose(fd);
677 
678  G_debug(1, "Dblinks read");
679  return (rule);
680 }
681 
690 int Vect_write_dblinks(struct Map_info *Map)
691 {
692  int i;
693  FILE *fd;
694  char file[GPATH_MAX], buf[GPATH_MAX];
695  struct dblinks *dbl;
696 
697  G_debug(1, "Vect_write_dblinks(): map = %s, mapset = %s", Map->name,
698  Map->mapset);
699 
700  dbl = Map->dblnk;
701 
702  sprintf(file, "%s/%s/%s/%s/%s/%s", Map->gisdbase, Map->location,
703  Map->mapset, GRASS_VECT_DIRECTORY, Map->name,
704  GRASS_VECT_DBLN_ELEMENT);
705  G_debug(1, "dbln file: %s", file);
706 
707  fd = fopen(file, "w");
708  if (fd == NULL) { /* This may be correct, no tables defined */
709  G_warning(_("Unable to open vector database definition file '%s'"),
710  file);
711  return (-1);
712  }
713 
714  for (i = 0; i < dbl->n_fields; i++) {
715  if (dbl->field[i].name != NULL)
716  sprintf(buf, "%d/%s", dbl->field[i].number, dbl->field[i].name);
717  else
718  sprintf(buf, "%d", dbl->field[i].number);
719 
720  fprintf(fd, "%s %s %s %s %s\n", buf, dbl->field[i].table,
721  dbl->field[i].key, dbl->field[i].database,
722  dbl->field[i].driver);
723  G_debug(1, "%s %s %s %s %s", buf, dbl->field[i].table,
724  dbl->field[i].key, dbl->field[i].database,
725  dbl->field[i].driver);
726  }
727  fclose(fd);
728 
729  G_debug(1, "Dblinks written");
730  return 0;
731 }
732 
741 char *Vect_subst_var(const char *in, struct Map_info *Map)
742 {
743  char *c;
744  char buf[1000], str[1000];
745 
746  G_debug(3, "Vect_subst_var(): in = %s, map = %s, mapset = %s", in,
747  Map->name, Map->mapset);
748 
749 #ifdef __MINGW32__
750  char *cin;
751  cin = G_str_replace((char *)in, "/", "\\");
752  strcpy(str, cin);
753  G_free(cin);
754 #else
755  strcpy(str, in);
756 #endif
757 
758  strcpy(buf, str);
759  c = (char *)strstr(buf, "$GISDBASE");
760  if (c != NULL) {
761  *c = '\0';
762  sprintf(str, "%s%s%s", buf, Map->gisdbase, c + 9);
763  }
764 
765  strcpy(buf, str);
766  c = (char *)strstr(buf, "$LOCATION_NAME");
767  if (c != NULL) {
768  *c = '\0';
769  sprintf(str, "%s%s%s", buf, Map->location, c + 14);
770  }
771 
772  strcpy(buf, str);
773  c = (char *)strstr(buf, "$MAPSET");
774  if (c != NULL) {
775  *c = '\0';
776  sprintf(str, "%s%s%s", buf, Map->mapset, c + 7);
777  }
778 
779  strcpy(buf, str);
780  c = (char *)strstr(buf, "$MAP");
781  if (c != NULL) {
782  *c = '\0';
783  sprintf(str, "%s%s%s", buf, Map->name, c + 4);
784  }
785 
786  G_debug(3, " -> %s", str);
787  return (G_store(str));
788 }
789 
801 void Vect_set_db_updated(struct Map_info *Map)
802 {
803  if (strcmp(Map->mapset, G_mapset()) != 0) {
804  G_fatal_error(_("Bug: attempt to update map which is not in current mapset"));
805  }
806 
807  Vect_write_dblinks(Map);
808 }
dbDriver * db_start_driver_open_database(const char *drvname, const char *dbname)
Open driver/database connection.
Definition: db.c:28
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
int db_close_cursor(dbCursor *cursor)
Close cursor.
Definition: c_close_cur.c:27
struct driver * driver
Definition: driver/init.c:26
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
struct field_info * Vect_get_field(struct Map_info *Map, int field)
Get information about link to database.
Definition: field.c:404
char * G_store(const char *s)
Copy string to allocated memory.
Definition: store.c:32
int G_free_tokens(char **tokens)
Free memory allocated to tokens.
Definition: gis/token.c:98
char * Vect_subst_var(const char *in, struct Map_info *Map)
Substitute variable in string.
Definition: field.c:741
#define FALSE
Definition: dbfopen.c:117
FILE * fd
Definition: g3dcolor.c:368
int db_close_database_shutdown_driver(dbDriver *driver)
Close driver/database connection.
Definition: db.c:62
string name
Definition: render.py:1314
char ** G_tokenize(const char *buf, const char *delim)
Tokenize string.
Definition: gis/token.c:33
void db_auto_print_errors(int flag)
char * G_chop(char *line)
Chop leading and trailing white spaces:
Definition: strings.c:418
char * G__getenv2(const char *name, int loc)
Get environment variable from specific place.
Definition: env.c:331
int Vect_check_dblink(struct dblinks *p, int field)
Check if db connection exists in dblinks structure.
Definition: field.c:185
int db_get_connection(dbConnection *connection)
get default db connection settings
Definition: connect.c:49
int G_number_of_tokens(char **tokens)
Return number of tokens.
Definition: gis/token.c:76
int G_getl2(char *buf, int n, FILE *fd)
gets a line of text from a file of any pedigree
Definition: getl.c:52
int Vect_add_dblink(struct dblinks *p, int number, const char *name, const char *table, const char *key, const char *db, const char *driver)
Add new db connection to dblinks structure.
Definition: field.c:214
int Vect_map_add_dblink(struct Map_info *Map, int number, const char *name, const char *table, const char *key, const char *db, const char *driver)
Add new db connection to Map_info structure.
Definition: field.c:86
char * G_str_replace(char *buffer, const char *old_str, const char *new_str)
Replace all occurencies of old_str in buffer with new_str.
Definition: strings.c:316
void * malloc(YYSIZE_T)
int Vect_write_dblinks(struct Map_info *Map)
Write dblinks to file.
Definition: field.c:690
int db_set_default_connection(void)
Sets up database connection settings using GRASS default from dbmi.h.
Definition: default_name.c:92
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
struct field_info * Vect_get_dblink(struct Map_info *Map, int link)
Get information about link to database.
Definition: field.c:364
int Vect_map_check_dblink(struct Map_info *Map, int field)
Check if db connection exists in dblinks structure.
Definition: field.c:171
return NULL
Definition: dbfopen.c:1394
Definition: driver.h:25
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
tuple Map
Definition: render.py:1310
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
fclose(fd)
char buf2[200]
Definition: g3dcats.c:89
#define file
int db_set_string(dbString *x, const char *s)
Definition: string.c:33
struct field_info * Vect_default_field_info(struct Map_info *Map, int field, const char *field_name, int type)
Get default information about link to database for new dblink.
Definition: field.c:278
struct dblinks * Vect_new_dblinks_struct(void)
Create and init new dblinks ctructure.
Definition: field.c:45
int Vect_map_del_dblink(struct Map_info *Map, int field)
Delete db connection from Map_info structure.
Definition: field.c:125
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int Vect_read_dblinks(struct Map_info *Map)
Read dblinks to existing structure.
Definition: field.c:431
void Vect_reset_dblinks(struct dblinks *p)
Reset dblinks structure.
Definition: field.c:66
int db_open_select_cursor(dbDriver *driver, dbString *select, dbCursor *cursor, int mode)
Open select cursor.
Definition: c_openselect.c:29
void Vect_set_db_updated(struct Map_info *Map)
Rewrite &#39;dbln&#39; file.
Definition: field.c:801
void db_init_string(dbString *x)
Definition: string.c:11