Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If I understand the question correctly, it sounds like you're after <a href="http://search.cpan.org/perldoc?SQL::Abstract" rel="nofollow noreferrer">SQL::Abstract</a>. First, we create an <code>SQL::Abstract</code> object:</p> <pre><code>use SQL::Abstract; my $sql = SQL::Abstract-&gt;new; </code></pre> <p>Now, as an example, we'll use it to insert some data into a table:</p> <pre><code>my %record = ( FirstName =&gt; 'Buffy', LastName =&gt; 'Summers', Address =&gt; '1630 Revello Drive', City =&gt; 'Sunnydale', State =&gt; 'California', Occupation =&gt; 'Student', Health =&gt; 'Alive', ); my ($stmt, @bind) = $sql-&gt;insert(’staff’,\%record); </code></pre> <p>This results in:</p> <pre><code>$stmt = "INSERT INTO staff (FirstName, LastName, Address, City, State, Occupation, Health) VALUES (?, ?, ?, ?, ?, ?, ?)"; @bind = ('Buffy','Summers','1630 Revello Drive', 'Sunnydale',’California','Student','Alive'); </code></pre> <p>The nice thing about this is we can pass it directly to DBI:</p> <pre><code> $dbh-&gt;do($stmt, undef, @bind); </code></pre> <p>Of course, you want to be updating records, not just inserting them. Luckily, this is also quite easy:</p> <pre><code>my $table = 'People'; my %new_fields = ( Occupation =&gt; 'Slayer', Health =&gt; 'Dead', ); my %where = ( FirstName =&gt; 'Buffy', LastName =&gt; 'Summers', ); my ($stmt, @bind) = $sql-&gt;update($table, \%new_fields, \%where); $dbh-&gt;do($stmt, undef, @bind); </code></pre> <p>This produces:</p> <pre><code>$stmt = 'UPDATE People SET Health = ?, Occupation = ? WHERE ( FirstName = ? AND LastName = ? )'; @bind = ('Dead', 'Slayer', 'Buffy', 'Summers'); </code></pre> <p>If you're after more information about <code>SQL::Abstract</code>, I recommend you look at its <a href="http://search.cpan.org/perldoc?SQL::Abstract" rel="nofollow noreferrer">CPAN page</a>. There's also a chapter in <a href="http://perltraining.com.au/" rel="nofollow noreferrer">Perl Training Australia</a>'s <em>Database Programming with Perl</em> manual, which are freely available from our <a href="http://perltraining.com.au/notes.html" rel="nofollow noreferrer">course notes page</a>.</p> <p>All the best,</p> <p><em>Paul</em></p> <p>Disclaimer: I'm managing director of Perl Training Australia, and therefore think that our course notes are pretty good.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload