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.5k 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 26 Aug 2014, 21:14 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 26 Aug 2014, 21:52 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 27 Aug 2014, 08:17 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 27 Aug 2014, 08:27 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 27 Aug 2014, 08:46 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
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 27 Aug 2014, 08:50 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 27 Aug 2014, 09:23 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
                • S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 27 Aug 2014, 11:56 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 27 Aug 2014, 14:30 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
                    • S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 27 Aug 2014, 20:12 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

                      13/13

                      27 Aug 2014, 20:12

                      • Login

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