Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Qt5 - MySQL - create trigger not working
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Qt5 - MySQL - create trigger not working

Scheduled Pinned Locked Moved General and Desktop
13 Posts 2 Posters 4.6k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Something is not clear. When you say copy/paste do you mean paste it in the sqlconsole ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    0
    • N Offline
      N Offline
      nando76
      wrote on last edited by
      #3

      [quote author="SGaist" date="1409084557"]Hi,

      Something is not clear. When you say copy/paste do you mean paste it in the sqlconsole ?[/quote]

      Hi :)
      yes exactly. I copy paste the generated output to the mysql console and it works.

      But when calling QSqlQuery exec method with a QString containg the complete stuff exec do not complain but the triggers are not created.
      The _TRACE tables are created... But not the triggers...

      Greetings

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #4

        Ok,

        One thing you could try is to break the query to send one command at a time.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • N Offline
          N Offline
          nando76
          wrote on last edited by
          #5

          [quote author="SGaist" date="1409087690"]Ok,

          One thing you could try is to break the query to send one command at a time.[/quote]
          OK thank you.. Will try this tomorrow and the report...
          Good n8

          1 Reply Last reply
          0
          • N Offline
            N Offline
            nando76
            wrote on last edited by
            #6

            Hi,
            i broke it down. And i can see that the following request works fine on the mysql console but not when calling QSqlQuery's exec method.

            @
            DROP TRIGGER IF EXISTS TR_INSERT_warningLines;
            DELIMITER $$
            CREATE TRIGGER TR_INSERT_warningLines BEFORE INSERT ON warningLines
            FOR EACH ROW
            BEGIN
            INSERT INTO warningLines_TRACE (warning_id,attribute,operator,value,ACTION_TIME, SYNC_VERSION)
            VALUES (new.warning_id,new.attribute,new.operator,new.value,now(),0);
            END $$
            @

            Very strange because query.exec(...) does not complain.

            Any idea?

            Greetings
            Nando

            1 Reply Last reply
            0
            • N Offline
              N Offline
              nando76
              wrote on last edited by
              #7

              I tried to call
              @
              query.prepare(request)
              @

              and then
              @
              query.exec(...)
              @

              now i get an error:
              @
              "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$
              @

              must now check how to deal with this problem... will report.

              Greetings

              1 Reply Last reply
              0
              • N Offline
                N Offline
                nando76
                wrote on last edited by
                #8

                I solved it!

                2 problems:

                1. I had to split the @DROP TRIGGER IF EXISTS@
                  and the @CREATR TRIGGER@ part into two separate query executions (thank you SGaist for the tip.)

                2. do not use @DELIMITER $$@ because it seems to be only for mysql command line client.

                With these changes everything works as expected :)

                Greetings

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  Nice !

                  By the way, where did the original SQL query come from ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    nando76
                    wrote on last edited by
                    #10

                    [quote author="SGaist" date="1409129425"]Nice !

                    By the way, where did the original SQL query come from ?[/quote]

                    I (try to) generate the query (trace tables + triggers) in a generic way for all given tables of a db instance.
                    So the queries are generated dynamically.

                    Greetings
                    Nando

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      Ok, I was wondering where the DELIMITER $$ came from so you might have used a tool to generate the queries for you

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • N Offline
                        N Offline
                        nando76
                        wrote on last edited by
                        #12

                        Yes, i took this DELIMITER $$ stuff from some documentation.
                        Didn't know that this is mysql-client-console specific stuff.
                        Thanks for your help :)

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          Dangerous documentation :D

                          You're welcome !

                          Happy coding :)

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved