--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Is a list of one or more columns in which to insert data. column_list must be enclosed in parentheses and delimited by commas.
[...]
column_list must be used when explicit values are inserted into an identity column, and the SET IDENTITY_INSERT option must be ON for the table.
@Override
public void visitStart(VisitContext context) {
if (ctx.data("prepend-identity-insert") != null) {
context.renderContext().sql("SET IDENTITY_INSERT table_name ON ");
}
}
@Override
public void renderEnd(ExecuteContext ctx) {
if (ctx.data("prepend-identity-insert") != null) {
ctx.sql("SET IDENTITY_INSERT table_name ON " + ctx.sql());
}
}select COLUMN_NAME, TABLE_NAME
from INFORMATION_SCHEMA.COLUMNS
where TABLE_SCHEMA = 'dbo'
and COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1
order by TABLE_NAMEHi Lukas,I implememened a ExecuteListener as you recommended and the insert statements now find their way into the database :-)
I had to find out which tables actually have a identity column:select COLUMN_NAME, TABLE_NAME from INFORMATION_SCHEMA.COLUMNS where TABLE_SCHEMA = 'dbo' and COLUMNPROPERTY(object_id(TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1 order by TABLE_NAME
SELECT [INFORMATION_SCHEMA].[COLUMNS].[COLUMN_NAME],
[INFORMATION_SCHEMA].[COLUMNS].[ORDINAL_POSITION],
[INFORMATION_SCHEMA].[COLUMNS].[DATA_TYPE],
[INFORMATION_SCHEMA].[COLUMNS].[IS_NULLABLE],
[INFORMATION_SCHEMA].[COLUMNS].[COLUMN_DEFAULT],
[INFORMATION_SCHEMA].[COLUMNS].[CHARACTER_MAXIMUM_LENGTH],
[INFORMATION_SCHEMA].[COLUMNS].[NUMERIC_PRECISION],
[INFORMATION_SCHEMA].[COLUMNS].[NUMERIC_SCALE],
c.is_identity
FROM [INFORMATION_SCHEMA].[COLUMNS]
JOIN sys.schemas s
ON [INFORMATION_SCHEMA].[COLUMNS].[TABLE_SCHEMA] = s.name
JOIN sys.objects t
ON ((t.type IN ('U', 'V'))
AND (t.schema_id = s.schema_id)
AND [INFORMATION_SCHEMA].[COLUMNS].[TABLE_NAME] = t.name)
JOIN sys.columns c
ON ((c.object_id = t.object_id)
AND [INFORMATION_SCHEMA].[COLUMNS].[COLUMN_NAME] = c.name)
WHERE ([INFORMATION_SCHEMA].[COLUMNS].[TABLE_SCHEMA] = ?
AND [INFORMATION_SCHEMA].[COLUMNS].[TABLE_NAME] = ?)
ORDER BY [INFORMATION_SCHEMA].[COLUMNS].[ORDINAL_POSITION] ASC
and than check ob the sql statement whether it is a insert or not:if (ctx.configuration().data("prepend-identity-insert") != null && ctx.sql().toLowerCase().contains("insert into")) {Matcher matcher = tablePattern.matcher(ctx.sql());while (matcher.find()) {String tableName = matcher.group(2).trim();if (idTables.contains(tableName)) {ctx.sql("SET IDENTITY_INSERT " + tableName + " ON " + ctx.sql());}}}Maybe there is a better way to do this.
BTW: Wouldn't it be better to have batch insert support for the csv and json loaders?
BTW: Wouldn't it be better to have batch insert support for the csv and json loaders?Yes, of course! I'm hoping to implement this for jOOQ 3.4:
2014-02-12 8:59 GMT+01:00 Johannes Bühler <jonn...@gmail.com>:Hi Lukas,
BTW: Wouldn't it be better to have batch insert support for the csv and json loaders?Yes, of course! I'm hoping to implement this for jOOQ 3.4:May I help implementing this feature?How could I say no to this, after your excellent help with the JSON feature! :-)
It won't be a trivial refactoring, so let's have a quick review of the existing functionality and how this fits with batch:
So how would you like to proceed with a contribution? The easiest way would be to implement this for H2 and I'll make it work for all the other 15 SQL dialects. Or do you have any other suggestion?
So how would you like to proceed with a contribution? The easiest way would be to implement this for H2 and I'll make it work for all the other 15 SQL dialects. Or do you have any other suggestion?This makes absolutely sense. I will start with the H2 implementation and see how far I can get.