Integer to GUID conversion notes for Inspector Blair project.
Grouping feature requires GUID in place of Integer values for IDs. I would prefer not to perform this conversion for the following reasons:
- It represents a lot of work for absolutely no visual progress to internal customers.
- GUID IDs are X*16 per record compared to integer values. This obvious exponential increase represents a larger load on the database server, but more importantly, means far more HTML code being sent for each page. The extra load is utterly negligible to our network and servers, but could impact mobile devices. <option value = “BC072ADE-ACBF-42B0-8FCA-5587E0FE95BC”>Inspector – Biosafety</option> <option value=”1”>Inspector – Biosafety</option>
While I don’t believe switching to GUID will impact performance to a noticeable degree, I had still hoped to use integers for absolute maximum speed. However, in order to add grouping and integrate it with lists of individuals, GUIDS are an absolute must. Following steps were taken to convert account records to GUID. These same steps may be applied to inspections, system log, autoclaves, and buildings.
- Rename integer ID field to “ID_old”.
- Create new Unique Identifier (Guid) field named “ID”.
- Set Rowguid = True
- Ensure default data binding is (newid())
- If table is not part of a relationship, set “id” to primary key.
- If table is part of any relationship perform the following:
- Rename Integer “FK_ID” to “FK_ID_OLD” in child table.
- Create new Unique Identifier (Guid) field named “FK_ID” in child table.
- Set Rowguid = True
- Run following query:
UPDATE _sub SET _sub.fk_id = _main.id FROM parent _main, child _sub WHERE _sub.fk_id.old = _main.id_old
- Delete one (ID_OLD) to many (FK_ID_OLD) relationship of between parent and child table.
- Set “ID” field in parent and children tables to primary key.
- Create new one (ID) to many (FK_ID) relationship between parent and child table.
- Primary key table: ID, Foreign key table: FK_ID
- INSERT AND UPDATE, Delete Rule: Cascade
- INSERT AND UPDATE, Update Rule: Cascade
- Retype all @id variables in stored procedures from “int” to “uniqueidentifier”.
- Retype all INT values in xml variables to “uniqueidentifier”.
- If table is a list for selected items, (ex. Account roles), the relevant field must be converted to GUID as well. No notes available, use query similar to parent and child.
- For detail display (opposed to data list pages), perform the following additional steps.
- Modify the detail output stored procedure as follows. See “dbo.account” stored procedure for example.
- Replace primary table variable (<@tempMain>) with temp table (<#primary_cache>). This does not change functionality but will increase performance.
- Navigation queries can no longer use output variables. Instead, all relevant output data for navigation should now be output as the first record set.
- If the ID is not provided, run a SELECT TOP 1 query to pre populate.
- Modify display page as follows. See “account.php” for example.
- Remove all navigation variables from stored procedure call and the associated navigation variables.
- Insert recordset read, and place resulting values directly into navigation object. Navigation is the first record set.
- Make sure to add “$query->get_next_result();” for main data recordset read immediately below.
- If detail view contains sub data, remove array verification in sub table update code.
- Add array verification in the xml() method of the relevant data’s class file.
- Add <script> url reference to “dc_guid” function.
- In all insert functions, add a single string variable populated from “dc_guid” function. Replace all $temp_int references with this new variable.\
- Remove global $temp_int.
- Test detail page.
- Create new record.
- Update record.
- Create sub record.
- Update sub record.
- Delete sub record.
- Delete record.
- Navigation
- Modify the detail output stored procedure as follows. See “dbo.account” stored procedure for example.
- Verify list pages point to correct entry in detail page.