<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>GRASS GIS: v.db.connect</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" href="grassdocs.css" type="text/css"> </head> <body bgcolor="white"> <img src="grass_logo.png" alt="GRASS logo"><hr align=center size=6 noshade> <h2>NAME</h2> <em><b>v.db.connect</b></em> - Prints/sets DB connection for a vector map to attribute table. <h2>KEYWORDS</h2> vector, database, attribute table <h2>SYNOPSIS</h2> <b>v.db.connect</b><br> <b>v.db.connect help</b><br> <b>v.db.connect</b> [-<b>pgcod</b>] <b>map</b>=<em>name</em> [<b>driver</b>=<em>name</em>] [<b>database</b>=<em>name</em>] [<b>table</b>=<em>name</em>] [<b>key</b>=<em>name</em>] [<b>layer</b>=<em>integer</em>] [--<b>verbose</b>] [--<b>quiet</b>] <h3>Flags:</h3> <DL> <DT><b>-p</b></DT> <DD>Print all map connection parameters and exit</DD> <DT><b>-g</b></DT> <DD>Print all map connection parameters and exit in shell script style</DD> <DD>Format: layer[/layer name] table key database driver</DD> <DT><b>-c</b></DT> <DD>Print types/names of table columns for specified layer and exit</DD> <DT><b>-o</b></DT> <DD>Overwrite connection parameter for certain layer</DD> <DT><b>-d</b></DT> <DD>Delete connection for certain layer (not the table)</DD> <DT><b>--verbose</b></DT> <DD>Verbose module output</DD> <DT><b>--quiet</b></DT> <DD>Quiet module output</DD> </DL> <h3>Parameters:</h3> <DL> <DT><b>map</b>=<em>name</em></DT> <DD>Name of input vector map</DD> <DT><b>driver</b>=<em>name</em></DT> <DD>Driver name</DD> <DD>Options: <em>odbc,dbf,pg,sqlite,mesql,mysql,ogr</em></DD> <DD>Default: <em>dbf</em></DD> <DT><b>database</b>=<em>name</em></DT> <DD>Database name</DD> <DD>Default: <em>$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/</em></DD> <DT><b>table</b>=<em>name</em></DT> <DD>Table name</DD> <DT><b>key</b>=<em>name</em></DT> <DD>Key column name</DD> <DD>Must refer to an integer column</DD> <DD>Default: <em>cat</em></DD> <DT><b>layer</b>=<em>integer</em></DT> <DD>Layer number</DD> <DD>A single vector map can be connected to multiple database tables. This number determines which table to use.</DD> <DD>Default: <em>1</em></DD> </DL> <h2>DESCRIPTION</h2> <em>v.db.connect</em> prints or sets database connection for a vector map. The user can add or remove link to attribute table on the certain layer. <h2>NOTE</h2> If parameters for database connection are already set with <a HREF="db.connect.html">db.connect</a>, they are taken as default values and do not need to be spcified each time. <p> When printing database connection (<em>p</em> or <em>g</em> flag) the parameter <em>layer</em> is ignored, i.e. <b>all</b> connections are printed to the output. <p> <b>Attention:</b> Removing a vector map will also delete all tables linked to it! If you use <a HREF="db.connect.html">v.db.connect </a>to link further tables to your map, it is advisable to make a copy from those tables first and connect the copied tables to the vector map (see also <a HREF="v.overlay.html">v.overlay</a>). <h2>EXAMPLE</h2> <h3>Print database connection</h3> Print all database connection parameters for vector map. <div class="code"><pre> v.db.connect -p map=roads </pre></div> <p> Print column types and names of table linked to vector map. <div class="code"><pre> v.db.connect -c map=roads </pre></div> <h3>Connect vector map to database (DBF driver)</h3> Connect vector map to DBF table without or with variables.<br> <p> Using default DB connection: <div class="code"><pre> v.db.connect map=vectormap table=table </pre></div> <p> Using hardcoded path to DBF directory (not recommended):<br> <div class="code"><pre> v.db.connect map=vectormap table=table database=/home/user/grassdata/spearfish60/PERMANENT/dbf </pre></div> <p> Using variable as DBF directory definition, single quotes must be used:<br> <div class="code"><pre> v.db.connect map=vectormap table=table database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/' </pre></div> <p> Connect vector map layer 2 and key ID to database with variables (note: if needed, single quotes must be used for the <em>database</em> parameter): <div class="code"><pre> v.db.connect map=vectormap table=table layer=2 key=ID </pre></div> <h3>Connect vector map to database (MySQL driver)</h3> <div class="code"><pre> # note: connection which requires password db.connect driver=mysql database="host=dbserver.foo.org,dbname=my_database" db.login user=joshua [password=xxx] # ... or enter password interactively. db.tables -p # connect external table to layer 2: v.db.connect map=my_map table=my_mysql_table key=baz layer=2 v.db.connect -p my_map </pre></div> <h3>Connect vector map to database (PostgreSQL driver)</h3> <div class="code"><pre> # note: connection without password being asked v.db.connect map=vectormap table=table layer=1 key=oid driver=pg \ database="host=myserver.itc.it,dbname=mydb,user=name" \ table=mytable key=id </pre></div> <H3>Store geometry in GRASS but attributes in PostgreSQL</H3> This example illustrated a mixed data storage with possibility top update attributes in external PostgreSQL database: <div class="code"><pre> # Check current settings for attribute storage: db.connect -p # Import table from PostgreSQL to new map # (NOTE: output map name needs to be different from table name in # case that GRASS is connected to PostgreSQL): v.in.db driver=pg database="host=localhost,dbname=meteo" \ table=mytable x=lon y=lat key=cat out=mytable v.db.connect map=mytable -p # Cancel table connection between map and attribute table: v.db.connect map=mytable -d v.db.connect map=mytable -p # Drop table which was replicated due to import: db.tables -p echo "DROP TABLE mytable" | db.execute db.tables -p # reconnect map to table in PostgreSQL: v.db.connect map=mytable driver=pg database="host=localhost,dbname=meteo" \ table=mytable key=cat # Now the geometry is stored in GRASS while the attributes are stored # in PostgreSQL. </pre></div> An alternative is to create a "view" of only ID, x, y [,z] columns and to use <a HREF="v.in.db.html">v.in.db</a> on this view, then connect the original table to the geometry. This will be faster if the original table is very large. <H3>Store geometry in GRASS but attributes in PostGIS</H3> This example illustrated a mixed data storage with possibility top update attributes in external PostGIS database: <div class="code"><pre> # Check current settings for attribute storage: db.connect -p # Import table from PostGIS to new map # (NOTE: output map name needs to be different from table name in # case that GRASS is connected to PostGIS): v.in.db driver=pg database="host=localhost,dbname=meteo" \ table=mytable x="x(geom)" y="y(geom)" key=cat out=mytable v.db.connect map=mytable -p # Cancel table connection between map and attribute table: v.db.connect map=mytable -d v.db.connect map=mytable -p # Drop table which was replicated due to import: db.tables -p echo "DROP TABLE mytable" | db.execute db.tables -p # reconnect map to table in PostGIS: v.db.connect map=mytable driver=pg database="host=localhost,dbname=meteo" \ table=mytable key=cat # Now the geometry is stored in GRASS while the attributes are stored # in PostGIS. </pre></div> <h2>SEE ALSO</h2> <a HREF="db.connect.html">db.connect</a>, <a HREF="db.copy.html">db.copy</a>, <a HREF="db.tables.html">db.tables</a>, <a HREF="v.db.addtable.html">v.db.addtable</a>, <a HREF="v.db.droptable.html">v.db.droptable</a>, <a HREF="v.db.addcol.html">v.db.addcol</a>, <a HREF="v.db.dropcol.html">v.db.dropcol</a>, <a HREF="v.external.html">v.external</a>, <a HREF="v.in.db.html">v.in.db</a>, <a HREF="v.overlay.html">v.overlay</a> <h2>AUTHOR</h2> Radim Blazek, ITC-Irst, Trento, Italy <p><i>Last changed: $Date: 2007-09-10 08:58:58 +0200 (Mon, 10 Sep 2007) $</i> <HR> <P><a href="index.html">Main index</a> - <a href="vector.html">vector index</a> - <a href="full_index.html">Full index</a></P> <P>© 2003-2008 <a href="http://grass.osgeo.org">GRASS Development Team</a></p> </body> </html>