[GRASS-SVN] r53598 - grass/trunk/db/db.databases

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Oct 28 11:09:04 PDT 2012


Author: martinl
Date: 2012-10-28 11:09:03 -0700 (Sun, 28 Oct 2012)
New Revision: 53598

Modified:
   grass/trunk/db/db.databases/db.databases.html
   grass/trunk/db/db.databases/main.c
Log:
db.databases: module now working for SQLite and PostgreSQL driver
              manual extended


Modified: grass/trunk/db/db.databases/db.databases.html
===================================================================
--- grass/trunk/db/db.databases/db.databases.html	2012-10-28 18:05:18 UTC (rev 53597)
+++ grass/trunk/db/db.databases/db.databases.html	2012-10-28 18:09:03 UTC (rev 53598)
@@ -1,8 +1,38 @@
 <h2>DESCRIPTION</h2>
 
-<em>db.databases</em> lists all databases for a given driver. Supported drivers
-are dbf, shp, odbc and pg.
+<em>db.databases</em> lists all databases for a given <b>driver</b>
+and optionally <b>location</b>. 
 
+<h2>NOTES</h2>
+
+Currently supported database drivers are
+<em><a href="grass-sqlite.html">SQLite</a></em>, <em><a href="grass-pg.html">PostgreSQL</a></em>,
+and <em><a href="grass-odbc.html">ODBC</a></em>.
+
+<p>
+Default <b>location</b> for SQLite driver is the full path for the
+current mapset. For PostgreSQL driver it's empty connection string.
+
+<h2>EXAMPLES</h2>
+
+List SQLite databases in the current mapset:
+
+<div class="code"><pre>
+db.databases driver=sqlite
+</pre></div>
+
+List SQLite databases in the given directory:
+
+<div class="code"><pre>
+db.databases driver=sqlite location=/opt/sqlite
+</pre></div>
+
+List PostgreSQL databases from database server running on given port:
+
+<div class="code"><pre>
+db.databases driver=pg location="host=server_name port=5333"
+</pre></div>
+
 <h2>SEE ALSO</h2>
 
 <em><a href="db.columns.html">db.columns</a>,
@@ -10,11 +40,16 @@
 <a href="db.drivers.html">db.drivers</a>,
 <a href="db.execute.html">db.execute</a>,
 <a href="db.login.html">db.login</a>,
-<a href="db.tables.html">db.tables</a>,
-<a href="sql.html">GRASS SQL interface</a></em>
+<a href="db.tables.html">db.tables</a>
+</em>
 
+<p>
+<a href="sql.html">GRASS SQL interface</a>
+
 <h2>AUTHOR</h2>
 
-Radim Blazek, ITC-Irst, Trento, Italy
+Radim Blazek, ITC-Irst, Trento, Italy<br>
+Updated for GRASS 7 by Martin Landa, Czech Technical University in Prague, Czech Republic
 
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>

Modified: grass/trunk/db/db.databases/main.c
===================================================================
--- grass/trunk/db/db.databases/main.c	2012-10-28 18:05:18 UTC (rev 53597)
+++ grass/trunk/db/db.databases/main.c	2012-10-28 18:09:03 UTC (rev 53598)
@@ -5,11 +5,11 @@
  * AUTHOR(S):    Radim Blazek <radim.blazek gmail.com> (original contributor)
  *               Glynn Clements <glynn gclements.plus.com>, Markus Neteler <neteler itc.it>
  * PURPOSE:      lists all databases for a given driver
- * COPYRIGHT:    (C) 2002-2006 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2002-2006, 2012 by the GRASS Development Team
  *
- *               This program is free software under the GNU General Public
- *               License (>=v2). Read the file COPYING that comes with GRASS
- *               for details.
+ *               This program is free software under the GNU General
+ *               Public License (>=v2). Read the file COPYING that
+ *               comes with GRASS for details.
  *
  *****************************************************************************/
 
@@ -18,18 +18,15 @@
 #include <grass/gis.h>
 #include <grass/glocale.h>
 
-
 struct
 {
     char *driver;
     char *location;
 } parms;
 
-
 /* function prototypes */
 static void parse_command_line(int, char **);
 
-
 int main(int argc, char **argv)
 {
     dbDriver *driver;
@@ -50,17 +47,19 @@
     if (driver == NULL)
 	G_fatal_error(_("Unable to start driver <%s>"), parms.driver);
 
-    if (db_list_databases(driver, &locations, nlocs, &handles, &count) !=
-	DB_OK)
-	G_fatal_error(_("Unable to list databases"));
-
+    if (db_list_databases(driver, &locations,
+                          nlocs, &handles, &count) != DB_OK)
+        G_fatal_error(_("Unable to list databases"));
+    
     db_shutdown_driver(driver);
 
     for (i = 0; i < count; i++) {
-	fprintf(stdout, "%s", db_get_handle_dbname(&handles[i]));
-	fprintf(stdout, "\n");
+	fprintf(stdout, "%s\n", db_get_handle_dbname(&handles[i]));
     }
 
+    if (count < 1)
+        G_important_message(_("No databases found"));
+                            
     exit(EXIT_SUCCESS);
 }
 
@@ -75,26 +74,31 @@
 
     driver = G_define_standard_option(G_OPT_DB_DRIVER);
     driver->options = db_list_drivers();
-
+    driver->answer = (char *) db_get_default_driver_name();
+    driver->guisection = _("Connection");
+    
     location = G_define_option();
     location->key = "location";
     location->type = TYPE_STRING;
     location->required = NO;
-    location->multiple = YES;
-    location->description = _("Location name");
+    /* location->multiple = YES; ? */
+    location->label = _("Location");
+    location->description = _("Path for SQLite driver, or connection string "
+                              "for PostgreSQL driver");
+    location->key_desc = "name";
+    location->guisection = _("Connection");
 
-
     /* Set description */
     module = G_define_module();
     G_add_keyword(_("database"));
     G_add_keyword(_("attribute table"));
     G_add_keyword(_("SQL"));
     module->description =
-	_("List all databases for a given driver and location.");
+	_("Lists all databases for a given driver and location.");
 
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
 
     parms.driver = driver->answer;
-    parms.location = location->answer;
+    parms.location = location->answer ? location->answer : "";
 }



More information about the grass-commit mailing list