GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
default_name.c
Go to the documentation of this file.
1 
15 #include <stdlib.h>
16 #include <string.h>
17 #include <grass/gis.h>
18 #include <grass/dbmi.h>
19 #include <grass/glocale.h>
20 
27 const char *db_get_default_driver_name(void)
28 {
29  const char *drv;
30 
31  if ((drv = G__getenv2("DB_DRIVER", G_VAR_MAPSET)))
32  return G_store(drv);
33 
34  return NULL;
35 }
36 
44 {
45  const char *drv;
46 
47  if ((drv = G__getenv2("DB_DATABASE", G_VAR_MAPSET)))
48  return G_store(drv);
49 
50  return NULL;
51 }
52 
59 const char *db_get_default_schema_name(void)
60 {
61  const char *sch;
62 
63  if ((sch = G__getenv2("DB_SCHEMA", G_VAR_MAPSET)))
64  return G_store(sch);
65 
66  return NULL;
67 }
68 
75 const char *db_get_default_group_name(void)
76 {
77  const char *gr;
78 
79  if ((gr = G__getenv2("DB_GROUP", G_VAR_MAPSET)))
80  return G_store(gr);
81 
82  return NULL;
83 }
84 
93 {
94  dbConnection connection;
95  char buf[GPATH_MAX];
96 
97  G_debug(1,
98  "Creating new default DB params with db_set_default_connection()");
99 
100  /* is this really needed ? */
101  db_get_connection(&connection);
102 
103  if (strcmp(DB_DEFAULT_DRIVER, "dbf") == 0) {
104  /* Set default values and create dbf db dir */
105 
106  connection.driverName = "dbf";
107  connection.databaseName = "$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/";
108  db_set_connection(&connection);
109 
110  sprintf(buf, "%s/%s/dbf", G_location_path(), G_mapset());
111  G__make_mapset_element("dbf");
112  }
113  else if (strcmp(DB_DEFAULT_DRIVER, "sqlite") == 0) {
114  /* Set default values and create dbf db dir */
115 
116  connection.driverName = "sqlite";
117  /*
118  * TODO: Use one DB for entire mapset (LFS problems?)
119  * or per-map DBs in $MASPET/vector/mapname/sqlite.db (how to set that here?)
120  * or $MAPSET/sqlite/mapname.sql as with dbf?
121  */
122  connection.databaseName =
123  "$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite.db";
124  db_set_connection(&connection);
125  }
126  else
127  G_fatal_error(_("Programmer error"));
128 
129  return DB_OK;
130 }