[GRASS-dev] [GRASS GIS] #2457: DBF driver: stub functions for SQL TRANSACTION

#2457: DBF driver: stub functions for SQL TRANSACTION
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.5
Component: Database | Version: svn-releasebranch64
Keywords: dbf, sql | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------
On some systems (here: Ubuntu, user report on grass-user), it is not
possible to run v.rast.stats properly when using the DBF driver as it is
internally executing a SQL transaction:

{{{
v.rast.stats -c vector=basin_250@PERMANENT raster=rainfall_idw@PERMANENT
colprefix=z
Updating the database ...
DBMI-DBF driver error:
SQL parser error: syntax error, unexpected NAME processing
'BEGIN'
in statement:
BEGIN TRANSACTION
Error in db_execute_immediate()
ERROR: Error while executing: 'BEGIN TRANSACTION'
}}}

I would suggest to add stub functions for
  * db_begin_transaction()
  * db_commit_transaction()

to db/drivers/dbf/execute.c to make the DBMI interface happy.

Is attached patch ok? If yes, also add to GRASS 7?

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2457&gt;
GRASS GIS <http://grass.osgeo.org>

#2457: DBF driver: stub functions for SQL TRANSACTION
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.5
Component: Database | Version: svn-releasebranch64
Keywords: dbf, sql | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by neteler):

I modified the patch but don't know where to add these two items:

  * SQLP_BEGIN_TRANSACTION
  * SQLP_COMMIT_TRANSACTION

{{{
dbfexe.c:251:11: error: ‘SQLP_BEGIN_TRANSACTION’ undeclared (first use in
this function)
      case (SQLP_BEGIN_TRANSACTION):

dbfexe.c:252:11: error: ‘SQLP_COMMIT_TRANSACTION’ undeclared (first use in
this function)
      case (SQLP_COMMIT_TRANSACTION):
}}}

I suppose they need to go somewhere into lib/db/ ?

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2457#comment:1&gt;
GRASS GIS <http://grass.osgeo.org>

#2457: DBF driver: stub functions for SQL TRANSACTION
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.5
Component: Database | Version: svn-releasebranch64
Keywords: dbf, sql | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by mlennert):

Replying to [comment:1 neteler]:
> I modified the patch but don't know where to add these two items:
>
> * SQLP_BEGIN_TRANSACTION
> * SQLP_COMMIT_TRANSACTION

According to lib/db/sqlp/README:

"New types have to be added in yac.y, lex.l, print.c and
../../../include/sqlp.h."

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2457#comment:2&gt;
GRASS GIS <http://grass.osgeo.org>

#2457: DBF driver: stub functions for SQL TRANSACTION
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.5
Component: Database | Version: svn-releasebranch64
Keywords: dbf, sql | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by neteler):

Thanks, attached patch updated which now compiles. Still not reaching the
desired effect to simply ignore the SQL transaction when using a DBF
driver...

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2457#comment:3&gt;
GRASS GIS <http://grass.osgeo.org>

#2457: DBF driver: stub functions for SQL TRANSACTION
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.5
Component: Database | Version: svn-releasebranch64
Keywords: dbf, sql | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by mlennert):

Replying to [comment:3 neteler]:
> Thanks, attached patch updated which now compiles. Still not reaching
the desired effect to simply ignore the SQL transaction when using a DBF
driver...

You still are missing the additions to the other files mentioned. AFAICT,
with the current patch, st->command will never take the values
SQLP_BEGIN_TRANSACTION or SQLP_COMMIT_TRANSACTION as they are not
recognized by the parser, so your case statement will always be false.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2457#comment:4&gt;
GRASS GIS <http://grass.osgeo.org>

#2457: DBF driver: stub functions for SQL TRANSACTION
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.5
Component: Database | Version: svn-releasebranch64
Keywords: dbf, sql | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by neteler):

Replying to [comment:4 mlennert]:
> You still are missing the additions to the other files mentioned.

Ops, right.
Updated patch attached, now it complains about double defined BEGIN...

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2457#comment:5&gt;
GRASS GIS <http://grass.osgeo.org>

#2457: DBF driver: stub functions for SQL TRANSACTION
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.5
Component: Database | Version: svn-releasebranch64
Keywords: dbf, sql | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by mlennert):

Replying to [comment:5 neteler]:
> Replying to [comment:4 mlennert]:
> > You still are missing the additions to the other files mentioned.
>
> Ops, right.
> Updated patch attached, now it complains about double defined BEGIN...

