[GRASS-dev] [GRASS GIS] #3397: db.select - reading multiline SQL statements from file fails

GRASS GIS trac at osgeo.org
Sun Nov 12 07:44:53 PST 2017


#3397: db.select - reading multiline SQL statements from file fails
--------------------------+-----------------------------------
  Reporter:  maitl        |      Owner:  grass-dev@…
      Type:  defect       |     Status:  new
  Priority:  normal       |  Milestone:  7.4.0
 Component:  Database     |    Version:  7.2.1
Resolution:               |   Keywords:  db.select, db.execute
       CPU:  Unspecified  |   Platform:  All
--------------------------+-----------------------------------

Comment (by mmetz):

 Replying to [comment:3 mlennert]:
 > Replying to [comment:2 mlennert]:
 > > and I cannot integrate a newline ('\n') character:
 > >
 > > {{{
 > > echo "SELECT count(*) FROM boundary_county WHERE Z_MEAN > 38\n; SELECT
 count(*) FROM boundary_county;" | db.select input=-
 > > DBMI-SQLite erreur de pilote :
 > > Error in sqlite3_prepare():
 > > SELECT count(*) FROM boundary_county WHERE Z_MEAN > 38\n; SELECT
 count(*) FROM boundary_county;
 > > unrecognized token: "\"
 > > }}}
 >
 >
 > Sorry, the '\n' was not well placed. It should have been
 >
 >
 > {{{
 > echo "SELECT count(*) FROM boundary_county WHERE Z_MEAN > 38;\n SELECT
 count(*) FROM boundary_county;" | db.select input=-
 database=GRASS/GRASSDATA/NC_spm_temporal_workshop/PERMANENT/sqlite/sqlite.db
 > count(*)
 > 333
 > }}}
 >
 > So, no error, but the query on the second line does not get executed...

 You need to use echo -e (enable interpretation of backslash escapes).

 About the main issue, we could introduce a new flag, e.g. -m, to allow
 multiline statements: only a semicolon, not a newline would mark the end
 of a statement.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3397#comment:4>
GRASS GIS <https://grass.osgeo.org>



More information about the grass-dev mailing list