.TH v.db.connect 1grass "" "GRASS 6.4.4" "Grass User's Manual" .SH NAME \fI\fBv.db.connect\fR\fR - Prints/sets DB connection for a vector map to attribute table. .SH KEYWORDS vector, database, attribute table .SH SYNOPSIS \fBv.db.connect\fR .br \fBv.db.connect help\fR .br \fBv.db.connect\fR [\-\fBpglcod\fR] \fBmap\fR=\fIname\fR [\fBdriver\fR=\fIname\fR] [\fBdatabase\fR=\fIname\fR] [\fBtable\fR=\fIname\fR] [\fBkey\fR=\fIname\fR] [\fBlayer\fR=\fIinteger\fR] [\fBfs\fR=\fIcharacter\fR] [\-\-\fBverbose\fR] [\-\-\fBquiet\fR] .SS Flags: .IP "\fB\-p\fR" 4m .br Print all map connection parameters and exit .IP "\fB\-g\fR" 4m .br Print all map connection parameters and exit in shell script style .br Format: layer[/layer name] table key database driver .IP "\fB\-l\fR" 4m .br When printing, limit to layer specified by the layer option .IP "\fB\-c\fR" 4m .br Print types/names of table columns for specified layer and exit .IP "\fB\-o\fR" 4m .br Overwrite connection parameter for certain layer .IP "\fB\-d\fR" 4m .br Delete connection for certain layer (not the table) .IP "\fB\-\-verbose\fR" 4m .br Verbose module output .IP "\fB\-\-quiet\fR" 4m .br Quiet module output .PP .SS Parameters: .IP "\fBmap\fR=\fIname\fR" 4m .br Name of input vector map .IP "\fBdriver\fR=\fIname\fR" 4m .br Driver name .br Options: \fIpg,dbf,ogr,odbc,mysql,sqlite\fR .br Default: \fIdbf\fR .IP "\fBdatabase\fR=\fIname\fR" 4m .br Database name .br Default: \fI$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/\fR .IP "\fBtable\fR=\fIname\fR" 4m .br Table name .IP "\fBkey\fR=\fIname\fR" 4m .br Key column name .br Must refer to an integer column .br Default: \fIcat\fR .IP "\fBlayer\fR=\fIinteger\fR" 4m .br Layer number .br A single vector map can be connected to multiple database tables. This number determines which table to use. .br Default: \fI1\fR .IP "\fBfs\fR=\fIcharacter\fR" 4m .br Field separator .br Field separator for shell script style output .br Default: \fI \fR .PP .SH DESCRIPTION \fIv.db.connect\fR prints or sets database connection for a vector map. The user can add or remove link to attribute table on the certain layer. .SH NOTE If parameters for database connection are already set with db.connect, they are taken as default values and do not need to be spcified each time. .PP When printing database connection (\fIp\fR or \fIg\fR flag) the parameter \fIlayer\fR is ignored, i.e. \fBall\fR connections are printed to the output, unless \fIl\fR flag is given. .PP \fBAttention:\fR Removing a vector map will also delete all tables linked to it! If you use v.db.connect 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 v.overlay). .SH EXAMPLE .SS Print database connection Print all database connection parameters for vector map. \fC .DS .br v.db.connect \-p map=roads .br .DE \fR .PP Print column types and names of table linked to vector map. \fC .DS .br v.db.connect \-c map=roads .br .DE \fR .SS Connect vector map to database (DBF driver) Connect vector map to DBF table without or with variables. .br .PP Using default DB connection: \fC .DS .br v.db.connect map=vectormap table=table .br .DE \fR .PP Using hardcoded path to DBF directory (not recommended): .br \fC .DS .br v.db.connect map=vectormap table=table \(rs .br database=/home/user/grassdata/spearfish60/PERMANENT/dbf .br .DE \fR .PP Using variable as DBF directory definition, single quotes must be used: .br \fC .DS .br v.db.connect map=vectormap table=table \(rs .br database='$GISDBASE/$LOCATION_NAME/$MAPSET/dbf/' .br .DE \fR .PP Connect vector map layer 2 and key ID to database with variables (note: if needed, single quotes must be used for the \fIdatabase\fR parameter): \fC .DS .br v.db.connect map=vectormap table=table layer=2 key=ID .br .DE \fR .SS Connect vector map to database (SQLite driver) Very similar to DBF driver example above. \fC .DS .br db.connect driver=sqlite database='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite.db' .br db.tables \-p .br v.db.connect map=vectormap table=table driver=sqlite \(rs .br database='$GISDBASE/$LOCATION_NAME/$MAPSET/sqlite.db' .br v.db.connect \-p map=vectormap .br .DE \fR .SS Connect vector map to database (MySQL driver) \fC .DS .br # note: connection which requires password .br db.connect driver=mysql database="host=dbserver.foo.org,dbname=my_database" .br db.login user=joshua [password=xxx] .br # ... or enter password interactively. .br .br db.tables \-p .br .br # connect external table to layer 2: .br v.db.connect map=my_map table=my_mysql_table key=baz layer=2 .br v.db.connect \-p my_map .br .DE \fR .SS Connect vector map to database (PostgreSQL driver) \fC .DS .br # note: connection without password being asked .br v.db.connect map=vectormap table=table layer=1 key=oid driver=pg \(rs .br database="host=myserver.itc.it,dbname=mydb,user=name" \(rs .br table=mytable key=id .br .DE \fR .SS Store geometry in GRASS but attributes in PostgreSQL This example illustrated a mixed data storage with possibility top update attributes in external PostgreSQL database: \fC .DS .br # Check current settings for attribute storage: .br db.connect \-p .br .br # Import table from PostgreSQL to new map .br # (NOTE: output map name needs to be different from table name in .br # case that GRASS is connected to PostgreSQL): .br v.in.db driver=pg database="host=localhost,dbname=meteo" \(rs .br table=mytable x=lon y=lat key=cat out=mytable .br .br v.db.connect map=mytable \-p .br .br # Cancel table connection between map and attribute table: .br v.db.connect map=mytable \-d .br v.db.connect map=mytable \-p .br .br # Drop table which was replicated due to import: .br db.tables \-p .br echo "DROP TABLE mytable" | db.execute .br db.tables \-p .br .br # reconnect map to table in PostgreSQL: .br v.db.connect map=mytable driver=pg database="host=localhost,dbname=meteo" \(rs .br table=mytable key=cat .br .br # Now the geometry is stored in GRASS while the attributes are stored .br # in PostgreSQL. .br .DE \fR An alternative is to create a "view" of only ID, x, y [,z] columns and to use v.in.db on this view, then connect the original table to the geometry. This will be faster if the original table is very large. .SS Store geometry in GRASS but attributes in PostGIS This example illustrated a mixed data storage with possibility top update attributes in external PostGIS database: \fC .DS .br # Check current settings for attribute storage: .br db.connect \-p .br .br # Import table from PostGIS to new map .br # (NOTE: output map name needs to be different from table name in .br # case that GRASS is connected to PostGIS): .br v.in.db driver=pg database="host=localhost,dbname=meteo" \(rs .br table=mytable x="x(geom)" y="y(geom)" key=cat out=mytable .br .br v.db.connect map=mytable \-p .br .br # Cancel table connection between map and attribute table: .br v.db.connect map=mytable \-d .br v.db.connect map=mytable \-p .br .br # Drop table which was replicated due to import: .br db.tables \-p .br echo "DROP TABLE mytable" | db.execute .br db.tables \-p .br .br # reconnect map to table in PostGIS: .br v.db.connect map=mytable driver=pg database="host=localhost,dbname=meteo" \(rs .br table=mytable key=cat .br .br # Now the geometry is stored in GRASS while the attributes are stored .br # in PostGIS. .br .DE \fR .SH SEE ALSO \fI db.connect, db.copy, db.tables, v.db.addtable, v.db.droptable, v.db.addcol, v.db.dropcol, v.external, v.in.db, v.overlay \fR .SH AUTHOR Radim Blazek, ITC-Irst, Trento, Italy .PP \fILast changed: $Date: 2011-11-08 12:29:50 +0100 (Tue, 08 Nov 2011) $\fR .PP Full index .PP © 2003-2014 GRASS Development Team