[GRASS-user] db.execute where condition

Dear GRASS users,

I have imported a table titled landuse_tabe with the db.in.ogr command.
I want to do the following with the table:
Add a column named FEATURE_ID
and add values to the column.
To add the values to the column I use:

echo 'UPDATE landuse_table SET FEATURE_ID='1' WHERE
FEATURE='Grazing_land'|db.execute driver=dbf database=$database

I get the following error:

DBMI-DBF driver error:
Column 'Grazing_land' not found
Incompatible types in WHERE condition.
Error in selecting rows
Error in db_execute_immediate()

ERROR: Error while executing: 'UPDATE landuse_table SET FEATURE_ID=1 WHERE
       FEATURE=Grazing_land
       '
If I leave out the WHERE condition the command works fine.
Is it not possible to use SQL where conditions with dbf databases?
The site http://grass.fbk.eu/grass62/manuals/html62_user/grass-dbf.html says
it is possible to use this command.
Can anyone explain to me what I'm doing wrong?

Thank you in advance,
Frans-Joost Boogert

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/db-execute-where-condition-tp6094088p6094088.html
Sent from the Grass - Users mailing list archive at Nabble.com.

On Sun, Mar 6, 2011 at 1:10 PM, frans-joost <fjboogert@gmail.com> wrote:

Dear GRASS users,

I have imported a table titled landuse_tabe with the db.in.ogr command.
I want to do the following with the table:
Add a column named FEATURE_ID
and add values to the column.
To add the values to the column I use:

echo 'UPDATE landuse_table SET FEATURE_ID='1' WHERE

I suspect that '1' makes GRASS-DB interpret this values
as a string. What does

v.info -c landuse_table

say? If that is a numeric column, you need to specify 1 as number.

FEATURE='Grazing_land'|db.execute driver=dbf database=$database

Additionally, you cannot have ' within ' quotes. Either you need to
escape them or use ".

Markus

Hello Markus
The database is not linked to a vector map so I used
db.describe -c landuse_table

ncols: 6
nrows: 5
Column 1: OBJECTID:INTEGER:11
Column 2: FEATURE:CHARACTER:16
Column 3: A:DOUBLE PRECISION:20
Column 4: CC:DOUBLE PRECISION:20
Column 5: PH:DOUBLE PRECISION:20
Column 6: FEATURE_ID:INTEGER:11

I removed the 'within' quotes and the command line now looks like this:
echo 'UPDATE landuse_table SET FEATURE_ID=1 WHERE
FEATURE=Grazing_land'|db.execute driver=dbf database=$database

Unfortunately this doesn't change the output.
The error still refers to the value Grazing_land not found as a column:
DBMI-DBF driver error:

Column 'Grazing_land' not found
Incompatible types in WHERE condition.
Error in selecting rows
Error in db_execute_immediate()

Thanks in advance,
Frans-Joost

On Mon, 7 Mar 2011, Frans-Joost Boogert wrote:

I removed the 'within' quotes and the command line now looks like this:
echo 'UPDATE landuse_table SET FEATURE_ID=1 WHERE
FEATURE=Grazing_land'|db.execute driver=dbf database=$database

Frans-Joost,

   You still don't have the correct syntax. Look at the examples on the
db.execute page:

Update attribute entries to new value based on SQL rule:

echo "UPDATE roads SET travelcost=5 WHERE cat=1" | db.execute

   Notice that the entire expression to be echoed is in double quotes. Other
examples on that page show the column values are in single quotes. Try:

echo "UPDATE landuse_table SET FEATURE_ID=1 WHERE FEATURE='Grazing_land'" | db.execute

after setting the driver and database name separately.

Rich

Hello Rich,

I got the syntax wrong, had been looking at it too long to see the problem!

Thank you for pointing it out!
Frans-Joost

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/db-execute-where-condition-tp6094088p6098727.html
Sent from the Grass - Users mailing list archive at Nabble.com.