insert_auto_inc_row

The insert_auto_inc_row method inserts a row into the specified table that has an auto-increment column.

Method Synopsis

NCP::DBI_Factory::insert_auto_inc_row($dbHandle,$tableName, 
$tableRow, $autoIncColumnName)

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_auto_inc_row method inserts the row specified in the $tableRow parameter.
$tableRow
Specifies a hash of scalars keyed on the column name.
$autoIncColumnName
Specifies the name of the auto-increment column in the specified table.

Description

The insert_auto_inc_row method inserts the row specified in the $tableRow parameter into the table specified in the $tableName parameter. The table is expected to contain the auto-increment column name specified in the $autoIncColumnName parameter.

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

NotesĀ®

To ensure that the insert_auto_inc_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_auto_inc_row method to insert rows in tables that have an auto- increment column. Use the insert_row method to insert rows in tables that have do not have an auto- increment column.

Example Usage

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

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

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

my $autoIncColumnName = "entityId";

    my $newId = NCP::DBI_Factory::insert_auto_inc_row(
        $dbh, $tableName, \%row, $autoIncColumnName) 
        or print "Insert failed ", $dbh->errstr "\n";

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

Returns

Upon completion, the insert_auto_inc_row method returns the new auto-increment value, provided that the row could be uniquely identified by the fields that the insert_auto_inc_row method just inserted into the specified table.

See Also