Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Test for number or string

by nedals (Deacon)
on May 03, 2003 at 00:39 UTC ( #255204=note: print w/replies, xml ) Need Help??


in reply to Test for number or string

Thanks for the node but I don't think placeholders will solve the problem. I could use them (again I think) to insert the lines.

Let me expand a little further. The '$fileline" contains a record... (id,'name','address',..... for example) which is build by my script. This is then downloaded and saved as backup. On the upload side, the only thing my script knows is the table name. The $fileline contains the correct number of fields to be inserted. I don't believe that the placeholder will insert the appropiate quotes in each of the fields.

My current solution involves getting a DESCRIPTION of the table to deterime which fields contain strings (varchar) and then inserting the quotes on the download side. Pretty long-winded

Replies are listed 'Best First'.
Re: Re: Test for number or string
by pfaut (Priest) on May 03, 2003 at 00:48 UTC

    This is exactly the problem placeholders are intended to solve. With placeholders, you just mark where you want to insert data into your SQL statement and the database interface layers take care of passing that data to the database where it belongs. I always use placeholders and have never had to worry about quoting.

    Look in the Tutorials section. There are plenty of tutorials that explain how to use DBI with placeholders.

    Also, you'll get faster and more accurate answers to your questions if you give all the details you can up front instead of being miserly with information about what you are really trying to do.

    90% of every Perl application is already written.
    dragonchild
      Too true :)
      I guess I thought there would be a simple answer to the original question.

      UPDATE
      Let me make sure I understand what you are saying.

      I can easily download my data with no quotes in the form...

      id,name,address,etc

      Now I upload this same data using something like this...
      my $sql = "INSERT INTO tablename VALUES(?)"; my $sth = $dbh->prepare($sql); foreach my $record (@filedata) { $sth->execute($record); }
      ... and I don't have to worry about quotes, etc.?
        Exactly that is the case. Even if you insist on quoting yourself though, you should know which columns expect numbers and which expect strings, so you don't need to examine the value either way.

        Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (6)
As of 2021-04-21 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?