insert_row

The insert_row method inserts a row into the specified table.

Method Synopsis

NCP::DBI_Factory::insert_row($dbHandle,$tableName, $tableRow)

Parameters

$dbHandle
Specifies the DBI handle returned in a previous call to the createDbHandle method. This handle supplies the context for connecting to the specified NCIM topology database.
$tableName
Specifies the name of the table into which the insert_row method inserts the row specified in the $tableRow parameter.
$tableRow
Specifies a hash of scalars keyed on the column name.

Description

The insert_row method inserts the row specified in the $tableRow parameter into the table specified in the $tableName parameter. The insert_row method automatically interpolates any strings in $tableRow into double-quoted strings.

Note: You can also call the DBI rollback interface to undo the most recent insert row change.

NotesĀ®

To ensure that the insert_row method can print appropriate messages to a log file, you must have previously specified a log handle (that is, a reference to a file object) by calling the setLogHandle method. Otherwise, the method sends these messages to STDOUT.

Use the insert_row method to insert rows in tables that have do not have an auto- increment column. Use the insert_auto_inc_row method to insert rows in tables that have an auto- increment column.

Example Usage

The following code example illustrates a typical call to the insert_row method:

my $tableName = "entityNameCache";
    my $name = "fred";

    # Note: the string in $name will automatically be quoted
    my %row = (
        entityName => $name,
        domainMgrId => 1
    );

    NCP::DBI_Factory::insert_row($dbh, $tableName, \%row) 
        or print "Insert failed ", $dbh->errstr "\n";

# Changes only take effect when commit is called
    if ($happy)
    {
        $dbh->commit();
    }
    else
    {
        $dbh->rollback();
    }

Returns

Upon completion, the insert_row method returns whatever the standard DBI statement handle execute method returns.

See Also