Accessing Pervasive.SQL With Perl

Page Last Modified:

Home Links ODBC (DBI) Contact

All content on this site is copyright
Neil Hughes 2010 - 2017

DBI + ODBC - Manipulating Data

Just as with fetching the data, when we want to INSERT, UPDATE or DELETE rows in the database we can follow the same procedure or connecting to the database, preparing the query and then executing it. So, to add a row:

$dbHandle = DBI->connect('dbi:ODBC:DEMODATA', '', '');
$stHandle = $dbHandle->prepare("INSERT INTO Course (Name, Description, Credit_Hours, Dept_Name) VALUES ('PERL 01', 'Basic Perl Programming', 1, 'Computing')");
$stHandle->execute();

to update that row change the query to :

$stHandle = $dbHandle->prepare("UPDATE Course SET Credit_Hours = 2 WHERE Name = 'PERL 01'");

and to delete it:

$stHandle = $dbHandle->prepare("DELETE FROM Course WHERE Name = 'PERL 01'");

In all three cases the execute call should return the number of rows affected. If no rows are affected then execute returns 0E0 rather than just zero, because 0E0 is treated by Perl as a true value which means the call was successful. A return of -1 means that the count affected is unknown and a return of undef means there was an error.

More detailed examples can be found here:

 

Home Links ODBC (DBI) Contact