GRASS Programmer's Manual  6.4.4(2014)-r
python.db Namespace Reference

Functions

def db_describe (table, args)
 Return the list of columns for a database table (interface to `db.describe -c'). More...
 
def db_connection ()
 Return the current database connection parameters (interface to `db.connect -p'). More...
 
def db_select (sql=None, filename=None, table=None, args)
 Perform SQL select statement. More...
 

Function Documentation

def python.db.db_connection ( )

Return the current database connection parameters (interface to `db.connect -p').

Example:

1 >>> grass.db_connection()
2 {'group': 'x', 'schema': '', 'driver': 'dbf', 'database': '$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/'}
Returns
parsed output of db.connect

Definition at line 73 of file db.py.

References python.core.parse_key_val(), and python.core.read_command().

def python.db.db_describe (   table,
  args 
)

Return the list of columns for a database table (interface to `db.describe -c').

Example:

1 >>> grass.db_describe('lakes')
2 {'nrows': 15279, 'cols': [['cat', 'INTEGER', '11'], ['AREA', 'DOUBLE PRECISION', '20'],
3 ['PERIMETER', 'DOUBLE PRECISION', '20'], ['FULL_HYDRO', 'DOUBLE PRECISION', '20'],
4 ['FULL_HYDR2', 'DOUBLE PRECISION', '20'], ['FTYPE', 'CHARACTER', '24'],
5 ['FCODE', 'INTEGER', '11'], ['NAME', 'CHARACTER', '99']], 'ncols': 8}
Parameters
tabletable name
args
Returns
parsed module output

Definition at line 33 of file db.py.

References python.core.fatal(), and python.core.read_command().

def python.db.db_select (   sql = None,
  filename = None,
  table = None,
  args 
)

Perform SQL select statement.

Note: one of sql, filename, or table arguments must be provided.

Examples:

1 grass.db_select(sql = 'SELECT cat,CAMPUS FROM busstopsall WHERE cat < 4')
2 
3 (('1', 'Vet School'), ('2', 'West'), ('3', 'North'))
1 grass.db_select(filename = '/path/to/sql/file')

Simplyfied usage

1 grass.db_select(table = 'busstopsall')

performs SELECT * FROM busstopsall.

Parameters
sqlSQL statement to perform (or None)
filenamename of file with SQL statements (or None)
tablename of table to query (or None)
argssee db.select arguments

Definition at line 87 of file db.py.

References python.core.fatal(), python.core.run_command(), utils.split(), and python.core.try_remove().