Navigation

    APPDRAG Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular

    REMINDER

    Please be respectful of all AppDragers! Keep it really civil so that we can make the AppDrag community of builders as embracing, positive and inspiring as possible.

    Update multiple records via SQLselect and one API call

    General Discussion
    2
    9
    289
    Loading More Posts
    • 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.
    • Dick Honing
      Dick Honing last edited by

      Hi there,

      I'm trying to update multiple records via one API Call and was wondering what the best approach is.

      I've already created an API in which I sent the SQL as input parameter, i.e.:

      {
      "SQL": "REPLACE INTO trips (id, name) VALUES (998, 123);REPLACE INTO trips (id, name) VALUES (999, 456);"
      }

      This works! ... however, only with numeric data. As soon as I want to send string data and ad the '' single quotes, I get the following error:

      "SQL Syntax Error near 'test'');REPLACE INTO trips (id, name) VALUES (999, 456)' at line 1",

      I've tried escaping the '' quotes, but that doesn't fix the problem.

      So I was wondering whether there's another/better approach for this.

      Thanks in advance and best regards - Dick

      1 Reply Last reply Reply Quote 0
      • Wassim
        Wassim last edited by

        @Dick-Honing said in Update multiple records via SQLselect and one API call:

        This works! ... however, only with numeric

        Hi Dick,

        First of all what are you using to do this update? (maybe post a screenshot it would be easier)

        0f93daa7-2239-410b-8ee9-84270e2d7ab5-image.png

        Second question, why do you use REPLACE INTO instead of

        UPDATE trips SET name='yourname' WHERE id=yourid;
        

        ?

        1 Reply Last reply Reply Quote 0
        • Dick Honing
          Dick Honing last edited by

          Hi Wassim

          I use Raw SQL Select. I mentioned SQLselect in the subject of my message, but that apparently wasn't clear enough ... sorry.

          I use replace instead of update as I want the same function to both create new records as well as modify/update existing records.

          Is there a (preferred) method of adding/updating multiple records simultaneously in one API call? ... in other words not having to do an API call for each record your want to add/update ...

          Thanks again and best regards - Dick

          1 Reply Last reply Reply Quote 0
          • Wassim
            Wassim last edited by

            @Dick-Honing said in Update multiple records via SQLselect and one API call:

            REPLACE INTO trips (id, name) VALUES (998, 123);REP

            Can you send a screenshot when you set text values?

            Dick Honing 2 Replies Last reply Reply Quote 0
            • Dick Honing
              Dick Honing @Wassim last edited by

              @Wassim Screenshot 2020-10-21 at 16.28.51.png

              1 Reply Last reply Reply Quote 0
              • Dick Honing
                Dick Honing @Wassim last edited by

                @Wassim Hi Wassim, this is probably better SQL code, but still throws back an error when using single quotes '' to enclose strings. Strange enough, this setup works fine if I only use numbers.Screenshot 2020-10-21 at 19.17.39.png

                1 Reply Last reply Reply Quote 0
                • Dick Honing
                  Dick Honing last edited by

                  Eureka ... I've got it working ... a string needs to be enclosed by escaped double quotes ... so I can now insert/update multiple records in one call 🙂

                  'Screenshot 2020-10-21 at 21.09.24.png

                  1 Reply Last reply Reply Quote 0
                  • Wassim
                    Wassim last edited by

                    Hello,

                    Sorry for late answer.

                    Glad you found a solution!
                    Well the problem is that we already escape the strings and didn't expect to use it this way with multiple values. @PARAM_parameter is originally meant to be a single value instead of a query.

                    Dick Honing 1 Reply Last reply Reply Quote 0
                    • Dick Honing
                      Dick Honing @Wassim last edited by

                      @Wassim Am I allowed to fill the @PARAM_paramater with multiple parameters or am I pushing the envelope?

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post