Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: DBI placeholders for spatial data

by LanX (Saint)
on Jun 25, 2021 at 23:42 UTC ( [id://11134307]=note: print w/replies, xml ) Need Help??


in reply to DBI placeholders for spatial data

  • I can't find any Site::Point on CPAN.
  • I don't know which DB you are using.
  • The specification for that "POINT Datatype" is not clear.

    I can only guess that your query should rather include something like ST_GeomFromText(?,4326) with the string 'POINT ( -4.75513748886666 58.2553702983331 )' as argument.

    Placeholders are for values not for nested SQL-Terms like ST_GeomFromText( String, Integer )

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

  • Replies are listed 'Best First'.
    Re^2: DBI placeholders for spatial data
    by Bod (Parson) on Jun 26, 2021 at 00:21 UTC
      I can't find any Site::Point on CPAN.

      You won't - it is a module specific to this application. Although, it is quite a general representation of a point on the globe so it might make a useful CPAN addition.

      I don't know which DB you are using.

      Sorry - I should have included that it is MariaDB.
      Spatial datatypes are something that varies quite a bit between databases. Even between MySQL and MariaDB!

      The specification for that "POINT Datatype" is not clear.

      Exactly!

      I had tried substituting just the numeric values through placeholders like so ST_GeomFromText('POINT( ? ? )') which didn't work. I don't recall the error. I shall look tomorrow. I hadn't tried ST_GeomFromText(?,4326) as you suggest. Thanks - I'll try that tomorrow too...

        Sorry - I should have included that it is MariaDB.

        It would also be helpful to know which version of MariaDB you are connecting to and also which DBD driver (and version) you are using to make that connection.


        🦛

          10.2.39-MariaDB

          I was using DBD::mysql until yesterday when I switched this project to DBD::MariaDB. I'm still using the MySQL driver for other projects that don't require spatial data.

          However, I cannot find DBD::MariaDB listed amongst the installed modules so I am struggling to find the version of that! DBD::mysql is version 4.050

          edit:

          Running cpan -D DBD::MariaDB tells me that the module is not installed!

          However, DBI->connect("DBD:MariaDB:database=xxx", $user, $pass); connects without problem.

          Further edit

          foreach my $driver(DBI->available_drivers) { print "$driver\n"; }
          Produces:
          DBM ExampleP File Gofer Mem Pg Proxy SQLite SQLite2 Sponge mysql
          So I guess that DBI->connect("DBD:MariaDB:database=... is using some form of default driver.

        >    ST_GeomFromText('POINT( ? ? )')

        To make my argument clearer: this 'POINT( ? ? )' might look like an SQL function but it's a string which is parsed by ST_GeomFromText() !

        Please note the missing commas, too. Function arguments in SQL are comma separated.

        The MariaDB documentation calls the argument a WKT with T for Text! °

        WKT is not SQL, pretty much like SQL is not Perl

        Your string passed here to ST_GeomFromText() will always include literal question marks in your example.

        There is nothing like ? placeholder handling inside strings in SQL!

        The error you get will be along the line "too many arguments for placeholders" because the two ? inside a string are just ignored.

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery

        °) The Well-Known Text (WKT) representation of Geometry is designed to exchange geometry data in ASCII form

        update

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: note [id://11134307]
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others goofing around in the Monastery: (6)
    As of 2024-04-19 08:16 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found