GRASS Programmer's Manual 6.4.1(2011)
default_name.c
Go to the documentation of this file.
00001 
00015 #include <stdlib.h>
00016 #include <string.h>
00017 #include <grass/gis.h>
00018 #include <grass/dbmi.h>
00019 #include <grass/glocale.h>
00020 
00027 const char *db_get_default_driver_name(void)
00028 {
00029     const char *drv;
00030 
00031     if ((drv = G__getenv2("DB_DRIVER", G_VAR_MAPSET)))
00032         return G_store(drv);
00033 
00034     return NULL;
00035 }
00036 
00043 const char *db_get_default_database_name(void)
00044 {
00045     const char *drv;
00046 
00047     if ((drv = G__getenv2("DB_DATABASE", G_VAR_MAPSET)))
00048         return G_store(drv);
00049 
00050     return NULL;
00051 }
00052 
00059 const char *db_get_default_schema_name(void)
00060 {
00061     const char *sch;
00062 
00063     if ((sch = G__getenv2("DB_SCHEMA", G_VAR_MAPSET)))
00064         return G_store(sch);
00065 
00066     return NULL;
00067 }
00068 
00075 const char *db_get_default_group_name(void)
00076 {
00077     const char *gr;
00078 
00079     if ((gr = G__getenv2("DB_GROUP", G_VAR_MAPSET)))
00080         return G_store(gr);
00081 
00082     return NULL;
00083 }
00084 
00092 int db_set_default_connection(void)
00093 {
00094     dbConnection connection;
00095     char buf[GPATH_MAX];
00096 
00097     G_debug(1,
00098             "Creating new default DB params with db_set_default_connection()");
00099 
00100     /* is this really needed ? */
00101     db_get_connection(&connection);
00102 
00103     if (strcmp(DB_DEFAULT_DRIVER, "dbf") == 0) {
00104         /* Set default values and create dbf db dir */
00105 
00106         connection.driverName = "dbf";
00107         connection.databaseName = "$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/";
00108         db_set_connection(&connection);
00109 
00110         sprintf(buf, "%s/%s/dbf", G_location_path(), G_mapset());
00111         G__make_mapset_element("dbf");
00112     }
00113     else if (strcmp(DB_DEFAULT_DRIVER, "sqlite") == 0) {
00114         /* Set default values and create dbf db dir */
00115 
00116         connection.driverName = "sqlite";
00117         /*
00118          * TODO: Use one DB for entire mapset (LFS problems?)
00119          *      or per-map DBs in $MASPET/vector/mapname/sqlite.db (how to set that here?)
00120          *      or $MAPSET/sqlite/mapname.sql as with dbf?
00121          */
00122         connection.databaseName =
00123             "$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite.db";
00124         db_set_connection(&connection);
00125     }
00126     else
00127         G_fatal_error(_("Programmer error"));
00128 
00129     return DB_OK;
00130 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines