Skip Top Menu Navigation
Skip Top Menu Navigation

The FREE Enterprise Open Source Database

  Software Tools Interfaces Development Documentation
 

 
You Are Here:  SAP DB > 7.3 > Interfaces > SAP::DBTech::sapdb (Perl)

SAP::DBTech::sapdb (Perl)

Module Contents LONG values Installation Examples Exceptions

Module Contents

class SapDB_Session

Allows the execution of SQL statements.
When the last reference to the session is dropped the database connection is released with an implicit transaction rollback.

sql
$sqlResult = $session->sql ($cmd)

Executes an SQL statement.
Returns data values on SELECT INTO, a SapDB_ResultSet on SELECT and otherwise an empty list.

sqlX
$sqlResult = $session->sqlX ($cmd [, $params])

Executes an SQL statement with arguments.
Returns data values on SELECT INTO, an SapDB_ResultSet on SELECT and otherwise the number of the affected records. The arguments must not be given as an array but as a reference to an array: [$a, $b, ...].

prepare
$session->prepare ($cmd)

Parses an SQL statement and creates an SapDB_Prepared object.

release
$session->release ( [$withCommit])

Closes the connection. The default is to end the session without COMMIT.

commit
$session->commit ()

Commits the current transaction.

rollback
$session->rollback ()

Aborts the current transaction.

class SapDB_ResultSet

Allows navigation and the retrieval of a result set.
Objects are created by all SQL statements that create a result set
(SapDB_Session::sql, SapDB_Prepared::execute).

next
$result = $resultSet->next ()

Gets the next row.
Output values are returned as a list. The end of the result set is indicated by an undefined value.

previous
$result = $resultSet->previous ()

Gets the previous row.
Output values are returned as a list. The end of the result set is indicated by an undefined value.

relative
$result = $resultSet->relative ($count)

Moves the cursor relatively to the current row.
A negative value of count will move the cursor backwards in the result set. Output values are returned as a list. The end of the result set is indicated by an undefined value.

absolute
$result = $resultSet->absolute ($i)

Gets the row no. i.
Output values are returned as a list. The first row has the index 1. The end of the result set is indicated by an undefined value.

first
$result = $resultSet->first ()

Gets the first row.
Output values are returned as a list. The end of the result set is indicated by an undefined value.

last
$result = $resultSet->last ()

Gets the last row.
Output values are returned as a list. The end of the result set is indicated by an undefined value.

current
$result = $resultSet->current ()

Returns the current row.
Output values are returned as a list.

cursorName
$result = $resultSet->cursorName ()

Returns the name of the result set.

columnCount
$result = $resultSet->columnCount ()

Returns the number of columns.

columnInfo
$result = $resultSet->columnInfo ($i)

Returns information about a column specifying four values:
  • column name
  • column type
  • length of the column
  • number of fractional digits
The first column has the index 0.
getDescription
$result = $resultSet->getDescription ();

Returns information about the output columns.
A reference to an array is returned. Each array element consists of a reference to a column description. A column description is an array with the following elements:
  • column name
  • column type as a string
  • column type as an ANSI/ODBC type integer
  • length of the column
  • number of fractional digits
  • specification whether the column may contain NULL
  • specification whether the column is IN, OUT or IN/OUT (always OUT)
Example:
my $descriptions = $resultSet->getDescription ();
foreach my $description (@{$descriptions}) {
    my ($name, $typeName, $typeCode,
        $colLength, $colPrecision, $isNullable, $inout)
        = @{$description};
}

class SapDB_LongReader

Allows to retrieve LONGs.

read
$result = $reader->read ($count)

Returns the subsequent count characters.
Returns an empty string when the end of the LONG is reached.

class SapDB_Prepared

Allows the execution of SQL statements with parameters.
Objects are created with SapDB_Session::prepare.

execute
$result = $prepared->execute ( [$sqlParms])

Executes statements with arguments.
Output values are returned as a list. If the statement creates a result set, then a SapDB_ResultSet is returned. The arguments must not be specified as an array but as a reference to an array [$a, $b, ...].

getDescription
$result = $prepared->getDescription ();

Returns information about the parameters. A reference to an array is returned. Each array element consists of a reference to a parameter description. A parameter desvription is an array with the following elements:
  • parameter name (currently the empty string)
  • parameter type as a string
  • parameter type as an ANSI/ODBC type integer
  • length of the parameter
  • number of fractional digits
  • specification whether the parameter may contain NULL
  • specification whether the parameter is IN, OUT or IN/OUT
Example:
my $descriptions = $prepared->getDescription ();
foreach my $description (@{$descriptions}) {
    my ($name, $typeName, $typeCode,
    $colLength, $colPrecision, $isNullable, $inout)
        = @{$description};
}

connect

$session = sapdb::connect ($user, $pwd, $dbname [, $host [, $config]])

Establishes the connection to the database.
The username is case sensitive. config is a string of the following format:
keyword=value[&keyword=value]...
Allowed keywords are:
  • sqlmode (internal, oracle)
  • isolation (isolation level as an integer)
  • timeout (command timeout in seconds)

_buildInfo

$result = sapdb::_buildInfo ()

Returns a string containing the version and build number.

Long Values

Input

Input values for LONGs can be either a string or a callable object with the following properties:
  • The object is called with an integer argument, number of bytes requested
  • The object must return a string
  • The end of the stream is indicated by an empty string

Output

Output values of LONGs are of the type SapDB-LongReader and can be read using the method read.

Installation

  1. Change to the directory <dependent_path>/misc
  2. Execute the Perl script instperl.pl sapdb

Examples

How to test SQL features: egSQL.pl

How to test inserts of LONGs and SELECT them: longtest.pl

Exceptions

  • CommunicationError: The communication link to the server failed.
  • SQLError: The execution of the SQL statement resulted in an error.


Search
See also ...












Questions or comments about the Web site? Contact the webmaster.