New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DB table ip field does not initialize value #4

Closed
bluepoet opened this Issue Jan 12, 2017 · 4 comments

Comments

Projects
None yet
2 participants
@bluepoet
Copy link

bluepoet commented Jan 12, 2017

@janbols

Hi!

I initialized the value in the ip field of the DB table as below, but it does not contain the value.

 @DbUnit(configure = { IDatabaseTester it ->
        it.setUpOperation = DatabaseOperation.CLEAN_INSERT
    })
def content = {
    User(name: 'test1', ip: '1.2.3.4')
    User(name: 'test2', ip: '127.0.0.1')
}

What should I do?

Please confirm.

Your help is very much appreciated!

@janbols janbols closed this Jan 12, 2017

@janbols janbols reopened this Jan 12, 2017

@janbols

This comment has been minimized.

Copy link
Owner

janbols commented Jan 12, 2017

Hi, I don't know how your table looks like, what columns it has. Perhaps there's a PK somewhere that you didn't define. The way it's set up here it looks like you have a table called User with 2 columns called 'name' and 'ip'. If not, then that's probably the cause. I added a test containing your example that should pass on https://github.com/janbols/spock-dbunit/blob/master/src/test/groovy/be/janbols/spock/extension.dbunit/Issue4Test.groovy

Hope this helps.
Jan

@bluepoet

This comment has been minimized.

Copy link
Author

bluepoet commented Jan 13, 2017

@janbols

Thank you for your response.

I have tried to execute the insert statement by changing the insert statement like below.

Def content = {
    User (name: 'test1', ip: '1.2.3.4')
    User (name: 'test2')
}

If you insert the row data with the ip first, then the row data without the ip, the ip field will contain the value.
Probably the first thing you have to guess is that the insert sql statement that was executed was executed.

Please review below.

#5

bluepoet pushed a commit to bluepoet/spock-dbunit that referenced this issue Jan 13, 2017

janbols added a commit that referenced this issue Jan 13, 2017

Merge pull request #5 from bluepoet/master
[#4]Add test code to check insert bug
@janbols

This comment has been minimized.

Copy link
Owner

janbols commented Jan 13, 2017

Ok @bluepoet , I understand your problem now. The first row (in our case, the first User item) defines the columns dbUnit will use. So if you put User (name: 'test2') first, it will assume there's only 1 column. This is a flaw of dbUnit and I don't know if we can easily do something about this, though I agree it is rather annoying and I also bumped into the same issue before.
See http://dbunit.sourceforge.net/faq.html#differentcolumnnumber

@janbols

This comment has been minimized.

Copy link
Owner

janbols commented Mar 26, 2017

Closing this issue because it's not something we can do something about.

@janbols janbols closed this Mar 26, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment