Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
QueryDSL-SQL addBatch() with null values #74
QueryDsl classes generated from this:
CREATE TABLE FOO(ID INT IDENTITY(1,1), c1 int null,c2 int null)
QFoo f= QFoo.foo; SQLInsertClause sic = new SQLInsertClause(c, new H2Templates(), f); sic.columns(f.c1,f.c2).values(null,null).addBatch(); sic.columns(f.c1,f.c2).values(null,1).addBatch(); sic.execute();
QFoo f= QFoo.foo; SQLInsertClause sic = new SQLInsertClause(c, new H2Templates(), f); Foo f1=new Foo(); sic.populate(f1).addBatch(); f1=new Foo(); f1.setC1(1); sic.populate(f1).addBatch(); sic.execute();
Seems that engine not recognizing nulls as necessary to be included(as "NULL") in prepared stmt, this behavoir is not valid in cases like above.
added a commit
Feb 8, 2012
You need an easier way to build without tests?
I found now a way to support the second issue
I'll close this when it's released
Just interesting: this is most elegant way from this project architecture pov? Idea: maintaining fields mask and finally constructing prepared statement field list based on that mask.
Sorry for inattention, actual situation is like this:
CREATE TABLE BAR(ID INT IDENTITY(1,1), c1 int null,c2 int default 1 not null)
But i cant handle assigning default value even with PreparedStatement:
PreparedStatement ps = c.prepareStatement("INSERT INTO BAR (c1,c2) values (?, ?)"); ps.setInt(1, 2); //ps.setDefaultValue(); - not exist ps.addBatch(); //... ps.executeBatch();
Maybe this can be done via setObject(), but i don know how.
From common sense this should be as simple as providing DEFAULT keyword(like NULL) for particular parameter, but there is no viable JDBC-way of doing this without messing with driver, and more than that: while most DBs support insert into bar (c1,c2) values (1, default), they(h2,mssql2005) cannot insert into bar (c1,c2) values (1, coalesce(null, default)) facepalm.