[GRASS-user] Best way to reconnect tables in grass' databse

Hi All!

I think I have questioned something similar but not quite the same
several months ago.

I moved the "grassdb" foldes (with all of its locations of course) in
another directory and thus, the absolute database path has been changed.

I need to re-connect all database tables. I think I am doing the right
thing by trying to use the v.db.reconnect.all module. However, I am a
bit confused about the appropriate format to be used for the
"old_database", "new_database" parameters.

Isn't it the absolute paths that are required?

Is there a better way to ensure integrity of the grass database while
moving it on another place(=directory)?

Thank you, Nikos

Nikos Alexandris wrote:

I think I have questioned something similar but not quite the same
several months ago.

I moved the "grassdb" foldes (with all of its locations of course) in
another directory and thus, the absolute database path has been changed.

I need to re-connect all database tables. I think I am doing the right
thing by trying to use the v.db.reconnect.all module. However, I am a
bit confused about the appropriate format to be used for the
"old_database", "new_database" parameters.

Isn't it the absolute paths that are required?

For old_database=, it needs to be the exact string which appears as
the fourth field of "v.db.connect -g", including the trailing "/"
character if it is present.

For new_database=, the value is passed directly to v.db.connect's
database= option, so it can be in any form which the driver accepts,
including variable substitutions for the DBF driver.

The default database for the DBF driver is literally:

  $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/

By "literally", I mean that's how it appears in the "dbln" file; the
driver expands the variables whenever you access the data.

Any such maps don't need to be explicitly reconnected if you move the
database.

--
Glynn Clements <glynn@gclements.plus.com>

On Wed, 2008-11-26 at 18:52 +0100, Nikos Alexandris wrote:

Hi All!

I think I have questioned something similar but not quite the same
several months ago.

I moved the "grassdb" foldes (with all of its locations of course) in
another directory and thus, the absolute database path has been changed.

I need to re-connect all database tables. I think I am doing the right
thing by trying to use the v.db.reconnect.all module. However, I am a
bit confused about the appropriate format to be used for the
"old_database", "new_database" parameters.

Isn't it the absolute paths that are required?

Is there a better way to ensure integrity of the grass database while
moving it on another place(=directory)?

Thank you, Nikos

*** NOTE ***
Feel really tired today and I was writing The Text (below) before
Glynn's reply showed-up in my Inbox!
I hope you see it's comical side and don't get offended :slight_smile:
*** NOTE ***

OK,

I don't understand or the descriptions and the names of the modules
v.db.connect and v.db.reconnect.all are a bit "cryptic" :-p

* v.db.connect is to be used on one map. And gives with "-g" the
following information: layer[/layer name] table key database driver

* v.db.reconnect.all is to be used for all vector maps present on the
database (as the name of this modules implies).

Question: How should a beginner understand how to fill in the
"old_database", "new_database" parameters if the print out of
v.db.connect is for one map (including several variables) and
v.db.reconnect.all expects something (I suppose one variable or 2?) for
all maps?

I try different things but I only get errors.

An example:

# print current db.connect settings
db.connect -p

driver:sqlite
database:/geo/grassdb/peloponnese/hgrs87/PERMANENT/sqlite.db

# some table present in the database
db.tables -p | grep water

samples_water

# connection settings of this table (as it was set before moving grassdb
in another directory
v.db.connect -g samples_water

1 samples_water
cat /home/nik/grassdb/peloponnese/hgrs87/PERMANENT/sqlite.db sqlite

# of course the old database contains several tables/vector maps
# How would I go about to v.db.reconnect.all at once?

# Trying to figure-out how this module works
# reading the description
v.db.reconnect.all help

[...]
Usage:
v.db.reconnect.all old_database=string new_database=string
   [old_schema=string] [new_schema=string] [--verbose] [--quiet]
[...]
old_database Name of old database. The database must be in form
printed by v.db.connect -g, i.e. with substituted variables
[...]

# shrug!
# hmmm, ok... so I need to look the "v.db.connect -g" result... !?
# wait a second, the v.db.connect -g result gives for one map several
stuff
# ok... I am a beginner on this. But some programer wrote it, he tested
it, others use it. It should work. Yes, it works! I've read it in one
message in the mailing list. There was no example though. It doesn't
matter. So, Niko, think logical :slight_smile:
# What on earth should I fill in in the old_database parameter. But it's
clearly stated: "The database must be in form printed by v.db.connect
-g, i.e. with substituted variables"

# ok, lets try
# I will use the output of "v.db.connect -g" from some map. I'll take my
"water_samples"
# OK, I think I'll pick all variables that refer clearly to the database
itself.

# ??? -- What am I talking now... ?
# Ahh, go ahead and try it.
...
...

# STOP-STOP-STOP here. STOP right here - right now.
# I just read Glynn's mail :slight_smile: Let's read first carefuly his reply.
# Oh... I really like this community.
# I have to admit that beginners/intermediate end-users (including me)
ask sometimes things for which they could easily get an answer if they
tried a bit more :slight_smile:

(*possibly* to be continued :wink:

Cheers, Nikos

On Wed, 2008-11-26 at 20:14 +0000, Glynn Clements wrote:

Nikos Alexandris wrote:

> I think I have questioned something similar but not quite the same
> several months ago.
>
> I moved the "grassdb" foldes (with all of its locations of course) in
> another directory and thus, the absolute database path has been changed.
>
> I need to re-connect all database tables. I think I am doing the right
> thing by trying to use the v.db.reconnect.all module. However, I am a
> bit confused about the appropriate format to be used for the
> "old_database", "new_database" parameters.
>
> Isn't it the absolute paths that are required?

For old_database=, it needs to be the exact string which appears as
the fourth field of "v.db.connect -g", including the trailing "/"
character if it is present.

For new_database=, the value is passed directly to v.db.connect's
database= option, so it can be in any form which the driver accepts,
including variable substitutions for the DBF driver.

The default database for the DBF driver is literally:

  $GISDBASE/$LOCATION_NAME/$MAPSET/dbf/

By "literally", I mean that's how it appears in the "dbln" file; the
driver expands the variables whenever you access the data.

Any such maps don't need to be explicitly reconnected if you move the
database.

Glynn & Company,

thank you. It worked :slight_smile:

Your explanation(s) are, as usual, precise. The parameter's names are
very clear. I got confused somehow from the fact the "v.db.connect -g"
prints out several "variables" and the help-text of "v.db.reconnect.all"
contains the word "variables" as well. So I stuck in "plural" :-?

My mistake of course. But adding your words *the string which appears as
the fourth field of "v.db.connect -g"* (or some other text) in
v.db.reconnect.all's description/help can't harm anyone.

Or maybe an example, in my case using sqlite as a DBMS, (for future
grass-adventurer's ;-):

v.db.reconnect.all
old_database="/home/nik/grassdb/peloponnese/hgrs87/PERMANENT/sqlite.db"
new_database="/geo/grassdb/peloponnese/hgrs87/PERMANENT/sqlite.db"

Kind regards, Nikos

hi Nikos,

On Thu, Nov 27, 2008 at 1:32 AM, Nikos Alexandris
<nikos.alexandris@felis.uni-freiburg.de> wrote:
...

Your explanation(s) are, as usual, precise. The parameter's names are
very clear. I got confused somehow from the fact the "v.db.connect -g"
prints out several "variables" and the help-text of "v.db.reconnect.all"
contains the word "variables" as well. So I stuck in "plural" :-?

My mistake of course. But adding your words *the string which appears as
the fourth field of "v.db.connect -g"* (or some other text) in
v.db.reconnect.all's description/help can't harm anyone.

Or maybe an example, in my case using sqlite as a DBMS, (for future
grass-adventurer's ;-):

v.db.reconnect.all
old_database="/home/nik/grassdb/peloponnese/hgrs87/PERMANENT/sqlite.db"
new_database="/geo/grassdb/peloponnese/hgrs87/PERMANENT/sqlite.db"

Can you please submit a diff against SVN with the document change?
Then it is 100 times easier to merge that in :slight_smile: Since you are power user
I am sure that creating a diff is no big deal for you, see
http://trac.osgeo.org/grass/wiki/HowToSVN#LocalDiffs

Thanks,
Markus

On Thu, 2008-11-27 at 09:33 +0100, Markus Neteler wrote:

hi Nikos,

On Thu, Nov 27, 2008 at 1:32 AM, Nikos Alexandris
<nikos.alexandris@felis.uni-freiburg.de> wrote:
...
> Your explanation(s) are, as usual, precise. The parameter's names are
> very clear. I got confused somehow from the fact the "v.db.connect -g"
> prints out several "variables" and the help-text of "v.db.reconnect.all"
> contains the word "variables" as well. So I stuck in "plural" :-?
>
> My mistake of course. But adding your words *the string which appears as
> the fourth field of "v.db.connect -g"* (or some other text) in
> v.db.reconnect.all's description/help can't harm anyone.
>
> Or maybe an example, in my case using sqlite as a DBMS, (for future
> grass-adventurer's ;-):
>
> v.db.reconnect.all
> old_database="/home/nik/grassdb/peloponnese/hgrs87/PERMANENT/sqlite.db"
> new_database="/geo/grassdb/peloponnese/hgrs87/PERMANENT/sqlite.db"

Can you please submit a diff against SVN with the document change?
Then it is 100 times easier to merge that in :slight_smile: Since you are power user
I am sure that creating a diff is no big deal for you, see
http://trac.osgeo.org/grass/wiki/HowToSVN#LocalDiffs

Thanks,
Markus

Hi Markus!

Sure, I will do so.

Thank you, Nikos

On Thu, 2008-11-27 at 13:09 +0100, Nikos Alexandris wrote:

On Thu, 2008-11-27 at 09:33 +0100, Markus Neteler wrote:
> hi Nikos,
>
> On Thu, Nov 27, 2008 at 1:32 AM, Nikos Alexandris
> <nikos.alexandris@felis.uni-freiburg.de> wrote:
> ...
> > Your explanation(s) are, as usual, precise. The parameter's names are
> > very clear. I got confused somehow from the fact the "v.db.connect -g"
> > prints out several "variables" and the help-text of "v.db.reconnect.all"
> > contains the word "variables" as well. So I stuck in "plural" :-?
> >
> > My mistake of course. But adding your words *the string which appears as
> > the fourth field of "v.db.connect -g"* (or some other text) in
> > v.db.reconnect.all's description/help can't harm anyone.
> >
> > Or maybe an example, in my case using sqlite as a DBMS, (for future
> > grass-adventurer's ;-):
> >
> > v.db.reconnect.all
> > old_database="/home/nik/grassdb/peloponnese/hgrs87/PERMANENT/sqlite.db"
> > new_database="/geo/grassdb/peloponnese/hgrs87/PERMANENT/sqlite.db"
>
> Can you please submit a diff against SVN with the document change?
> Then it is 100 times easier to merge that in :slight_smile: Since you are power user
> I am sure that creating a diff is no big deal for you, see
> http://trac.osgeo.org/grass/wiki/HowToSVN#LocalDiffs
>
> Thanks,
> Markus

Hi Markus!

Sure, I will do so.

Thank you, Nikos

This seem to require another treatment... ?

# editing the file and saving changes
nik@vertical:/usr/local/src/grass6_devel$ nano
scripts/v.db.reconnect.all/v.db.reconnect.all.tmp.html

# excute svn diff to check changes
nik@vertical:/usr/local/src/grass6_devel$ svn diff
scripts/v.db.reconnect.all/

No output!!

What am I doing wrong?
Is something, due to the ".tmp.html" ending, different?

Nikos

On Fri, Nov 28, 2008 at 12:16 AM, Nikos Alexandris
<nikos.alexandris@felis.uni-freiburg.de> wrote:
...

This seem to require another treatment... ?

# editing the file and saving changes
nik@vertical:/usr/local/src/grass6_devel$ nano
scripts/v.db.reconnect.all/v.db.reconnect.all.tmp.html

This is the temporary file, not the file in SVN (which
is description.html in 6.x and modulename.html in 7).

Just copy over your changes into the right html file and
svn diff will work.

Markus

On Fri, 2008-11-28 at 00:18 +0100, Markus Neteler wrote:

On Fri, Nov 28, 2008 at 12:16 AM, Nikos Alexandris
<nikos.alexandris@felis.uni-freiburg.de> wrote:
...
> This seem to require another treatment... ?
>
> # editing the file and saving changes
> nik@vertical:/usr/local/src/grass6_devel$ nano
> scripts/v.db.reconnect.all/v.db.reconnect.all.tmp.html

This is the temporary file, not the file in SVN (which
is description.html in 6.x and modulename.html in 7).

Just copy over your changes into the right html file and
svn diff will work.

Markus

Well, I thought so (that description is the file to be edited) but it
(=description.html) has only one sentence in it:

cat /usr/local/src/grass6_devel/scripts/v.db.reconnect.all/description.html
<H2>DESCRIPTION</H2>

<EM>v.db.reconnect.all</EM> changes database connection of all layers of
all vectors in the current mapset from old_database to database. If a
link
does not match the old_database it is left untouched.

<H2>AUTHOR</H2>
Radim Blazek

<p>
<i>Last changed: $Date: 2007-04-17 01:41:41 +0200 (Tue, 17 Apr 2007)
$</i>

Anyhow, I'll copy the whole file (I think it's not wrong -- or is it?)

Cheers, Nikos

On Fri, 2008-11-28 at 00:43 +0100, Nikos Alexandris wrote:

On Fri, 2008-11-28 at 00:18 +0100, Markus Neteler wrote:
> On Fri, Nov 28, 2008 at 12:16 AM, Nikos Alexandris
> <nikos.alexandris@felis.uni-freiburg.de> wrote:
> ...
> > This seem to require another treatment... ?
> >
> > # editing the file and saving changes
> > nik@vertical:/usr/local/src/grass6_devel$ nano
> > scripts/v.db.reconnect.all/v.db.reconnect.all.tmp.html
>
> This is the temporary file, not the file in SVN (which
> is description.html in 6.x and modulename.html in 7).
>
> Just copy over your changes into the right html file and
> svn diff will work.
>
> Markus

Well, I thought so (that description is the file to be edited) but it
(=description.html) has only one sentence in it:

cat /usr/local/src/grass6_devel/scripts/v.db.reconnect.all/description.html
<H2>DESCRIPTION</H2>

<EM>v.db.reconnect.all</EM> changes database connection of all layers of
all vectors in the current mapset from old_database to database. If a
link
does not match the old_database it is left untouched.

<H2>AUTHOR</H2>
Radim Blazek

<p>
<i>Last changed: $Date: 2007-04-17 01:41:41 +0200 (Tue, 17 Apr 2007)
$</i>

Anyhow, I'll copy the whole file (I think it's not wrong -- or is it?)

Cheers, Nikos

Sorry for the mail-traffic. Just more info to support my claim that the
"current" description.html is sort of "empty":

# copy the ".tmp.html" over to ".html"
nik@vertical:/usr/local/src/grass6_devel$ cp
scripts/v.db.reconnect.all/v.db.reconnect.all.tmp.html
scripts/v.db.reconnect.all/description.html

# changes
nik@vertical:/usr/local/src/grass6_devel$ svn diff
scripts/v.db.reconnect.all/

Index: scripts/v.db.reconnect.all/description.html

--- scripts/v.db.reconnect.all/description.html (revision 34562)
+++ scripts/v.db.reconnect.all/description.html (working copy)
@@ -1,3 +1,40 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>GRASS GIS: v.db.reconnect.all</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.reconnect.all</b></em> - Reconnects vectors to a new
database.
+<h2>KEYWORDS</h2>
+vector, database, attribute table
+<h2>SYNOPSIS</h2>
+<b>v.db.reconnect.all</b><br>
+<b>v.db.reconnect.all help</b><br>
+<b>v.db.reconnect.all</b> <b>old_database</b>=<em>string</em>
<b>new_database</b>=<em>string</em> [<b>old_schema</b>=<em>string</em>]
[<b>new_schema</b>=<em>string</em>] [--<b>verbose</b>]
[--<b>quiet</b>]
+
+
+<h3>Parameters:</h3>
+<DL>
+<DT><b>old_database</b>=<em>string</em></DT>
+<DD>Name of old database. It needs to be the exact string which
+appears as the fourth field printed by v.db.connect -g, i.e. with
substituted variables</DD>
+
+<DT><b>new_database</b>=<em>string</em></DT>
+<DD>Name of new database</DD>
+
+<DT><b>old_schema</b>=<em>string</em></DT>
+<DD>Old schema</DD>
+
+<DT><b>new_schema</b>=<em>string</em></DT>
+<DD>New schema</DD>
+
+</DL>
<H2>DESCRIPTION</H2>

<EM>v.db.reconnect.all</EM> changes database connection of all layers
of
@@ -9,3 +46,8 @@

<p>
<i>Last changed: $Date$</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>&copy; 2003-2008 <a href="http://grass.osgeo.org">GRASS Development
Team</a></p>
+</body>
+</html>

Nikos

Nikos Alexandris wrote:

> > This seem to require another treatment... ?
> >
> > # editing the file and saving changes
> > nik@vertical:/usr/local/src/grass6_devel$ nano
> > scripts/v.db.reconnect.all/v.db.reconnect.all.tmp.html
>
> This is the temporary file, not the file in SVN (which
> is description.html in 6.x and modulename.html in 7).
>
> Just copy over your changes into the right html file and
> svn diff will work.
>
> Markus

Well, I thought so (that description is the file to be edited) but it
(=description.html) has only one sentence in it:

Yep, that's the one.

Everything prior to the "<H2>DESCRIPTION</H2>" line is generated by
the parser:

  v.db.reconnect.all --html-description

The Makefile rules merge this with the contents of the
description.html file to get the completed HTML documentation.

This approach guarantees that the flags and options at least have
accurate (if somewhat minimal) documentation, even if the rest of the
documentation is hopelessly out of date.

Anyhow, I'll copy the whole file (I think it's not wrong -- or is it?)

It is. Don't copy the boilerplate from the top of the .tmp.html file
into the description.html file.

--
Glynn Clements <glynn@gclements.plus.com>

On Fri, 2008-11-28 at 02:52 +0000, Glynn Clements wrote:

Nikos Alexandris wrote:

> > > This seem to require another treatment... ?
> > >
> > > # editing the file and saving changes
> > > nik@vertical:/usr/local/src/grass6_devel$ nano
> > > scripts/v.db.reconnect.all/v.db.reconnect.all.tmp.html
> >
> > This is the temporary file, not the file in SVN (which
> > is description.html in 6.x and modulename.html in 7).
> >
> > Just copy over your changes into the right html file and
> > svn diff will work.
> >
> > Markus
>
> Well, I thought so (that description is the file to be edited) but it
> (=description.html) has only one sentence in it:

Yep, that's the one.

Everything prior to the "<H2>DESCRIPTION</H2>" line is generated by
the parser:

  v.db.reconnect.all --html-description

The Makefile rules merge this with the contents of the
description.html file to get the completed HTML documentation.

This approach guarantees that the flags and options at least have
accurate (if somewhat minimal) documentation, even if the rest of the
documentation is hopelessly out of date.

> Anyhow, I'll copy the whole file (I think it's not wrong -- or is it?)

It is. Don't copy the boilerplate from the top of the .tmp.html file
into the description.html file.

OhOh... too late. Sorry, I'll correct it. Excuse my ignorance.
Nikos