How to scope a MySQL JOOQ rename table query to the same database?












4















I have a scala application that manages multiple MySQL database schemas, which includes modifying (adding, renaming, etc.) tables. The commands are issued over a connection pool that connects to a generic management database in the database server.



Because the application is designed to be cross-database, I use JOOQ to render SQL queries (execution is done via a separate JDBC module).



I experience issues with JOOQs alterTable(...).renameTo(...) DSL - consider the following example:



We have a table "TestTable" in database "TestDatabase". Let's say I want to rename that table simply to "Foo", keeping it in "TestDatabase".



This code:



...
val context = DSL.using(SQLDialect.MYSQL_5_7)
val query = context
.alterTable(table(name("TestDatabase", "TestDatabase")))
.renameTo(name("TestDatabase", "Foo"))
...


Generates: ALTER TABLE `TestDatabase`.`TestTable` RENAME TO `Foo`
However, since the connection pool I'm using is connected to my management database, it just renames the table to "Foo" and moves it to my management database. I would have expected the SQL to be: ALTER TABLE `TestDatabase`.`TestTable` RENAME TO `TestDatabase`.`Foo`. I tried a variety of alternatives to invoke the .renameTo method and convice it to use the fully qualified name, to no avail:





  • .renameTo(table(name(...) -> same behaviour.


  • .renameTo("`TestDatabase`.`Foo`") -> Escapes the name with backticks, treats it as one name instead of a qualified name.


I'm wondering if I'm missing something, if this is intended behaviour, or maybe even a bug or design shortcoming of JOOQ.



Is there a way to rename the table using fully qualified names?



Thank you!










share|improve this question























  • Did you try using raw jdbc connections?

    – Mon Calamari
    Nov 8 '18 at 15:13











  • @MonCalamari That works of course, however, this question is specifically about keeping the JOOQ abstraction for cross DB support, or else I'd have to move this code into DB specific code for every DB I want to support.

    – Dominic
    Nov 8 '18 at 15:17











  • If I were you I would raise an issue with github.com/jOOQ/jOOQ

    – Mon Calamari
    Nov 8 '18 at 15:21













  • @MonCalamari Thanks, I will consider it.

    – Dominic
    Nov 8 '18 at 15:51
















4















I have a scala application that manages multiple MySQL database schemas, which includes modifying (adding, renaming, etc.) tables. The commands are issued over a connection pool that connects to a generic management database in the database server.



Because the application is designed to be cross-database, I use JOOQ to render SQL queries (execution is done via a separate JDBC module).



I experience issues with JOOQs alterTable(...).renameTo(...) DSL - consider the following example:



We have a table "TestTable" in database "TestDatabase". Let's say I want to rename that table simply to "Foo", keeping it in "TestDatabase".



This code:



...
val context = DSL.using(SQLDialect.MYSQL_5_7)
val query = context
.alterTable(table(name("TestDatabase", "TestDatabase")))
.renameTo(name("TestDatabase", "Foo"))
...


Generates: ALTER TABLE `TestDatabase`.`TestTable` RENAME TO `Foo`
However, since the connection pool I'm using is connected to my management database, it just renames the table to "Foo" and moves it to my management database. I would have expected the SQL to be: ALTER TABLE `TestDatabase`.`TestTable` RENAME TO `TestDatabase`.`Foo`. I tried a variety of alternatives to invoke the .renameTo method and convice it to use the fully qualified name, to no avail:





  • .renameTo(table(name(...) -> same behaviour.


  • .renameTo("`TestDatabase`.`Foo`") -> Escapes the name with backticks, treats it as one name instead of a qualified name.


I'm wondering if I'm missing something, if this is intended behaviour, or maybe even a bug or design shortcoming of JOOQ.



Is there a way to rename the table using fully qualified names?



Thank you!










share|improve this question























  • Did you try using raw jdbc connections?

    – Mon Calamari
    Nov 8 '18 at 15:13











  • @MonCalamari That works of course, however, this question is specifically about keeping the JOOQ abstraction for cross DB support, or else I'd have to move this code into DB specific code for every DB I want to support.

    – Dominic
    Nov 8 '18 at 15:17











  • If I were you I would raise an issue with github.com/jOOQ/jOOQ

    – Mon Calamari
    Nov 8 '18 at 15:21













  • @MonCalamari Thanks, I will consider it.

    – Dominic
    Nov 8 '18 at 15:51














4












4








4








I have a scala application that manages multiple MySQL database schemas, which includes modifying (adding, renaming, etc.) tables. The commands are issued over a connection pool that connects to a generic management database in the database server.



Because the application is designed to be cross-database, I use JOOQ to render SQL queries (execution is done via a separate JDBC module).



I experience issues with JOOQs alterTable(...).renameTo(...) DSL - consider the following example:



We have a table "TestTable" in database "TestDatabase". Let's say I want to rename that table simply to "Foo", keeping it in "TestDatabase".



This code:



...
val context = DSL.using(SQLDialect.MYSQL_5_7)
val query = context
.alterTable(table(name("TestDatabase", "TestDatabase")))
.renameTo(name("TestDatabase", "Foo"))
...


Generates: ALTER TABLE `TestDatabase`.`TestTable` RENAME TO `Foo`
However, since the connection pool I'm using is connected to my management database, it just renames the table to "Foo" and moves it to my management database. I would have expected the SQL to be: ALTER TABLE `TestDatabase`.`TestTable` RENAME TO `TestDatabase`.`Foo`. I tried a variety of alternatives to invoke the .renameTo method and convice it to use the fully qualified name, to no avail:





  • .renameTo(table(name(...) -> same behaviour.


  • .renameTo("`TestDatabase`.`Foo`") -> Escapes the name with backticks, treats it as one name instead of a qualified name.


I'm wondering if I'm missing something, if this is intended behaviour, or maybe even a bug or design shortcoming of JOOQ.



Is there a way to rename the table using fully qualified names?



Thank you!










share|improve this question














I have a scala application that manages multiple MySQL database schemas, which includes modifying (adding, renaming, etc.) tables. The commands are issued over a connection pool that connects to a generic management database in the database server.



Because the application is designed to be cross-database, I use JOOQ to render SQL queries (execution is done via a separate JDBC module).



I experience issues with JOOQs alterTable(...).renameTo(...) DSL - consider the following example:



We have a table "TestTable" in database "TestDatabase". Let's say I want to rename that table simply to "Foo", keeping it in "TestDatabase".



This code:



...
val context = DSL.using(SQLDialect.MYSQL_5_7)
val query = context
.alterTable(table(name("TestDatabase", "TestDatabase")))
.renameTo(name("TestDatabase", "Foo"))
...


Generates: ALTER TABLE `TestDatabase`.`TestTable` RENAME TO `Foo`
However, since the connection pool I'm using is connected to my management database, it just renames the table to "Foo" and moves it to my management database. I would have expected the SQL to be: ALTER TABLE `TestDatabase`.`TestTable` RENAME TO `TestDatabase`.`Foo`. I tried a variety of alternatives to invoke the .renameTo method and convice it to use the fully qualified name, to no avail:





  • .renameTo(table(name(...) -> same behaviour.


  • .renameTo("`TestDatabase`.`Foo`") -> Escapes the name with backticks, treats it as one name instead of a qualified name.


I'm wondering if I'm missing something, if this is intended behaviour, or maybe even a bug or design shortcoming of JOOQ.



Is there a way to rename the table using fully qualified names?



Thank you!







mysql scala jooq






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 8 '18 at 15:06









DominicDominic

9517




9517













  • Did you try using raw jdbc connections?

    – Mon Calamari
    Nov 8 '18 at 15:13











  • @MonCalamari That works of course, however, this question is specifically about keeping the JOOQ abstraction for cross DB support, or else I'd have to move this code into DB specific code for every DB I want to support.

    – Dominic
    Nov 8 '18 at 15:17











  • If I were you I would raise an issue with github.com/jOOQ/jOOQ

    – Mon Calamari
    Nov 8 '18 at 15:21













  • @MonCalamari Thanks, I will consider it.

    – Dominic
    Nov 8 '18 at 15:51



















  • Did you try using raw jdbc connections?

    – Mon Calamari
    Nov 8 '18 at 15:13











  • @MonCalamari That works of course, however, this question is specifically about keeping the JOOQ abstraction for cross DB support, or else I'd have to move this code into DB specific code for every DB I want to support.

    – Dominic
    Nov 8 '18 at 15:17











  • If I were you I would raise an issue with github.com/jOOQ/jOOQ

    – Mon Calamari
    Nov 8 '18 at 15:21













  • @MonCalamari Thanks, I will consider it.

    – Dominic
    Nov 8 '18 at 15:51

















Did you try using raw jdbc connections?

– Mon Calamari
Nov 8 '18 at 15:13





Did you try using raw jdbc connections?

– Mon Calamari
Nov 8 '18 at 15:13













@MonCalamari That works of course, however, this question is specifically about keeping the JOOQ abstraction for cross DB support, or else I'd have to move this code into DB specific code for every DB I want to support.

– Dominic
Nov 8 '18 at 15:17





@MonCalamari That works of course, however, this question is specifically about keeping the JOOQ abstraction for cross DB support, or else I'd have to move this code into DB specific code for every DB I want to support.

– Dominic
Nov 8 '18 at 15:17













If I were you I would raise an issue with github.com/jOOQ/jOOQ

– Mon Calamari
Nov 8 '18 at 15:21







If I were you I would raise an issue with github.com/jOOQ/jOOQ

– Mon Calamari
Nov 8 '18 at 15:21















@MonCalamari Thanks, I will consider it.

– Dominic
Nov 8 '18 at 15:51





@MonCalamari Thanks, I will consider it.

– Dominic
Nov 8 '18 at 15:51












1 Answer
1






active

oldest

votes


















2














That's a bug in jOOQ: https://github.com/jOOQ/jOOQ/issues/8042



Your workaround is close. This doesn't work:



.renameTo("`TestDatabase`.`Foo`")


As you've noticed, behind the scenes, the DSL.name() API is used to wrap the target name, because the renameTo() method doesn't implement the plain SQL templating API. You can, however, explicitly use plain SQL templating by writing as a workaround:



.renameTo(table("`TestDatabase`.`Foo`"))





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53210516%2fhow-to-scope-a-mysql-jooq-rename-table-query-to-the-same-database%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    That's a bug in jOOQ: https://github.com/jOOQ/jOOQ/issues/8042



    Your workaround is close. This doesn't work:



    .renameTo("`TestDatabase`.`Foo`")


    As you've noticed, behind the scenes, the DSL.name() API is used to wrap the target name, because the renameTo() method doesn't implement the plain SQL templating API. You can, however, explicitly use plain SQL templating by writing as a workaround:



    .renameTo(table("`TestDatabase`.`Foo`"))





    share|improve this answer




























      2














      That's a bug in jOOQ: https://github.com/jOOQ/jOOQ/issues/8042



      Your workaround is close. This doesn't work:



      .renameTo("`TestDatabase`.`Foo`")


      As you've noticed, behind the scenes, the DSL.name() API is used to wrap the target name, because the renameTo() method doesn't implement the plain SQL templating API. You can, however, explicitly use plain SQL templating by writing as a workaround:



      .renameTo(table("`TestDatabase`.`Foo`"))





      share|improve this answer


























        2












        2








        2







        That's a bug in jOOQ: https://github.com/jOOQ/jOOQ/issues/8042



        Your workaround is close. This doesn't work:



        .renameTo("`TestDatabase`.`Foo`")


        As you've noticed, behind the scenes, the DSL.name() API is used to wrap the target name, because the renameTo() method doesn't implement the plain SQL templating API. You can, however, explicitly use plain SQL templating by writing as a workaround:



        .renameTo(table("`TestDatabase`.`Foo`"))





        share|improve this answer













        That's a bug in jOOQ: https://github.com/jOOQ/jOOQ/issues/8042



        Your workaround is close. This doesn't work:



        .renameTo("`TestDatabase`.`Foo`")


        As you've noticed, behind the scenes, the DSL.name() API is used to wrap the target name, because the renameTo() method doesn't implement the plain SQL templating API. You can, however, explicitly use plain SQL templating by writing as a workaround:



        .renameTo(table("`TestDatabase`.`Foo`"))






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 13 '18 at 10:51









        Lukas EderLukas Eder

        133k70433949




        133k70433949






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53210516%2fhow-to-scope-a-mysql-jooq-rename-table-query-to-the-same-database%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Florida Star v. B. J. F.

            Danny Elfman

            Retrieve a Users Dashboard in Tumblr with R and TumblR. Oauth Issues