I'm having a devil of a time trying to insert a Windows UNC share into my MySQL database. The DBI quote function doesn't seem to be behaving as I would expect. Here's a little example:

#!/usr/bin/perl -w
use DBI;
my $unc = '\\somebox.somehost.com\someshare';
my $dsn = "DBI:mysql:cmdb;localhost";
my $dbh = DBI->connect($dsn,'root','') or die;

my $quoted_unc = $dbh->quote($unc);
$dbh->do("INSERT INTO mytable (uncname) VALUE ($quoted_unc)");

When I run this code, and then run a select against mytable, my UNC share is not the same as it was when it went in:


If I double-quote the unc variable like this:

my $unc = "\\somebox.somehost.com\someshare";

The result is different, but not much better:


Anyone know how to get around this problem?

9 Years
Discussion Span
Last Post by roswell1329

Hi KevinADC, thanks for the reply. As it turns out, the quote function was operating as expected. My problem was after the UNC was inserted, I was doing a select on that table and comparing the value that I inserted with the value that made it into the database, and I was doing the insert and comparison with 2 different methods:

To insert data:

$dbh->do("INSERT INTO table (uncname) VALUE ('$unc_name')");

To select data:

$sth = $dbh->prepare("SELECT uncname FROM table WHERE uncname = ?");

So, the select had the benefit of the quoting function, while the insert didn't. Thanks for the post!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.