GRASS GIS 7 Programmer's Manual  7.7.svn(2018)-r73679
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
temporal/lib/default_name.c
Go to the documentation of this file.
1 /*!
2  \file lib/db/dbmi_base/default_name.c
3 
4  \brief Temporal GIS Library (base) - default settings
5 
6  (C) 2012-2014 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Soeren Gebbert
12  Code is based on the dbmi library written by
13  Joel Jones (CERL/UIUC) and Radim Blazek
14 */
15 
16 #include <stdlib.h>
17 #include <string.h>
18 #include <grass/gis.h>
19 #include <grass/temporal.h>
20 #include <grass/glocale.h>
21 
22 /*!
23  \brief Get default TGIS driver name
24 
25  \return pointer to default TGIS driver name
26 */
28 {
29  return TGISDB_DEFAULT_DRIVER;
30 }
31 
32 /*!
33  \brief Get default TGIS database name for the sqlite connection
34 
35  The default name is $GISDBASE/$LOCATION_NAME/$MAPSET/tgis/sqlite.db
36 
37  \return pointer to default TGIS database name
38 */
40 {
41  char default_connection[2048];
42 
43  G_snprintf(default_connection, 2048, "$GISDBASE/$LOCATION_NAME/$MAPSET/%s",
45 
46  return G_store(default_connection);
47 }
48 
49 /*!
50  \brief Sets up TGIS database connection settings using GRASS default
51 
52  \return returns DB_OK
53 */
55 {
56  dbConnection connection;
57  char db_name[2048];
58  char *tmp = tgis_get_default_database_name();
59 
60  G_snprintf(db_name, 2048, "%s", tmp);
61  G_free(tmp);
62 
63  if (strcmp(TGISDB_DEFAULT_DRIVER, "sqlite") == 0) {
64  connection.driverName = "sqlite";
65  connection.databaseName = db_name;
66  tgis_set_connection(&connection);
67  }
68  else
69  G_fatal_error(_("Programmer error - only SQLite driver is currently supported"));
70 
71 
72  return DB_OK;
73 }
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:149
char * tgis_get_default_database_name(void)
Get default TGIS database name for the sqlite connection.
const char * tgis_get_default_driver_name(void)
Get default TGIS driver name.
char * G_store(const char *s)
Copy string to allocated memory.
Definition: strings.c:86
int tgis_set_default_connection(void)
Sets up TGIS database connection settings using GRASS default.
#define TGISDB_DEFAULT_SQLITE_PATH
Definition: temporal.h:11
int tgis_set_connection(dbConnection *connection)
Set Temporal GIS DB connection settings.
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
Definition: gis/error.c:160
int G_snprintf(char *str, size_t size, const char *fmt,...)
snprintf() clone.
Definition: snprintf.c:43
char * databaseName
Definition: dbmi.h:297
#define TGISDB_DEFAULT_DRIVER
Definition: temporal.h:9
char * driverName
Definition: dbmi.h:295
#define _(str)
Definition: glocale.h:13
#define DB_OK
Definition: dbmi.h:71