GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
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 <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <grass/gis.h>
20 #include <grass/temporal.h>
21 #include <grass/glocale.h>
22 
23 /*!
24  \brief Get default TGIS driver name
25 
26  \return pointer to default TGIS driver name
27  */
29 {
30  return TGISDB_DEFAULT_DRIVER;
31 }
32 
33 /*!
34  \brief Get default TGIS database name for the sqlite connection
35 
36  The default name is $GISDBASE/$LOCATION_NAME/$MAPSET/tgis/sqlite.db
37 
38  \return pointer to default TGIS database name
39  */
41 {
42  char default_connection[2048];
43 
44  snprintf(default_connection, 2048, "$GISDBASE/$LOCATION_NAME/$MAPSET/%s",
46 
47  return G_store(default_connection);
48 }
49 
50 /*!
51  \brief Sets up TGIS database connection settings using GRASS default
52 
53  \return returns DB_OK
54  */
56 {
57  dbConnection connection;
58  char db_name[2048];
59  char *tmp = tgis_get_default_database_name();
60 
61  snprintf(db_name, 2048, "%s", tmp);
62  G_free(tmp);
63 
64  if (strcmp(TGISDB_DEFAULT_DRIVER, "sqlite") == 0) {
65  connection.driverName = "sqlite";
66  connection.databaseName = db_name;
67  tgis_set_connection(&connection);
68  }
69  else
71  _("Programmer error - only SQLite driver is currently supported"));
72 
73  return DB_OK;
74 }
#define DB_OK
Definition: dbmi.h:71
void G_free(void *)
Free allocated memory.
Definition: gis/alloc.c:150
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
char * G_store(const char *)
Copy string to allocated memory.
Definition: strings.c:87
#define _(str)
Definition: glocale.h:10
char * databaseName
Definition: dbmi.h:280
char * driverName
Definition: dbmi.h:278
const char * tgis_get_default_driver_name(void)
Get default TGIS driver name.
int tgis_set_default_connection(void)
Sets up TGIS database connection settings using GRASS default.
char * tgis_get_default_database_name(void)
Get default TGIS database name for the sqlite connection.
int tgis_set_connection(dbConnection *connection)
Set Temporal GIS DB connection settings.
#define TGISDB_DEFAULT_SQLITE_PATH
Definition: temporal.h:10
#define TGISDB_DEFAULT_DRIVER
Definition: temporal.h:8