Database Reference
In-Depth Information
Add-Employee
uses the
OracleConnection
object in the script level
variable
$conn
as opposed to passing in the connection as a parameter as is
done in
Add-Oracle
. Here the idea is that more generic functions rely just
on parameters and the more speciic ones may use script level variables. The
$script:conn
syntax is used to clarify that this variable is in script scope.
The calls to the
Add
functions exercise different scenarios of inserting records, with and
without bind variables and record ID retrieval. The insert into the
COUNTRIES
table isn't
related to adding an
EMPLOYEES
record in this example but simply provides another example
and test case.
There's more...
One thing this script adds over scripts in previous recipes is disposal of the different ODP.NET
objects such as
OracleParameter
,
OracleCommand
, and
OracleConnection
. While the
Dispose
calls are not technically needed, it is best practice for responsible use of resources.
While calling
Dispose()
on the
OracleConnection
object calls
Close()
, it is often best to include both calls just to be explicit. Also note
that with PowerShell there is no native using statement block as there is
in C# or VB.NET to automatically call
Dispose()
, regardless of error or
success. A Try/Catch/Finally block could be used to achieve the same result.
In the following recipe we will look at inserting records in more of a bulk fashion.
Importing sets of records (Medium)
In this recipe we will look at adding records in batches from external sources. First we will
look at importing country data using
OracleBulkCopy,
from an XML ile shown in the
following igure:
Search WWH ::
Custom Search