GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 }
char * G_mapset(void)
current mapset name
Definition: mapset.c:31
sprintf(buf2,"%s", G3D_CATS_ELEMENT)
char * G_store(const char *s)
Copy string to allocated memory.
Definition: store.c:32
const char * db_get_default_schema_name(void)
Get default schema name.
Definition: default_name.c:59
char * G__getenv2(const char *name, int loc)
Get environment variable from specific place.
Definition: env.c:331
int db_get_connection(dbConnection *connection)
get default db connection settings
Definition: connect.c:49
char * G_location_path(void)
Get current location directory.
Definition: location.c:37
const char * db_get_default_driver_name(void)
Get default driver name.
Definition: default_name.c:27
int db_set_connection(dbConnection *connection)
set default db connection settings
Definition: connect.c:10
const char * db_get_default_database_name(void)
Get default database name.
Definition: default_name.c:43
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
return NULL
Definition: dbfopen.c:1394
int G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
const char * db_get_default_group_name(void)
Get default group name.
Definition: default_name.c:75
int G__make_mapset_element(const char *p_element)
Create element in the current mapset.
Definition: mapset_msc.c:34
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.