[GRASS-SVN] r51931 - grass/trunk/lib/python

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 2 03:35:23 PDT 2012


Author: martinl
Date: 2012-06-02 03:35:22 -0700 (Sat, 02 Jun 2012)
New Revision: 51931

Modified:
   grass/trunk/lib/python/db.py
Log:
pythonlib: db_select() returns tuple of tuples


Modified: grass/trunk/lib/python/db.py
===================================================================
--- grass/trunk/lib/python/db.py	2012-06-02 10:16:38 UTC (rev 51930)
+++ grass/trunk/lib/python/db.py	2012-06-02 10:35:22 UTC (rev 51931)
@@ -99,12 +99,27 @@
 
     Note: one of <em>sql</em>, <em>filename</em>, or <em>table</em>
     must be provided.
+    
+    Examples:
+    
+    \code
+    grass.db_select(sql = 'SELECT cat,CAMPUS FROM busstopsall WHERE cat < 4')
 
-    SQL statements:
+    (('1', 'Vet School'), ('2', 'West'), ('3', 'North'))
+    \endcode
+    
+    \code
+     grass.db_select(filename = '/path/to/sql/file')
+    \endcode
 
+    Simplyfied usage 
+    
     \code
+    grass.db_select(table = 'busstopsall')
     \endcode
-    
+
+    performs <tt>SELECT cat,CAMPUS FROM busstopsall</tt>.
+
     @param sql SQL statement to perform (or None)
     @param filename name of file with SQL statements (or None)
     @param table name of table to query (or None)
@@ -120,7 +135,10 @@
     else:
         fatal(_("Programmer error: '%s', '%s', or '%s' must be provided") %
               'sql', 'filename', 'table')
-        
+    
+    if 'fs' not in args:
+        args['fs'] = '|'
+    
     ret = run_command('db.select', quiet = True,
                       flags = 'c',
                       output = fname,
@@ -130,8 +148,9 @@
         fatal(_("Fetching data failed"))
     
     ofile = open(fname)
-    result = map(lambda x: x.rstrip(os.linesep), ofile.readlines())
+    result = map(lambda x: tuple(x.rstrip(os.linesep).split(args['fs'])),
+                 ofile.readlines())
     ofile.close()
     try_remove(fname)
         
-    return result
+    return tuple(result)



More information about the grass-commit mailing list