Home : Documentation : DBIx::Recordset
Google Web perl.apache.org

 
Home
 
Features
 
Introduction
 
Documentation
 
README
 
README.v2
 
Configuration
 
Embperl
 
Embperl::Object
 
Embperl::Form::Validate
 
Embperl::Syntax
 
Embperl::Recipe
 
Embperl::Mail
 
1.3.6 documentation
 
DBIx::Recordset
 
Installation
 
Download
 
Support
 
Changes
 
Wiki
 
More infos
 
Add info about Embperl
 
Login

    Stable 2.4.0
    Beta 2.5.0_3
Support the development of Embperl! More...
MODIFYING DATA DIRECTLY
[ << Prev: DATA ACCESS ] [ Content ] [ Next: WORKING WITH MULTIPLE TABLES >> ]

One way to update/insert data into the database is by using the Update, Insert or Execute method of the DBIx::Recordset object. A second way is to directly assign new values to the result of a previous Select/Search.

Example: # setup a new object and search all records with name xyz *set = DBIx::Recordset -> Search ({'!DataSource' => 'dbi:db:tab', '!PrimKey => 'id', '!Table' => 'tabname', 'name' => 'xyz'}) ;

  #now you can update an existing record by assigning new values
  #Note: if possible, specify a PrimKey for update to work faster
  $set[0]{'name'} = 'zyx' ;

  # or insert a new record by setting up an new array row
  $set[9]{'name'} = 'foo' ;
  $set[9]{'id'}   = 10 ;

  # if you don't know the index of a new row you can obtain
  # one by using Add
  my $i = $set -> Add () ;
  $set[$i]{'name'} = 'more foo' ;
  $set[$i]{'id'}   = 11 ;

  # or add an empty record via Add and assign the values to the current
  # record
  $set -> Add () ;
  $set{'name'} = 'more foo' ;
  $set{'id'}   = 11 ;

  # or insert the data directly via Add
  $set -> Add ({'name' => 'even more foo',
		'id'   => 12}) ;

  # NOTE: up to this point, NO data is actually written to the db!

  # we are done with that object,  Undef will flush all data to the db
  DBIx::Recordset::Undef ('set') ;

IMPORTANT: The data is not written to the database until you explicitly call flush, or a new query is started, or the object is destroyed. This is to keep the actual writes to the database to a minimum.


[ << Prev: DATA ACCESS ] [ Content ] [ Next: WORKING WITH MULTIPLE TABLES >> ]

© 1997-2012 Gerald Richter / ecos gmbh