GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
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 void void void G_fatal_error(const char *,...) __attribute__((format(printf
const char * tgis_get_default_driver_name(void)
Get default TGIS driver name.
void G_free(void *)
Free allocated memory.
Definition: gis/alloc.c:149
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.
char * databaseName
Definition: dbmi.h:297
char * tgis_get_default_database_name(void)
Get default TGIS database name for the sqlite connection.
#define TGISDB_DEFAULT_DRIVER
Definition: temporal.h:9
char * driverName
Definition: dbmi.h:295
int G_snprintf(char *, size_t, const char *,...) __attribute__((format(printf
#define _(str)
Definition: glocale.h:10
char * G_store(const char *)
Copy string to allocated memory.
Definition: strings.c:87
#define DB_OK
Definition: dbmi.h:71