View Ticket
Not logged in
Ticket Hash: d721933f4d466af6ebfde445a41d5248cab42596
Title: adapt spatialite to function as sqlite3 for the macro .read (without need of UTF-8)
Status: Fixed Type: Feature_Request
Severity: Important Priority: Immediate
Subsystem: Resolution: Fixed
Last Modified: 2015-12-12 10:58:11
Version Found In: 4.4.0-topo-1
User Comments:
anonymous added on 2015-11-26 04:41:28:

Despite the fact a "eternal frozen" has been declared for spatialite

https://groups.google.com/forum/?utm_source=digest&utm_medium=email#!searchin/spatialite-users/spatialite$20UTF8/spatialite-users/3rXXceexITQ/H9b2sr2ux3UJ

the need to get this working in the same way as sqlite3 still exists

  • to avoid writing 2 different scripts
  • sqlite3 without the UTF-8 parameter
  • spatialite with the UTF-8 parameter

Even when 'UTF-8' used and error is sent

  • *** charset ERROR *** cannot convert from 'segment' to 'UTF-8'

The forced use of an extra parameter

  • and receiving an error for the effort is not nice

After wasting (again) many hours looking for the cause of a segment-fault

  • I found this valgrind report, because the new script was based on a old one that was originally called by sqlite3
==21842== Process terminating with default action of signal 11 (SIGSEGV)
==21842==  Access not within mapped region at address 0x1A21310F
==21842==    at 0x563C666: libiconv_open (iconv_open1.h:142)
==21842==    by 0x40AAA0: create_input_utf8_converter (shell.c:637)
==21842==    by 0x40AAA0: process_input (shell.c:3884)
==21842==    by 0x409FC5: do_meta_command (shell.c:2764)
==21842==    by 0x40ABB3: process_input (shell.c:3904)
==21842==    by 0x403DE3: main (shell.c:4503)
==21842==  If you believe this happened as a result of a stack
==21842==  overflow in your program's main thread (unlikely but
==21842==  possible), you can try to increase the size of the
==21842==  main thread stack using the --main-stacksize= flag.
==21842==  The main thread stack size used in this run was 8388608.

The use of spatialite is justified when

  • a new database is created
  • - avoiding a needed InitSpatialMetadata(1);
  • but is not always needed, when however the script calls InitSpatialMetadata(1);
  • - errors/warnings are being issued

This discourages the use of sql-scripts, which should work in the same way

  • and is a pain for those who do

The suggested solution on 2015-01-09 was:

Could 'shell.c', in spatialite-tools, be adapted to 'tolerate' the 'sqlite3' syntax?
This could (possibly) be a simple change of
  if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 && nArg==2 ){
to:
  if( c=='r' && n>=3 && strncmp(azArg[0], "read", n)==0 && nArg> 0 ){

Mark


sandro added on 2015-12-12 10:56:55:
allowing .read to completely skip the charset argument opens a possible pitfall; if the SQL script being executed do actually contains non-UTF8 text strings they'll be directly imported into the DB without any appropriate conversion.
this usually is not a real issue on Linux because UTF8 usually is the standard platform charset, but can be rather dangerous when using the Windows CMD (still based on the old MS-DOS national char-pages).

anyway this exactly is the behavior implemented by sqlite3 (CLI frontend), so I easily understand that many practical considerations strongly advocates your suggested solution.

conclusion: patch accepted