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. QSqlQuery is not able to update geolocation LineString in DB

QSqlQuery is not able to update geolocation LineString in DB

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 2 Posters 1.6k Views 1 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.
  • M Offline
    M Offline
    MrEinsA
    wrote on last edited by koahnig
    #1

    Hi Guys,

    i have a question related to geolocation in QSqlQuery:
    Maybe you can help me ... i cannot find any topic related to this issue.

    The SQL Error:

    "UPDATE file SET geographical_location=? WHERE file_id=?;"
    QSqlError("1416", "QMYSQL3: Unable to execute statement", "Cannot get geometry object from data you send to the GEOMETRY field")

    What i did:

    I have code like this (pseudo code):

    QString strQ("UPDATE file SET geographical_location=:geo WHERE file_id=:fi;");
    QSqlQuery q;
    q.prepare(strQ);
    QString geoLoc("ST_LineStringFromText('LineString(23.5502 4.71853,47.5502 22,2221)')");
    q.bindValue(":fi", 1);
    q.bindValue(":geo", geoLoc);
    q.exec();
    

    The error above is reported.

    I cannot get why its not working ... in the mysql workbench it is running with this query.

    Any ideas?

    Thank guys!!!!

    [edit: koahnig] code tags added

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MrEinsA
      wrote on last edited by MrEinsA
      #6

      Thanks guys ... finally i made it by myself.

      The query was simply wrong ... it should look like this:

      QString strQ("UPDATE file SET geographical_location=ST_LineStringFromText(:geo) WHERE file_id=:fi;");
      QSqlQuery q;
      q.prepare(strQ);
      QString geoLoc("LineString(23.5502 4.71853,47.5502 22,2221"));
      q.bindValue(":fi", 1);
      q.bindValue(":geo", geoLoc);
      q.exec();
      

      The function ("ST_LineStringFromText") has to be called inside the query.

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

        Hi,

        Did you try to print the created query ?

        Does it match what you are using in workbench ?

        By the way, which version of Qt are you using ? MySQL ? On what platform ?

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

        M 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Did you try to print the created query ?

          Does it match what you are using in workbench ?

          By the way, which version of Qt are you using ? MySQL ? On what platform ?

          M Offline
          M Offline
          MrEinsA
          wrote on last edited by
          #3

          @SGaist

          Thanks for your quick response.

          Like above this is the output if i print the quer with: qDebug() << q.executedQuery();
          "UPDATE file SET geographical_location=? WHERE file_id=?;"

          I use mysql 5.7 and also Qt 5.7. Windows.
          If i execute exactly the same query in the mysql workbench it is working.

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

            That's surprising, the executed query seems to miss the bonded parameters. Did you try using positional bindings ?

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

            M 1 Reply Last reply
            0
            • SGaistS SGaist

              That's surprising, the executed query seems to miss the bonded parameters. Did you try using positional bindings ?

              M Offline
              M Offline
              MrEinsA
              wrote on last edited by MrEinsA
              #5

              @SGaist
              Good morning, jep i did it and the error is exactly the same.

              Very strange.

              I add the geolocation as string could it be, that the simple quotes will be added and then the db reject it, because it want to have a geo (blob) object?

              1 Reply Last reply
              0
              • M Offline
                M Offline
                MrEinsA
                wrote on last edited by MrEinsA
                #6

                Thanks guys ... finally i made it by myself.

                The query was simply wrong ... it should look like this:

                QString strQ("UPDATE file SET geographical_location=ST_LineStringFromText(:geo) WHERE file_id=:fi;");
                QSqlQuery q;
                q.prepare(strQ);
                QString geoLoc("LineString(23.5502 4.71853,47.5502 22,2221"));
                q.bindValue(":fi", 1);
                q.bindValue(":geo", geoLoc);
                q.exec();
                

                The function ("ST_LineStringFromText") has to be called inside the query.

                1 Reply Last reply
                1

                • Login

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