<p><a href="https://gerrit.osmocom.org/11898">View Change</a></p><p>1 comment:</p><ul style="list-style: none; padding: 0;"><li style="margin: 0; padding: 0;"><p><a href="https://gerrit.osmocom.org/#/c/11898/1/sql/hlr.sql">File sql/hlr.sql:</a></p><ul style="list-style: none; padding: 0;"><li style="margin: 0; padding: 0 0 0 16px;"><p style="margin-bottom: 4px;"><a href="https://gerrit.osmocom.org/#/c/11898/1/sql/hlr.sql@48">Patch Set #1, Line 48:</a> <code style="font-family:monospace,monospace">    -- last_lu_seen TIMESTAMP default NULL</code></p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;">I'm fine with possibility to update on the fly, but why requiring everybody who uses this . […]</blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">I understand where you are coming from. Having spent some time on this already,<br>and having already tried both approaches, my current response to this request is:<br>Yes it would be nice, but it's not trivial to do.</p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">One advantage of the proposed method is that schema upgrades will be extensively tested.<br>Another is that we have a single code path which covers all of these cases:<br> - A new DB is created from scratch.<br> - An existing DB which confirms to the current schema is opened.<br> - An existing DB which needs to be upgraded is opened.<br>And schema upgrades are a very cheap one-time operations, so the cost at run-time is minimal.</pre><p style="white-space: pre-wrap; word-wrap: break-word;">The main downside is of course that the complete schema can only be obtained by running '.fullschema' on an hlr.db.</p><p style="white-space: pre-wrap; word-wrap: break-word;">I couldn't yet find a working solution when the schema is created with the current<br>format to begin with and works for all 3 cases outlined above.</p><p style="white-space: pre-wrap; word-wrap: break-word;">There are several error conditions which show up in various approaches I have tried,<br>and they are all somehow linked to sqlite's limited support for ALTER TABLE.</p><p style="white-space: pre-wrap; word-wrap: break-word;">The ALTER TABLE statement cannot be prepared if the last_lu_seen column already exists:<br>DDB ERROR (1) duplicate column name: last_lu_seen (db.c:88)<br>DDB ERROR Unable to prepare SQL statement 'ALTER TABLE subscriber ADD COLUMN last_lu_seen TIMESTAMP default NULL</p><p style="white-space: pre-wrap; word-wrap: break-word;">If the meta data version is inserted by hlr.sql, then upgrades don't work because<br>an existing subscriber table can't be modified by hlr.sql. But the upgrade code<br>sees version number 1 and won't alter the table, so preparing our statements now fails with:</p><p style="white-space: pre-wrap; word-wrap: break-word;">DDB ERROR (1) no such column: last_lu_seen (db.c:88)<br>DDB ERROR Unable to prepare SQL statement 'SELECT id,imsi,msisdn,vlr_number,sgsn_number,sgsn_address,periodic_lu_tmr,periodic_rau_tau_tmr,nam_cs,nam_ps,lmsi,ms_purged_cs,ms_purged_ps,last_lu_seen FROM subscriber WHERE imsi = ?' (db.c:424)</p><p style="white-space: pre-wrap; word-wrap: break-word;">Also note that the sqlite API does not provide distinct error codes that tell us why a statement failed,<br>which makes it difficult to handle such specific error cases in C code.</p><p style="white-space: pre-wrap; word-wrap: break-word;">It can likely be done somehow, but as far as I can tell it will require more code, not less.</p><p style="white-space: pre-wrap; word-wrap: break-word;">Do you have a working suggestion?</p><p style="white-space: pre-wrap; word-wrap: break-word;">This would all be much easier if a version number had been included in the DB schema the first place.</p></li></ul></li></ul><p>To view, visit <a href="https://gerrit.osmocom.org/11898">change 11898</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.osmocom.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.osmocom.org/11898"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: osmo-hlr </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: comment </div>
<div style="display:none"> Gerrit-Change-Id: I8aeaa9a404b622657cbc7138106f38aa6ad8d01b </div>
<div style="display:none"> Gerrit-Change-Number: 11898 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Stefan Sperling <ssperling@sysmocom.de> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins Builder (1000002) </div>
<div style="display:none"> Gerrit-Reviewer: Stefan Sperling <ssperling@sysmocom.de> </div>
<div style="display:none"> Gerrit-CC: Pau Espin Pedrol <pespin@sysmocom.de> </div>
<div style="display:none"> Gerrit-Comment-Date: Fri, 23 Nov 2018 10:31:32 +0000 </div>
<div style="display:none"> Gerrit-HasComments: Yes </div>
<div style="display:none"> Gerrit-HasLabels: No </div>