Hello, You're not doing anything wrong. We currently have an open issues related to MySQL data types and DDL: https://github.com/jOOQ/jOOQ/issues/3341
The issue doesn't describe the CREATE TABLE statement, but it's still the same issue. Unfortunately, for the time being, you will need to write those queries manually. - Lukas 2015-01-26 8:21 GMT+01:00 <[email protected]>: > Hello, > > I am trying to use Jooq 3.5.1 to generate some SQL to be run on a MySQL > database. I cannot figure out what I am doing wrong, because the SQL query > being produced is nothing like i'd expect based on the DSL. > > FYI I am using Spring Boot, not sure if thats relevant or not :) > > Heres how i'm creating the DSLContext: > > @Bean > public DSLContext jooqDslContext(DataSource dataSource) throws > SQLException { > return DSL.using(dataSource.getConnection(), SQLDialect.MYSQL); > } > > Using this DSLContext, I have run the following: > > String sql = migration.createTable("users").column("id", > SQLDataType.INTEGER) > .column("email_address", > SQLDataType.VARCHAR.length(255).nullable(false)) > .column("password", > SQLDataType.VARCHAR.length(64)).column("api_key", > SQLDataType.VARCHAR.length(16)).getSQL(); > > I would expect the value of 'sql' to contain something like: > > create table `users` (`id` int not null, `email_address` varchar(255), > `password` varchar(64), `api_key` varchar(16)); > > However, it contains the following: > > create table `users`(`id` signed not null, `email_address` char(255) not > null, `password` char(64) null, `api_key` char(16) null) > > It completely missed the datatype for the 'id' column (and randomly > specified 'signed' as an integer type, even though I didnt specify anything > of the sort), and it used char's instead of varchar's even though I > specified varchar. > > Trying to execute it produces the following exception: > com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an > error in your SQL syntax; check the manual that corresponds to your MariaDB > server version for the right syntax to use near 'signed not null, > `email_address` char(255) not null, `password` char(64) null, `' at line 1 > > I thought this was because I was using the wrong SQLDialect or something, > however I am explicitly stating I want to use the MySQL dialect in the > DSLContext factory method (using the MariaDB dialect produces an identical > result). > > I have jooq, jooq-meta and jooq-codegen libraries on the classpath (I > initially started with jooq, but added jooq-meta and jooq-codegen incase > they contained the MySQL specific dialect implementation) > > What am I doing wrong? > > Thanks, > Erin > > -- > 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 [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
