Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#5604 closed defect (fixed)

missing CPLString().FormatC(..) when using doubles - fails on systems using Decimal.Comma

Reported by: mj10777 Owned by: Even Rouault
Priority: high Milestone: 2.0.0
Component: default Version: svn-trunk
Severity: critical Keywords: FormatC, doubles, Decimal.Comma
Cc:

Description

While trying the 'Rasterlite' Format, the images no longer showed.

I have recently updated to Ubuntu 14.04 from 12.04 where this problem was not noticed.


The following error showed in the terminal while loading 'Rasterlite' Databases:

ERROR 1: In ExecuteSQL(): sqlite3_prepare(SELECT m.geometry, r.raster, m.id, m.width, m.height FROM "TrueMarble_metadata" AS m, "TrueMarble_rasters" AS r WHERE m.rowid IN (SELECT pkid FROM "idx_TrueMarble_metadata_geometry" WHERE xmin < 22,916666666666668 AND xmax > 14,583333333333334 AND ymin < 39,416666666666664 AND ymax > 31,083333333333329) AND m.pixel_x_size >= 0,016666666666666 AND m.pixel_x_size <= 0,016666666666668 AND m.pixel_y_size >= 0,016666666666666 AND m.pixel_y_size <= 0,016666666666668 AND r.id = m.id):

near ",": syntax error

---

For:

frmts/rasterlite/ and

ogr/ogrsf_frmts/sqlite

I have replaced in all of the '.Printf('

the '%.15f' or '%.12f' and '%.18g'

everywhere where ' '%.1' could be found

with '%s' and a corresponding:

CPLString().FormatC(padfXResolutions[nLevel] - 1e-15,"%.15f").c_str()

---

After recompiling gdal and QGIS all of my 'Rasterlite' Rasters show up correctly.

---

The diff was created with:

svn upgrade

svn diff frmts/rasterlite > 20140804.rasterlite_formatc.diff

svn diff ogr/ogrsf_frmts/sqlite > 20140804.ogrsf_frmts_sqlite_formatc.diff

for whatever reason 'svn upgrade' had to be called first

---

the diff for 'sqlite' also includes changes already submitted in:

[GDAL] #5582: SpatialView? - writable

---

This problem is also meantioned in:

[GDAL] #5603: Rasterlite2 (spatialite)

---

I have NOT looked at other areas of the project to see if there are also other areas when machine specific formatting is needed for doubles

Attachments (4)

20140804.rasterlite_formatc.diff (62.7 KB) - added by mj10777 7 years ago.
added CPLString().FormatC to sql-queries
20140804.ogrsf_frmts_sqlite_formatc.diff (67.4 KB) - added by mj10777 7 years ago.
added CPLString().FormatC to sql-queries
20140805.ogrsf_frmts_sqlite_formatc.diff (7.9 KB) - added by mj10777 7 years ago.
diff done in gedit, without SpatialView? changes
20140805.rasterlite_formatc.diff (11.4 KB) - added by mj10777 7 years ago.
diff done in gedit

Download all attachments as: .zip

Change History (13)

Changed 7 years ago by mj10777

added CPLString().FormatC to sql-queries

Changed 7 years ago by mj10777

added CPLString().FormatC to sql-queries

comment:1 Changed 7 years ago by Even Rouault

Could you redo the patches without all the whitespace changes and without #5582 applied ?

comment:2 Changed 7 years ago by mj10777

I don't know what the cause of the whitespace changes are (possibly the editor - geany)

and I would have to make a fresh copy of everything so that #5582 would not be included.

comment:3 Changed 7 years ago by Even Rouault

Yes please try fixing the setting of your editor so that it preserve whitespaces, otherwise it produces diffs that are not easily reviewable.

Changed 7 years ago by mj10777

diff done in gedit, without SpatialView? changes

Changed 7 years ago by mj10777

diff done in gedit

comment:4 Changed 7 years ago by mj10777

A totally fresh svn was made. The 2 diffs have been redone with gedit (wish I knew why geany does this)

Everything has compiled properly.

comment:5 Changed 7 years ago by mj10777

The use of -x "-w --ignore-eol-style" can avoid such issues.

Most editors remove trailing spaces at the eol, some don't

With the above syntax such 'diff's will be ignored.

svn diff -x "-w --ignore-eol-style" frmts/rasterlite > 20140805.ignore-eol.rasterlite_formatc.diff

comment:6 Changed 7 years ago by Even Rouault

Milestone: 2.0
Resolution: fixed
Status: newclosed

There were errors in your sqlite patch, related to -/+ epsilon, plus an extra %d. You could have caught them by running the autotest/ogr/ogr_sqlite.py script.

In addition to that, I've reworked your patch since it showed that there were numerous copy&paste patterns that could be factored.

trunk r27566 "Rasterlite and Spatialite: avoid locale related issues when formatting floating point numbers (#5604)"

comment:7 Changed 7 years ago by Even Rouault

The change in ogrsqlitevirtualogr.cpp was broken too (missing % character)... Please run the autotest suite when you make changes.

trunk r27567 "Fix previous commit that broke ogr_sql_sqlite.py tests (#5604)"

comment:8 Changed 7 years ago by mj10777

Sorry, much of the internals are still new for me, so there is still much to learn.

comment:9 Changed 6 years ago by Even Rouault

Milestone: 2.02.0.0

Milestone renamed

Note: See TracTickets for help on using tickets.