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
Code generator and MetaImpl return CREATE DEFAULT statement instead of just the default expression #15934
Comments
Thanks a lot for your report. I can reproduce this. |
It's what the server returns. Try this query: select object_definition(default_object_id)
from sys.columns
where name = 'problem_column'; It will reproduce the |
Even the select column_default
from information_schema.columns
where column_name = 'problem_column' |
default
of Transact-SQL is processed incorrectly.
Exactly, I suspect this is because this field may have a function as a default provider, such as |
Implementing this now. In order to have a shared implementation between code generator and |
There's a slight chance users would prefer that no default is reported on such fields as generated DDL from those tables will inline the default. E.g. with: create default d_15934 as 'd';
create table t_15934 (d varchar(10));
sp_bindefault 'd_15934', 't_15934.d'; And then: Meta meta =
create().meta()
.filterCatalogs(c -> c.getName().equals(schema().getCatalog().getName()))
.filterSchemas(s -> s.getName().equals(schema().getName()))
.filterTables(x -> x.getName().equals("t_15934"));
String metaDDL = meta.ddl(new DDLExportConfiguration().flags(DDLFlag.TABLE)).toString();
System.out.println(metaDDL); The result is now this, after the fix: create table [test].[dbo].[t_15934] (
[d] varchar(10) default 'd'
); That's not exactly the same thing as what the original schema mandates. But we don't currently have a way to represent such named defaults in our meta model, so I don't see how this could be fixed without going all in on the feature support (which I don't think is worth prioritising right now): |
statement instead of just the default expression
statement instead of just the default expression
statement instead of just the default expression
statement instead of just the default expression
Expected behavior
The
Field
class should have the correct default value, which isunknown
in my case.Actual behavior
The MSSQL driver implementation for
java.sql.DatabaseMetaData#getColumns
returnscreate default my_default_data_type as 'unknown';
forcolumn number 13
instead of the expected string value:unknown
. I'm uncertain if this result aligns with the documented column behavior in the JDBC driver documentation:<LI><B>COLUMN_DEF</B> String {@code =>} default value for the column, which should be interpreted as a string when the value is enclosed in single quotes (may be {@code null}) for default types
However, it appears to be a result of the database engine, causing issues with jOOQ parsing at this point. Consequently, there are numerous logs and an incorrect default value like:
I suppose we should extend the field parser for this case.
Steps to reproduce the problem
jOOQ/jOOQ/src/main/java/org/jooq/impl/MetaImpl.java
Line 1399 in 50290b4
dslContext.meta().schemas.tables
.jOOQ Version
jOOQ Professional Edition 3.18.7
Database product and version
mcr.microsoft.com/mssql/server:2017-latest
Java Version
No response
OS Version
No response
JDBC driver name and version (include name if unofficial driver)
mssql-jdbc:12.5.0.jre11-preview (any)
The text was updated successfully, but these errors were encountered: