Skip to content
This repository has been archived by the owner on Dec 7, 2018. It is now read-only.

Improve loading of row columns by validating if the exist #139

Closed
wants to merge 1 commit into from
Closed

Conversation

emkookmer
Copy link

A resubmit of pull request #138, but this time to master

I was updating my XML seeds, but in doing so remove too much.
DBUnit gave an error while parsing the modified seed and throw a unknown index exception.
As it was unclear what happened, I started digging found that there was no check whereof a field was found or not.
So I came up with this solution.

@emkookmer
Copy link
Author

@elazar, here is the new pull request to master as you suggested in pull request #138

@elazar
Copy link
Collaborator

elazar commented Aug 19, 2014

Is throwing an exception the most desirable course of action here? Would returning null be a potentially feasible alternative?

@emkookmer
Copy link
Author

I think it's the most desirable course, because the field was already define in the table structure and missing from the dataset.
Here is an example seed which should go wrong and trigger my exception.

<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <database name="AdviesFactuur">
        <table_structure name="TBL_Actions">
            <field Field="ID" Type="int(10) unsigned" Null="NO" Key="PRI" Extra="auto_increment" Comment="" />
            <field Field="State" Type="int(10) unsigned" Null="NO" Key="MUL" Extra="" Comment="" />
            <field Field="VIPPeriod" Type="decimal(4,0)" Null="NO" Key="" Extra="" Comment="Period in Days" />
            <field Field="NormPeriod" Type="decimal(4,0)" Null="NO" Key="" Extra="" Comment="Period in Days" />
            <key Table="TBL_Actions" Non_unique="0" Key_name="PRIMARY" Seq_in_index="1" Column_name="ID" Collation="A" Cardinality="5" Null="" Index_type="BTREE" Comment="" />
        </table_structure>
        <table_data name="TBL_Actions">
            <row>
                <field name="ID">2</field>
                <field name="State">6</field>
                <field name="VIPPeriod">0</field>
<!-- NOTE the missing NormPeriod field here -->
            </row>
        </table_data>
    </database>
</mysqldump>

@elazar
Copy link
Collaborator

elazar commented Aug 31, 2014

Fair enough. I can see from doing a local test dump that mysqldump uses an attribute on the row to specify a null value for a column (see below), so it appears you're right: if a column is missing, something is likely wrong with the dump file.

    <row>
        <field name="test" xsi:nil="true" />
    </row>

Any chance you could add a test case for this change?

@sebastianbergmann
Copy link
Owner

This branch has conflicts that must be resolved.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants