[GRASS-user] problem using grass.write_comman, db.execute

Pythonians,

I never really got messed up with Python. Several months ago I had to
give up due to lack of free time. Now, I am trying to move on but I have
no idea on how solve the following "db.execute" problem:

# basic info about the point vector/ db
driver = 'sqlite'
database = '/geo/grassdb/peloponnese/evaluation_utm/PERMANENT/sqlite.db'
  # note: I am running python from within grass from within a
user-mapset (not PERMANENT)

# use variables
POINTS = 'points_map'
sql_coi_percent = "UPDATE %s SET coi_percent = (coi_pix * 1. / total_pix
*1. ) * 100" % POINTS

# updating fails!
grass.write_command('db.execute', input = '-', stdin = sql_coi_percent,
database = database, driver = driver)
-: No such file or directory
1

The map is there. So why does it return a non-zero value?
Regards, Nikos

Nikos wrote:

grass.write_command('db.execute', input = '-', stdin = sql_coi_percent,
database = database, driver = driver)
-: No such file or directory

'db.execute input=-' for stdin only works in grass7. for 6.4+6.5 it is
simpler, just omit the input option all together.

Hamish

On Thu, 2009-10-01 at 21:00 -0700, Hamish wrote:

Nikos wrote:
> grass.write_command('db.execute', input = '-', stdin = sql_coi_percent,
> database = database, driver = driver)
> -: No such file or directory

'db.execute input=-' for stdin only works in grass7. for 6.4+6.5 it is
simpler, just omit the input option all together.

Hmm... ok, thank you.

Scripting (or better said learning how to) can be very exciting but
changes (like the above) that break stuff are tough and can be
frustrating.

I read the other day that Python3 will introduce some changes. At what
extent will be os-geo stuff, and especially grass, affected? How should
an average scripter behave? How to prepare scripts that are ready for
changes?

Greets, Nikos

Nikos Alexandris wrote:

I read the other day that Python3 will introduce some changes. At what
extent will be os-geo stuff, and especially grass, affected? How should
an average scripter behave? How to prepare scripts that are ready for
changes?

The most fundamental change is that Python3's default string type is
Unicode; if you want byte strings, you have to specifically request
them (or in some cases, explicitly convert from Unicode, as is the
case with sys.argv and os.environ).

Needless to say, this doesn't interact well with Unix-style scripting,
where everything is byte strings. Expect to have to add a lot of
explict conversions between Unicode strings and byte strings.

OTOH, the change is sufficiently fundamental that you can expect the
2.x series to be maintained for the foreseeable future (even if Guido
abandons 2.x, someone else will maintain it).

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

'db.execute input=-' for stdin only works in grass7. for 6.4+6.5 it is
simpler, just omit the input option all together.

Hi,
What do you mean with omit the input?
Like this?

grass.write_command('db.execute', stdin = sql_coi_percent)

--
View this message in context: http://n2.nabble.com/problem-using-grass-write-comman-db-execute-tp3753409p4749063.html
Sent from the Grass - Users mailing list archive at Nabble.com.

On Wed, 2010-03-17 at 01:15 -0800, schorschli wrote:

>'db.execute input=-' for stdin only works in grass7. for 6.4+6.5 it is
>simpler, just omit the input option all together.

Hi,
What do you mean with omit the input?
Like this?

grass.write_command('db.execute', stdin = sql_coi_percent)

Yes. In my script I use(d):

--%<---
grass.write_command('db.execute',\
stdin = sql_coi_percent,\
database = database,\
driver = driver)
--%<---

Nikos