Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Update Blank Fields In MySQL

by Milti (Beadle)
on Feb 05, 2014 at 21:54 UTC ( [id://1073614]=perlquestion: print w/replies, xml ) Need Help??

Milti has asked for the wisdom of the Perl Monks concerning the following question:

Say I have a table with 5 fields. The first INSERT into the table requires and permits only the insertion of data into fields 1,2, and 3. At a later time a user might want to ad data in fields 4 and 5. If those fields are set to NULL the UPDATE query does not seem to work, apparently because there is nothing in those fields to update. There must be some way around this problem that I am missing. If I set the fields to NOT NULL and attempt to make the insertion in to fields 1,2, and 3, the program stops and I get an error saying field 4 doesn't have a default value (mysql shows that it does, i.e. NULL). The data type in all the fields is varchar. So what do I do? Any help will be greatly appreciated.

Replies are listed 'Best First'.
Re: Update Blank Fields In MySQL
by mbethke (Hermit) on Feb 05, 2014 at 22:11 UTC
    So what do I do?
    Just show your code. It sounds more like a problem with SQL than with Perl but I suppose it's not very complicated in any case.
Re: Update Blank Fields In MySQL
by Anonymous Monk on Feb 06, 2014 at 10:27 UTC
    This is nothing but a guess, but
    If those fields are set to NULL the UPDATE query does not seem to work, apparently because there is nothing in those fields to update.
    What's the query? "WHERE field4 = NULL"? Not going to work. "WHERE field4 IS NULL" will.
Re: Update Blank Fields In MySQL
by Jim (Curate) on Feb 06, 2014 at 00:00 UTC

    There's an extraneous left parenthesis on line 23 of your Perl script.

    If fixing that bug doesn't help, try this.

    Jim

Re: Update Blank Fields In MySQL
by mendeepak (Scribe) on Feb 07, 2014 at 06:58 UTC

    set a default value for your fields and as others told you it sounds more like SQL problem than Perl.
    FYI : whenever you write a question please provide what you have tried with your code

    Deepak
      NULL is a very good default value, you know. Don't be afraid of them.
        Thanks! I set the default values on each column and used placeholders with the query. The problem has been solved!!! Many thanks to all who responded.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-09-17 21:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (22 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.