<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Thanks Even,</p>
    <p>Executing PRAGMA foreign_keys = ON sounds interesting, one thing
      we'll then need to check on the relation editing end is that we
      make proper use of deferred foreign key constraints.<br>
    </p>
    What do you think about the way to go concerning handling broken
    files?<br>
    The current situation is that there's very limited information for a
    user concerning the problems and it requires advanced sqlite skills
    to investigate and fix those problems. I am a bit worried that this
    might impact overall acceptance of gpkg.<br>
    <br>
    * It looks like the error message is around (since it's in the
    message log), so that's mostly a visibility / UI problem<br>
    * There is no clear "path of action" for a user. It would be nice to
    offer to open the dataset anyway when that happens. Is it possible
    to prevent OGR from running the PRAGMA foreign_key_check?<br>
    <br>
    Matthias<br>
    <br>
    <div class="moz-cite-prefix">On 08/03/2018 08:40 PM, Even Rouault
      wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:1549794.06pyOKaaQo@even-i700">
      <pre wrap="">Matthias,

Looking a bit at this, I see from sqlite doc that foreign key constraints are 
only enforced if the user runs

PRAGMA foreign_keys = ON

which OGR does no activate by default, hence the easyness to break them.

This can be enabled by defining the configuration option/environment variable
OGR_SQLITE_PRAGMA="foreign_keys=ON"

I'm contemplating if the GPKG driver should do that by default (would probably 
makes sense since at opening it runs the PRAGMA foreign_key_check)

Even

</pre>
      <blockquote type="cite">
        <pre wrap="">Hi everyone,

I recently gave a course where geopackages were used as datasets. Those
geopackages had foreign key constraints (among others) activated. While
editing those files, at least on one machine, someone managed to get it
into a "corrupted" state (layer disappeared). Trying to load this layer
later on will result in a bad layer. The only thing we have is a tiny
message in the message log informing about "pragma foreign_key_check on
'file.gpkg' failed. You can disable this check by setting the
OGR_GPKG_FOREIGN_KEY_CHECK configuration option to NO".

I think it's quite strange that QGIS/OGR manages to bring a GeoPackage
into a corrupted state and then denies to open it.

* It would - I guess - be preferable to prevent a GeoPackage from going
into such a state

* Since it appears to be quite easy to bring a dataset into such a state
(although I'm afraid I can't provide detailed steps) QGIS should by
default probably rather open (and warn) or warn and give a possibility
to still open.

Did others experience this as well and have more ideas what to do?

Thanks and best wishes
Matthias
_______________________________________________
QGIS-Developer mailing list
<a class="moz-txt-link-abbreviated" href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a>
List info: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
Unsubscribe: <a class="moz-txt-link-freetext" href="https://lists.osgeo.org/mailman/listinfo/qgis-developer">https://lists.osgeo.org/mailman/listinfo/qgis-developer</a>
</pre>
      </blockquote>
      <pre wrap="">

</pre>
    </blockquote>
    <br>
    <div class="moz-signature">-- <br>
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <div class="moz-signature">
        <title></title>
        <div class="moz-signature"> <span style="text-align: left;
            color: #000000; font-family: 'Verdana', sans-serif;
            font-size: 10pt">Matthias Kuhn</span><br>
          <a href="mailto:matthias@opengis.ch" target="_blank"> <span
              style="text-align: left; color: #000000; font-family:
              'Verdana', sans-serif; font-size: 8pt">matthias@opengis.ch</span>
          </a><br>
          <span style="text-align: left; color: #000000; font-family:
            'Verdana', sans-serif; font-size: 8pt"><a
              href="tel:+41764356763">+41 (0)76 435 67 63</a></span><br>
          <div> <a href="http://www.opengis.ch"> <img
                moz-do-not-send="false"
                src="cid:part3.92FC86AE.ACB3767F@opengis.ch"
                alt="OPENGIS.ch Logo" width="200" height="80"></a> </div>
        </div>
      </div>
    </div>
  </body>
</html>