After running make in lib/db/sqlp/ there is a file lex.yy.c which has the
following line 125:

{{{
#define BEGIN (yy_start) = 1 + 2 *
}}}

My wild guess is that this causes your problem, but I'm way out of my
league here (don't even know where this line comes from in that file), so
you would have to consult with a lex/yacc guru.

Moritz

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2457#comment:6&gt;
GRASS GIS <http://grass.osgeo.org>

#2457: DBF driver: stub functions for SQL TRANSACTION
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.5
Component: Database | Version: svn-releasebranch64
Keywords: dbf, sql | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by glynn):

> After running make in lib/db/sqlp/ there is a file lex.yy.c which has
the following line 125:
>
{{{
#define BEGIN (yy_start) = 1 + 2 *
}}}
>
> My wild guess is that this causes your problem, but I'm way out of my
league here (don't even know where this line comes from in that file),

It's part of the boilerplate code which built into flex itself.

The bottom line is that you can't use "BEGIN" as a token identifier
(REJECT, ECHO and INITIAL are also unavailable; the other macro names are
unlikely to result in innocent collisions). Add a trailing underscore or
change the case to avoid a conflict.

Also the patch attempts to define the TRANSACTION token twice:

{{{
%token BEGIN TRANSACTION
%token COMMIT TRANSACTION
}}}

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2457#comment:7&gt;
GRASS GIS <http://grass.osgeo.org>

#2457: DBF driver: stub functions for SQL TRANSACTION
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.5
Component: Database | Version: svn-releasebranch64
Keywords: dbf, sql | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by neteler):

Thanks, getting closer:

{{{
GRASS 6.4.4svn (nc_spm_08):~ > v.rast.stats myzipcodes_wake
raster=elevation colprefix=elev -c
  100%
Updating the database ...
DBMI-DBF driver error:
Table '' doesn't exist.
Error in db_execute_immediate()

ERROR: Error while executing: 'BEGIN TRANSACTION'
}}}

Something is yet messed up in the updated patch.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2457#comment:8&gt;
GRASS GIS <http://grass.osgeo.org>

#2457: DBF driver: stub functions for SQL TRANSACTION
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.5
Component: Database | Version: svn-releasebranch64
Keywords: dbf, sql | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by renatomichel):

Hello,

I copied the file v.rast.stats Version 6.4.3 in the
apps/grass/grass-6.4.4/scripts successfully, I no longer have the error
message. These scipts are different with quotes usage ?

my system (windows, qgis 2.6.1)

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2457#comment:9&gt;
GRASS GIS <http://grass.osgeo.org>

#2457: DBF driver: stub functions for SQL TRANSACTION
-------------------------+--------------------------------------------------
Reporter: neteler | Owner: grass-dev@…
     Type: defect | Status: new
Priority: normal | Milestone: 6.4.5
Component: Database | Version: svn-releasebranch64
Keywords: dbf, sql | Platform: All
      Cpu: Unspecified |
-------------------------+--------------------------------------------------

Comment(by neteler):

Instead of trying to add SQL TRANSACTIONS to the DBF driver, I have now
simply conditionalized it in r63789. This will go into a future GRASS GIS
6.4.5.

Please try the updated script from here:
https://svn.osgeo.org/grass/grass/branches/releasebranch_6_4/scripts/v.rast.stats/v.rast.stats

Thanks for reporting it. The ticket may be closed if the updated script
works ok for you.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2457#comment:10&gt;
GRASS GIS <http://grass.osgeo.org>

#2457: DBF driver: stub functions for SQL TRANSACTION
-----------------------+----------------------------------------------------
  Reporter: neteler | Owner: grass-dev@…
      Type: defect | Status: closed
  Priority: normal | Milestone: 6.4.5
Component: Database | Version: svn-releasebranch64
Resolution: wontfix | Keywords: dbf, sql
  Platform: All | Cpu: Unspecified
-----------------------+----------------------------------------------------
Changes (by neteler):

  * status: new => closed
  * resolution: => wontfix

Comment:

The last comment did not belong here but to the list.

Since adding SQL TRANSACTIONs to the DBF driver appears to be too
complicated and essentially useless, I take liberty to close my own ticket
as wontfix. Thanks for the support, though.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/2457#comment:11&gt;
GRASS GIS <http://grass.osgeo.org>