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

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
Hi Monks,
I have written a script which checks if an id is already present in the database and depending on that it does other things. Following is the part of the code where i have confusion:
$mysql->query(q{select id from id_table where id = '1'}); if ( $mysql->has_selected_record) { #do something; } else { #do something else }
In the above 'if loop', the condition always return true even if the id is not present in the table. Am i misunderstanding the use of 'has_selected_record()'? If yes how do i know whether the query has returned result or not? I understand I can create an iterator and get the exact result but i don't think that is needed because
1) I don't want the result- I just want to know whether there is a result or not.
2) The query will be excuted a lot of times and creating iterator each time will not be resource friendly.
I have gone throught the documentation present at CPAN along with the module Net::MySQL but unfortunately did not get much info. Could you please clear my doubt?


--Let Logic Rule--

In reply to using has_selected_record() of Net::MySQL by ranjan_jajodia

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.