diff --git a/README.md b/README.md index a62d4282..39577f58 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ For beginning Oracle .NET developers, these Documentation +
  • Documentation
  • Code samples are included with the ODAC Oracle Universal Installation. You will find them in the "ODACSamples" directory in the Oracle Client installation home (e.g. d:\app\client\<username>\product\<Oracle version>\client_1\ODACsamples).
  • Contibutions to code samples should review CONTRIBUTING for more details.
  • You may use files in this repository only if in compliance with the LICENSE.
  • diff --git a/samples/array-bind/ArrayBind.cs b/samples/array-bind/ArrayBind.cs index 58061b13..edb9e7ca 100644 --- a/samples/array-bind/ArrayBind.cs +++ b/samples/array-bind/ArrayBind.cs @@ -31,7 +31,8 @@ class ArrayBind static void Main(string[] args) { // Connect - string connectStr = "User Id=scott;Password=tiger;Data Source=oracle"; + // This sample code's DEPT table shares the same characteristics as SCOTT schema's DEPT table + string connectStr = "User Id=;Password=;Data Source="; // Setup the Tables for sample Setup(connectStr); diff --git a/samples/assoc-array/AssocArray.cs b/samples/assoc-array/AssocArray.cs index 62e15569..e9dd9e66 100644 --- a/samples/assoc-array/AssocArray.cs +++ b/samples/assoc-array/AssocArray.cs @@ -32,8 +32,8 @@ static void Main(string[] args) { Console.WriteLine("Demo: PL/SQL Associative Array"); - // Connect - string connectStr = "User Id=scott;Password=tiger;Data Source=oracle"; + // Provide password and connect + string connectStr = "User Id=scott;Password=;Data Source=oracle"; // Setup the Tables for sample Setup(connectStr); diff --git a/samples/autonomous-db/README.md b/samples/autonomous-db/README.md index 8468c028..63cf3e95 100644 --- a/samples/autonomous-db/README.md +++ b/samples/autonomous-db/README.md @@ -1,8 +1,8 @@ -These ODP.NET Autonomous DB code samples are intended to be used with the [Developing .NET Applications for Oracle Autonomous Database tutorial](https://www.oracle.com/technetwork/topics/dotnet/tech-info/default-5032178.html). +These ODP.NET Autonomous Database code samples are intended to be used with the [Developing .NET Framework Applications for Oracle Autonomous Database tutorial](https://www.oracle.com/database/technologies/appdev/dotnet/adbdotnetfw.html). -This sample demonstrates how to connect to Oracle Autonomous Database, Including Oracle Autonomous Transaction Processing and Autonomous Data Warehouse. +This sample demonstrates how to connect to Oracle Autonomous Database, including Oracle Autonomous Transaction Processing and Autonomous Data Warehouse. -Create a new .NET Framework project and add either managed or unmanaged ODP.NET assembly. Managed ODP.NET ([Oracle.ManagedDataAccess](https://www.nuget.org/packages/Oracle.ManagedDataAccess)) can be downloaded from NuGet Gallery. Unmanaged ODP.NET can be added after an [ODAC installation](https://www.oracle.com/database/technologies/dotnet-odacdev-downloads.html). Paste the sample code into the project. You can then enter your ADB connection and configuration information into the sample code as described in the comments. +Create a new .NET Framework project and add either managed or unmanaged ODP.NET assembly. Oracle recommends using managed ODP.NET for most .NET Framework apps. Managed ODP.NET ([Oracle.ManagedDataAccess](https://www.nuget.org/packages/Oracle.ManagedDataAccess)) can be downloaded from NuGet Gallery. Unmanaged ODP.NET can be added after an [ODAC installation](https://www.oracle.com/database/technologies/dotnet-odacdeploy-downloads.html). Paste the sample code into the project. You can then enter your ADB connection and configuration information into the sample code as described in the comments. This directory contains the managed and unmanaged ODP.NET samples. The ODP.NET Core sample is located [here](https://github.com/oracle/dotnet-db-samples/tree/master/samples/dotnet-core/autonomous-db). diff --git a/samples/autonomous-db/managed-odp/web-app/README.md b/samples/autonomous-db/managed-odp/web-app/README.md new file mode 100644 index 00000000..8fe14dd0 --- /dev/null +++ b/samples/autonomous-db/managed-odp/web-app/README.md @@ -0,0 +1,7 @@ +To use the ASP.NET web sample code: +1. Create an empty ASP.NET Web Application (.NET Framework) in Visual Studio. +2. Add managed ODP.NET (Oracle.ManagedDataAccess) to your project from NuGet Gallery. +3. Save the files in this Github directory to your local project directory. +4. Add the files to your web project as existing items. +5. Modify the User Id, Password, and Data Source as necessary to connect to your Autonomous Database instance. +6. Run the app. diff --git a/samples/client-factory/ClientFactory.cs b/samples/client-factory/ClientFactory.cs index ed2040ce..733d2ca8 100644 --- a/samples/client-factory/ClientFactory.cs +++ b/samples/client-factory/ClientFactory.cs @@ -15,42 +15,42 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Data.Common; -using Oracle.ManagedDataAccess.Client; - -class FactorySample -{ - static void Main() - { - string constr = "user id=scott;password=tiger;data source=oracle"; - - DbProviderFactory factory = - DbProviderFactories.GetFactory("Oracle.ManagedDataAccess.Client"); - - DbConnection conn = factory.CreateConnection(); - - try - { - conn.ConnectionString = constr; - conn.Open(); - - DbCommand cmd = factory.CreateCommand(); - cmd.Connection = conn; - cmd.CommandText = "select * from emp"; - - DbDataReader reader = cmd.ExecuteReader(); - while (reader.Read()) - Console.WriteLine(reader["EMPNO"] + " : " + reader["ENAME"]); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - Console.WriteLine(ex.StackTrace); - } - } -} - + *****************************************************************************/ + +using System; +using System.Data; +using System.Data.Common; +using Oracle.ManagedDataAccess.Client; + +class FactorySample +{ + static void Main() + { + string constr = "user id=scott;password=;data source=oracle"; + + DbProviderFactory factory = + DbProviderFactories.GetFactory("Oracle.ManagedDataAccess.Client"); + + DbConnection conn = factory.CreateConnection(); + + try + { + conn.ConnectionString = constr; + conn.Open(); + + DbCommand cmd = factory.CreateCommand(); + cmd.Connection = conn; + cmd.CommandText = "select * from emp"; + + DbDataReader reader = cmd.ExecuteReader(); + while (reader.Read()) + Console.WriteLine(reader["EMPNO"] + " : " + reader["ENAME"]); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + Console.WriteLine(ex.StackTrace); + } + } +} + diff --git a/samples/connection-string-builder/ConnectionStringBuilder.cs b/samples/connection-string-builder/ConnectionStringBuilder.cs index 91b1f448..46ae7545 100644 --- a/samples/connection-string-builder/ConnectionStringBuilder.cs +++ b/samples/connection-string-builder/ConnectionStringBuilder.cs @@ -27,7 +27,7 @@ class ConnectionStringBuilderSample { static void Main(string[] args) { - string connString = "user id=scott;password=tiger;Data source=oracle;"; + string connString = "user id=scott;password=;Data source=oracle;"; bool bRet = false; // Create an instance of OracleConnectionStringBuilder diff --git a/samples/connection/Connection1.cs b/samples/connection/Connection1.cs index 5dd3836e..6dcbc8d2 100644 --- a/samples/connection/Connection1.cs +++ b/samples/connection/Connection1.cs @@ -15,40 +15,40 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Data.Common; -using Oracle.ManagedDataAccess.Client; - -class GetSchemaSample -{ - static void Main(string[] args) - { - string constr = "User Id=scott; Password=tiger; Data Source=oracle;"; - string ProviderName = "Oracle.ManagedDataAccess.Client"; - - DbProviderFactory factory = DbProviderFactories.GetFactory(ProviderName); - - using (DbConnection conn = factory.CreateConnection()) - { - try - { - conn.ConnectionString = constr; - conn.Open(); - - //Get all the schema collections and write to an XML file. - //The XML file name is Oracle.ManagedDataAccess.Client_Schema.xml - DataTable dtSchema = conn.GetSchema(); - dtSchema.WriteXml(ProviderName + "_Schema.xml"); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - Console.WriteLine(ex.StackTrace); - } - } - } -} - + *****************************************************************************/ + +using System; +using System.Data; +using System.Data.Common; +using Oracle.ManagedDataAccess.Client; + +class GetSchemaSample +{ + static void Main(string[] args) + { + string constr = "User Id=scott; Password=; Data Source=oracle;"; + string ProviderName = "Oracle.ManagedDataAccess.Client"; + + DbProviderFactory factory = DbProviderFactories.GetFactory(ProviderName); + + using (DbConnection conn = factory.CreateConnection()) + { + try + { + conn.ConnectionString = constr; + conn.Open(); + + //Get all the schema collections and write to an XML file. + //The XML file name is Oracle.ManagedDataAccess.Client_Schema.xml + DataTable dtSchema = conn.GetSchema(); + dtSchema.WriteXml(ProviderName + "_Schema.xml"); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + Console.WriteLine(ex.StackTrace); + } + } + } +} + diff --git a/samples/connection/Connection2.cs b/samples/connection/Connection2.cs index b49bec87..c4dd04ac 100644 --- a/samples/connection/Connection2.cs +++ b/samples/connection/Connection2.cs @@ -15,74 +15,74 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Data.Common; -using Oracle.ManagedDataAccess.Client; - -class GetSchemaSample -{ - static void Main(string[] args) - { - string constr = "User Id=scott; Password=tiger; Data Source=oracle;"; - string ProviderName = "Oracle.ManagedDataAccess.Client"; - - DbProviderFactory factory = DbProviderFactories.GetFactory(ProviderName); - - using (DbConnection conn = factory.CreateConnection()) - { - try - { - conn.ConnectionString = constr; - conn.Open(); - - //Get MetaDataCollections and write to an XML file. - //This is equivalent to GetSchema() - DataTable dtMetadata = - conn.GetSchema(DbMetaDataCollectionNames.MetaDataCollections); - dtMetadata.WriteXml(ProviderName + "_MetaDataCollections.xml"); - - //Get Restrictions and write to an XML file. - DataTable dtRestrictions = - conn.GetSchema(DbMetaDataCollectionNames.Restrictions); - dtRestrictions.WriteXml(ProviderName + "_Restrictions.xml"); - - //Get DataSourceInformation and write to an XML file. - DataTable dtDataSrcInfo = - conn.GetSchema(DbMetaDataCollectionNames.DataSourceInformation); - dtDataSrcInfo.WriteXml(ProviderName + "_DataSourceInformation.xml"); - - //DataTypes and write to an XML file. - DataTable dtDataTypes = - conn.GetSchema(DbMetaDataCollectionNames.DataTypes); - dtDataTypes.WriteXml(ProviderName + "_DataTypes.xml"); - - //Get ReservedWords and write to an XML file. - DataTable dtReservedWords = - conn.GetSchema(DbMetaDataCollectionNames.ReservedWords); - dtReservedWords.WriteXml(ProviderName + "_ReservedWords.xml"); - - //Get all the tables and write to an XML file. - DataTable dtTables = conn.GetSchema("Tables"); - dtTables.WriteXml(ProviderName + "_Tables.xml"); - - //Get all the views and write to an XML file. - DataTable dtViews = conn.GetSchema("Views"); - dtViews.WriteXml(ProviderName + "_Views.xml"); - - //Get all the columns and write to an XML file. - DataTable dtColumns = conn.GetSchema("Columns"); - dtColumns.WriteXml(ProviderName + "_Columns.xml"); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - Console.WriteLine(ex.StackTrace); - } - } - } -} - - + *****************************************************************************/ + +using System; +using System.Data; +using System.Data.Common; +using Oracle.ManagedDataAccess.Client; + +class GetSchemaSample +{ + static void Main(string[] args) + { + string constr = "User Id=scott; Password=; Data Source=oracle;"; + string ProviderName = "Oracle.ManagedDataAccess.Client"; + + DbProviderFactory factory = DbProviderFactories.GetFactory(ProviderName); + + using (DbConnection conn = factory.CreateConnection()) + { + try + { + conn.ConnectionString = constr; + conn.Open(); + + //Get MetaDataCollections and write to an XML file. + //This is equivalent to GetSchema() + DataTable dtMetadata = + conn.GetSchema(DbMetaDataCollectionNames.MetaDataCollections); + dtMetadata.WriteXml(ProviderName + "_MetaDataCollections.xml"); + + //Get Restrictions and write to an XML file. + DataTable dtRestrictions = + conn.GetSchema(DbMetaDataCollectionNames.Restrictions); + dtRestrictions.WriteXml(ProviderName + "_Restrictions.xml"); + + //Get DataSourceInformation and write to an XML file. + DataTable dtDataSrcInfo = + conn.GetSchema(DbMetaDataCollectionNames.DataSourceInformation); + dtDataSrcInfo.WriteXml(ProviderName + "_DataSourceInformation.xml"); + + //DataTypes and write to an XML file. + DataTable dtDataTypes = + conn.GetSchema(DbMetaDataCollectionNames.DataTypes); + dtDataTypes.WriteXml(ProviderName + "_DataTypes.xml"); + + //Get ReservedWords and write to an XML file. + DataTable dtReservedWords = + conn.GetSchema(DbMetaDataCollectionNames.ReservedWords); + dtReservedWords.WriteXml(ProviderName + "_ReservedWords.xml"); + + //Get all the tables and write to an XML file. + DataTable dtTables = conn.GetSchema("Tables"); + dtTables.WriteXml(ProviderName + "_Tables.xml"); + + //Get all the views and write to an XML file. + DataTable dtViews = conn.GetSchema("Views"); + dtViews.WriteXml(ProviderName + "_Views.xml"); + + //Get all the columns and write to an XML file. + DataTable dtColumns = conn.GetSchema("Columns"); + dtColumns.WriteXml(ProviderName + "_Columns.xml"); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + Console.WriteLine(ex.StackTrace); + } + } + } +} + + diff --git a/samples/connection/Connection3.cs b/samples/connection/Connection3.cs index b03bf0a7..1008d4aa 100644 --- a/samples/connection/Connection3.cs +++ b/samples/connection/Connection3.cs @@ -15,83 +15,83 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Data.Common; -using Oracle.ManagedDataAccess.Client; - -class GetSchemaSample -{ - static void Main(string[] args) - { - string constr = "User Id=scott; Password=tiger; Data Source=oracle;"; - string ProviderName = "Oracle.ManagedDataAccess.Client"; - - DbProviderFactory factory = DbProviderFactories.GetFactory(ProviderName); - - using (DbConnection conn = factory.CreateConnection()) - { - try - { - conn.ConnectionString = constr; - conn.Open(); - - //Get Restrictions - DataTable dtRestrictions = - conn.GetSchema(DbMetaDataCollectionNames.Restrictions); - - DataView dv = dtRestrictions.DefaultView; - - dv.RowFilter = "CollectionName = 'Columns'"; - dv.Sort = "RestrictionNumber"; - - for (int i = 0; i < dv.Count; i++) - Console.WriteLine("{0} (default) {1}" , - dtRestrictions.Rows[i]["RestrictionName"], - dtRestrictions.Rows[i]["RestrictionDefault"]); - - //Set restriction string array - string[] restrictions = new string[3]; - - //Get all columns from all tables owned by "SCOTT" - restrictions[0] = "SCOTT"; - DataTable dtAllScottCols = conn.GetSchema("Columns", restrictions); - - // clear collection - for (int i = 0; i < 3; i++) - restrictions[i] = null; - - //Get all columns from all tables named "EMP" owned by any - //owner/schema - restrictions[1] = "EMP"; - DataTable dtAllEmpCols = conn.GetSchema("Columns", restrictions); - - // clear collection - for (int i = 0; i < 3; i++) - restrictions[i] = null; - - //Get columns named "EMPNO" from tables named "EMP", - //owned by any owner/schema - restrictions[1] = "EMP"; - restrictions[2] = "EMPNO"; - DataTable dtAllScottEmpCols = conn.GetSchema("Columns", restrictions); - - // clear collection - for (int i = 0; i < 3; i++) - restrictions[i] = null; - - //Get columns named "EMPNO" from all - //tables, owned by any owner/schema - restrictions[2] = "EMPNO"; - DataTable dtAllEmpNoCols = conn.GetSchema("Columns", restrictions); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - Console.WriteLine(ex.Source); - } - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Data.Common; +using Oracle.ManagedDataAccess.Client; + +class GetSchemaSample +{ + static void Main(string[] args) + { + string constr = "User Id=scott; Password=; Data Source=oracle;"; + string ProviderName = "Oracle.ManagedDataAccess.Client"; + + DbProviderFactory factory = DbProviderFactories.GetFactory(ProviderName); + + using (DbConnection conn = factory.CreateConnection()) + { + try + { + conn.ConnectionString = constr; + conn.Open(); + + //Get Restrictions + DataTable dtRestrictions = + conn.GetSchema(DbMetaDataCollectionNames.Restrictions); + + DataView dv = dtRestrictions.DefaultView; + + dv.RowFilter = "CollectionName = 'Columns'"; + dv.Sort = "RestrictionNumber"; + + for (int i = 0; i < dv.Count; i++) + Console.WriteLine("{0} (default) {1}" , + dtRestrictions.Rows[i]["RestrictionName"], + dtRestrictions.Rows[i]["RestrictionDefault"]); + + //Set restriction string array + string[] restrictions = new string[3]; + + //Get all columns from all tables owned by "SCOTT" + restrictions[0] = "SCOTT"; + DataTable dtAllScottCols = conn.GetSchema("Columns", restrictions); + + // clear collection + for (int i = 0; i < 3; i++) + restrictions[i] = null; + + //Get all columns from all tables named "EMP" owned by any + //owner/schema + restrictions[1] = "EMP"; + DataTable dtAllEmpCols = conn.GetSchema("Columns", restrictions); + + // clear collection + for (int i = 0; i < 3; i++) + restrictions[i] = null; + + //Get columns named "EMPNO" from tables named "EMP", + //owned by any owner/schema + restrictions[1] = "EMP"; + restrictions[2] = "EMPNO"; + DataTable dtAllScottEmpCols = conn.GetSchema("Columns", restrictions); + + // clear collection + for (int i = 0; i < 3; i++) + restrictions[i] = null; + + //Get columns named "EMPNO" from all + //tables, owned by any owner/schema + restrictions[2] = "EMPNO"; + DataTable dtAllEmpNoCols = conn.GetSchema("Columns", restrictions); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + Console.WriteLine(ex.Source); + } + } + } +} diff --git a/samples/data-reader/DataReader.cs b/samples/data-reader/DataReader.cs index 2c1aa888..97409ce7 100644 --- a/samples/data-reader/DataReader.cs +++ b/samples/data-reader/DataReader.cs @@ -26,7 +26,7 @@ class VisibleFieldCountSample { static void Main(string[] args) { - string constr = "User Id=scott; Password=tiger; Data Source=oracle;"; + string constr = "User Id=scott; Password=; Data Source=oracle;"; DbProviderFactory factory = DbProviderFactories.GetFactory("Oracle.ManagedDataAccess.Client"); diff --git a/samples/dataset/DML/src/ConnectionParams.cs b/samples/dataset/DML/src/ConnectionParams.cs index 8c4dd657..90fbba4c 100644 --- a/samples/dataset/DML/src/ConnectionParams.cs +++ b/samples/dataset/DML/src/ConnectionParams.cs @@ -15,19 +15,19 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -namespace ManipulateProducts -{ - - public class ConnectionParams - { - //Parameters for database connection - //Change the values to those applicable to your database - public static string Datasource="oracle"; //Connect String as TNSNames - public static string Username="scott"; //Username - public static string Password="tiger"; //Password - } -} - \ No newline at end of file + *****************************************************************************/ + +using System; +namespace ManipulateProducts +{ + + public class ConnectionParams + { + //Parameters for database connection + //Change the values to those applicable to your database + public static string Datasource="oracle"; //Connect String as TNSNames + public static string Username="scott"; //Username + public static string Password=""; //Password + } +} + diff --git a/samples/dataset/fill/src/ConnectionParams.cs b/samples/dataset/fill/src/ConnectionParams.cs index b1953f96..fb3d8036 100644 --- a/samples/dataset/fill/src/ConnectionParams.cs +++ b/samples/dataset/fill/src/ConnectionParams.cs @@ -15,34 +15,34 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -/************************************************************************** -@author Jagriti -@version 1.0 -Development Environment : MS Visual Studio .Net -Name of the File : ConnectionParams.cs -Creation/Modification History : - 23-July-2002 Created - -Overview: -This file defines the variables for connection parameters for database. -**************************************************************************/ - -using System; -namespace DSPopulate -{ - - public class ConnectionParams - { - //Parameters for database connection - //Change the values to those applicable to your database - - //Replace with Connect String as TNSNames - public static string Datasource="oracle"; - - public static string Username="scott"; //Username - public static string Password="tiger"; //Password - } -} - \ No newline at end of file + *****************************************************************************/ + +/************************************************************************** +@author Jagriti +@version 1.0 +Development Environment : MS Visual Studio .Net +Name of the File : ConnectionParams.cs +Creation/Modification History : + 23-July-2002 Created + +Overview: +This file defines the variables for connection parameters for database. +**************************************************************************/ + +using System; +namespace DSPopulate +{ + + public class ConnectionParams + { + //Parameters for database connection + //Change the values to those applicable to your database + + //Replace with Connect String as TNSNames + public static string Datasource="oracle"; + + public static string Username="scott"; //Username + public static string Password=""; //Password + } +} + diff --git a/samples/dataset/lob/src/ConnectionParams.cs b/samples/dataset/lob/src/ConnectionParams.cs index 437aed6d..514014a9 100644 --- a/samples/dataset/lob/src/ConnectionParams.cs +++ b/samples/dataset/lob/src/ConnectionParams.cs @@ -15,33 +15,33 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -/************************************************************************** -@author Jagriti -@version 1.0 -Development Environment : MS Visual Studio .Net -Name of the File : ConnectionParams.cs -Creation/Modification History : - 21-July-2002 Created - -Overview: -This file defines the variables for connection parameters for database. -**************************************************************************/ - -using System; -namespace ManipulateAds -{ - - public class ConnectionParams - { - //Parameters for database connection - //Change the values to those applicable to your database - - //Replace with Connect String as TNSNames - public static string Datasource="oracle"; - public static string Username="scott"; //Username - public static string Password="tiger"; //Password - } -} - \ No newline at end of file + *****************************************************************************/ + +/************************************************************************** +@author Jagriti +@version 1.0 +Development Environment : MS Visual Studio .Net +Name of the File : ConnectionParams.cs +Creation/Modification History : + 21-July-2002 Created + +Overview: +This file defines the variables for connection parameters for database. +**************************************************************************/ + +using System; +namespace ManipulateAds +{ + + public class ConnectionParams + { + //Parameters for database connection + //Change the values to those applicable to your database + + //Replace with Connect String as TNSNames + public static string Datasource="oracle"; + public static string Username="scott"; //Username + public static string Password=""; //Password + } +} + diff --git a/samples/dataset/vb/src/ConnectionParams.vb b/samples/dataset/vb/src/ConnectionParams.vb index 265cd818..8260348a 100644 --- a/samples/dataset/vb/src/ConnectionParams.vb +++ b/samples/dataset/vb/src/ConnectionParams.vb @@ -29,22 +29,22 @@ 'This file defines the variables for connection parameters for database. '************************************************************************** -Module ConnectionParams - - Public datasource As String - Public username As String - Public password As String - - Public Sub setparams() - 'Parameters for database connection - 'Change the values to those applicable to your database - - 'Replace with Connect String as TNSNames - datasource = "oracle" - 'Username - username = "scott" - 'Password - password = "tiger" - End Sub - -End Module +Module ConnectionParams + + Public datasource As String + Public username As String + Public password As String + + Public Sub setparams() + 'Parameters for database connection + 'Change the values to those applicable to your database + + 'Replace with Connect String as TNSNames + datasource = "oracle" + 'Username + username = "scott" + 'Password + password = "" + End Sub + +End Module diff --git a/samples/dotnet-core/asp.net-core/Program.cs b/samples/dotnet-core/asp.net-core/2.x/Program.cs similarity index 93% rename from samples/dotnet-core/asp.net-core/Program.cs rename to samples/dotnet-core/asp.net-core/2.x/Program.cs index 939052d4..901df1ec 100644 --- a/samples/dotnet-core/asp.net-core/Program.cs +++ b/samples/dotnet-core/asp.net-core/2.x/Program.cs @@ -1,4 +1,4 @@ -/* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. */ +/* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. */ /****************************************************************************** * @@ -26,7 +26,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -namespace ODPCoreASPCore +namespace ODPCoreASPCore2 { public class Program { diff --git a/samples/dotnet-core/asp.net-core/Startup.cs b/samples/dotnet-core/asp.net-core/2.x/Startup.cs similarity index 97% rename from samples/dotnet-core/asp.net-core/Startup.cs rename to samples/dotnet-core/asp.net-core/2.x/Startup.cs index 0417ed5f..5d616bfd 100644 --- a/samples/dotnet-core/asp.net-core/Startup.cs +++ b/samples/dotnet-core/asp.net-core/2.x/Startup.cs @@ -1,4 +1,4 @@ -/* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. */ +/* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. */ /****************************************************************************** * @@ -27,7 +27,7 @@ using Microsoft.Extensions.DependencyInjection; using Oracle.ManagedDataAccess.Client; -namespace ODPCoreASPCore +namespace ODPCoreASPCore2 { public class Startup { diff --git a/samples/dotnet-core/asp.net-core/3.x/Program.cs b/samples/dotnet-core/asp.net-core/3.x/Program.cs new file mode 100644 index 00000000..a6234e23 --- /dev/null +++ b/samples/dotnet-core/asp.net-core/3.x/Program.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +namespace ODPCoreASPCore3 +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} + +/* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. */ + +/****************************************************************************** + * + * You may not use the identified files except in compliance with The MIT + * License (the "License.") + * + * You may obtain a copy of the License at + * https://github.com/oracle/Oracle.NET/blob/master/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + *****************************************************************************/ diff --git a/samples/dotnet-core/asp.net-core/3.x/Startup.cs b/samples/dotnet-core/asp.net-core/3.x/Startup.cs new file mode 100644 index 00000000..cf6efcf4 --- /dev/null +++ b/samples/dotnet-core/asp.net-core/3.x/Startup.cs @@ -0,0 +1,95 @@ +using System; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Oracle.ManagedDataAccess.Client; + +namespace ODPCoreASPCore3 +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseEndpoints(endpoints => + { + endpoints.MapGet("/", async context => + { + //Demo: Basic ODP.NET Core application for ASP.NET Core 3.1 + // to connect, query, and return results to a web page + + //Set the user id and password + string conString = "User Id=hr;Password=;" + + + //Set Data Source value to an Oracle net service name in + // the tnsnames.ora file or use EZ Connect + "Data Source=:1521/;"; + + using (OracleConnection con = new OracleConnection(conString)) + { + using (OracleCommand cmd = con.CreateCommand()) + { + try + { + con.Open(); + cmd.BindByName = true; + + //Use the command to display employee names from + // the EMPLOYEES table + cmd.CommandText = "select first_name, last_name from employees where department_id = :id"; + + // Assign id to the department number 50 + OracleParameter id = new OracleParameter("id", 50); + cmd.Parameters.Add(id); + + //Execute the command and use DataReader to display the data + OracleDataReader reader = cmd.ExecuteReader(); + while (reader.Read()) + { + await context.Response.WriteAsync("Employee Name: " + reader.GetString(0) + " " + reader.GetString(1) + "\n"); + } + + reader.Dispose(); + } + catch (Exception ex) + { + await context.Response.WriteAsync(ex.Message); + } + } + } + }); + }); + } + } +} + +/* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. */ + +/****************************************************************************** + * + * You may not use the identified files except in compliance with The MIT + * License (the "License.") + * + * You may obtain a copy of the License at + * https://github.com/oracle/Oracle.NET/blob/master/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + *****************************************************************************/ diff --git a/samples/dotnet-core/autonomous-db/README.md b/samples/dotnet-core/autonomous-db/README.md index b94952ed..8ef7a507 100644 --- a/samples/dotnet-core/autonomous-db/README.md +++ b/samples/dotnet-core/autonomous-db/README.md @@ -1,9 +1,10 @@ -This ODP.NET Core Autonomous DB code sample is intended to be used with the [Developing .NET Applications for Oracle Autonomous Database tutorial](https://www.oracle.com/technetwork/topics/dotnet/tech-info/default-5032178.html). +The ODP.NET Core Autonomous Database (ADB) code sample in the "console" subdirectory is intended to be used with the [Developing .NET Core Applications for Oracle Autonomous Database tutorial](https://www.oracle.com/database/technologies/appdev/dotnet/adbdotnetcore.html). -This sample demonstrates how to connect to Oracle Autonomous Database, Including Oracle Autonomous Transaction Processing and -Autonomous Data Warehouse. +This sample demonstrates how to connect to Oracle Autonomous Database, including Oracle Autonomous Transaction Processing and Autonomous Data Warehouse. Create a new .NET Core console project, add ODP.NET Core assembly ([Oracle.ManagedDataAccess.Core](https://www.nuget.org/packages/Oracle.ManagedDataAccess.Core/)) from NuGet Gallery, and paste the sample code. You can then enter your ADB connection and configuration information into the pasted sample code as described in the comments. -There are three samples, one each for ODP.NET Core, managed ODP.NET, and unmanaged ODP.NET. This directory contains the +This repository has ADB code samples for ODP.NET Core, managed ODP.NET, and unmanaged ODP.NET. This directory contains the ODP.NET Core sample. The other ODP.NET Autonomous DB samples are located [here](https://github.com/oracle/dotnet-db-samples/tree/master/samples/autonomous-db). + +The "web" subdirectory contains an ADB sample using ASP.NET Core and ODP.NET Core. diff --git a/samples/dotnet-core/autonomous-db/autonomous-odp-core.cs b/samples/dotnet-core/autonomous-db/console/autonomous-odp-core.cs similarity index 100% rename from samples/dotnet-core/autonomous-db/autonomous-odp-core.cs rename to samples/dotnet-core/autonomous-db/console/autonomous-odp-core.cs diff --git a/samples/dotnet-core/autonomous-db/web/Program.cs b/samples/dotnet-core/autonomous-db/web/Program.cs new file mode 100644 index 00000000..461fc596 --- /dev/null +++ b/samples/dotnet-core/autonomous-db/web/Program.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +namespace ADB_ODPCore_ASPCore3 +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} + +/* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. */ + +/****************************************************************************** + * + * You may not use the identified files except in compliance with The MIT + * License (the "License.") + * + * You may obtain a copy of the License at + * https://github.com/oracle/Oracle.NET/blob/master/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + *****************************************************************************/ diff --git a/samples/dotnet-core/autonomous-db/web/Startup.cs b/samples/dotnet-core/autonomous-db/web/Startup.cs new file mode 100644 index 00000000..b5b70613 --- /dev/null +++ b/samples/dotnet-core/autonomous-db/web/Startup.cs @@ -0,0 +1,91 @@ +using System; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Oracle.ManagedDataAccess.Client; + +namespace ADB_ODPCore_ASPCore3 +{ + public class Startup + { + public void ConfigureServices(IServiceCollection services) + { + } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + + app.UseRouting(); + + app.UseEndpoints(endpoints => + { + endpoints.MapGet("/", async context => + { + //Demo: ODP.NET Core application for ASP.NET Core 3.1 to connect, + // query, and return results from Oracle Autonomous Database + + //Set the user id and password + string conString = "User Id=admin;Password=;" + + + //Set Data Source value to an Oracle net service name in + // the tnsnames.ora file + "Data Source=;"; + + //Set the directory where the sqlnet.ora, tnsnames.ora, and + // wallet files are located + OracleConfiguration.TnsAdmin = @""; + OracleConfiguration.WalletLocation = OracleConfiguration.TnsAdmin; + + using (OracleConnection con = new OracleConnection(conString)) + { + using (OracleCommand cmd = con.CreateCommand()) + { + try + { + con.Open(); + await context.Response.WriteAsync("Connected to Oracle Autonomous Database." + "\n"); + + //Retrieve database version info + cmd.CommandText = "SELECT BANNER FROM V$VERSION"; + OracleDataReader reader = cmd.ExecuteReader(); + reader.Read(); + await context.Response.WriteAsync("The version is " + reader.GetString(0)); + + reader.Dispose(); + } + catch (Exception ex) + { + await context.Response.WriteAsync(ex.Message); + } + } + } + }); + }); + } + } +} + +/* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. */ + +/****************************************************************************** + * + * You may not use the identified files except in compliance with The MIT + * License (the "License.") + * + * You may obtain a copy of the License at + * https://github.com/oracle/Oracle.NET/blob/master/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + *****************************************************************************/ diff --git a/samples/dotnet-core/ef-core/autonomous-db/README.md b/samples/dotnet-core/ef-core/autonomous-db/README.md new file mode 100644 index 00000000..dac5bbef --- /dev/null +++ b/samples/dotnet-core/ef-core/autonomous-db/README.md @@ -0,0 +1,7 @@ +This sample code demonstrates using ODP.NET Entity Framework Core with an Oracle Autonomous Database (ADB). It is compatible with EF Core 2.x and 3.x. It builds off [this introductory sample](https://github.com/oracle/dotnet-db-samples/blob/master/samples/dotnet-core/ef-core/get-started/) for Oracle EF Core beginners. In this sample, ADB connection setup occurs in the OnConfiguring method. + +1. Set the OracleConfiguration.TnsAdmin property value to the tnsnames.ora and sqlnet.ora files directory location. + +2. Set the OracleConfiguration.WalletLocation property value to the ADB wallet directory location. Most Oracle Autonomous Databases require TCP with SSL (TCPS) connections for security purposes. ODP.NET uses the Oracle wallet, which stores the security credentials, to connect. + +3. Set the connection string with the user id, password, and data source. The data source is commonly populated with the ADB TNS name value. diff --git a/samples/dotnet-core/ef-core/autonomous-db/adb-odp-efcore.cs b/samples/dotnet-core/ef-core/autonomous-db/adb-odp-efcore.cs new file mode 100644 index 00000000..75dc0d15 --- /dev/null +++ b/samples/dotnet-core/ef-core/autonomous-db/adb-odp-efcore.cs @@ -0,0 +1,82 @@ +/* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. */ + +/****************************************************************************** + * + * You may not use the identified files except in compliance with The MIT + * License (the "License.") + * + * You may obtain a copy of the License at + * https://github.com/oracle/Oracle.NET/blob/master/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + *****************************************************************************/ + +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; + +// ODP.NET namespace added to access OracleConfiguration class +using Oracle.ManagedDataAccess.Client; + +namespace OracleEFCore_ADB +{ + // This sample code demonstrates using ODP.NET EF Core with an Oracle Autonomous Database + class Program + { + public class BloggingContext : DbContext + { + public DbSet Blogs { get; set; } + public DbSet Posts { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + + // Configure ODP.NET connection string + optionsBuilder.UseOracle(@"User Id=;Password=;Data Source="); + } + } + + public class Blog + { + public int BlogId { get; set; } + public string Url { get; set; } + public List Posts { get; set; } + } + + public class Post + { + public int PostId { get; set; } + public string Title { get; set; } + public string Content { get; set; } + + public int BlogId { get; set; } + public Blog Blog { get; set; } + } + + static void Main(string[] args) + { + // Set TnsAdmin value to directory location of tnsnames.ora and sqlnet.ora files + OracleConfiguration.TnsAdmin = @""; + + // Set WalletLocation value to directory location of the ADB wallet (i.e. cwallet.sso) + OracleConfiguration.WalletLocation = @""; + + using (var db = new BloggingContext()) + { + var blog = new Blog { Url = "https://blogs.oracle.com" }; + db.Blogs.Add(blog); + db.SaveChanges(); + } + + using (var db = new BloggingContext()) + { + var blogs = db.Blogs; + } + } + } +} diff --git a/samples/dotnet-core/ef-core/dependency-injection/README.md b/samples/dotnet-core/ef-core/dependency-injection/README.md index e0425eae..663e74c9 100644 --- a/samples/dotnet-core/ef-core/dependency-injection/README.md +++ b/samples/dotnet-core/ef-core/dependency-injection/README.md @@ -1,8 +1,8 @@ -This sample code demonstrates how to use dependency injection and ASP.NET Core with Oracle Entity Framework. +This sample code demonstrates how to use dependency injection and ASP.NET Core with Oracle Entity Framework Core 2.x. It does not support later EF Core versions. Before you run the application: -1. Add the Oracle.EntityFrameworkCore assembly from NuGet -2. Populate the Oracle User Id, Password, and Data Source information in the appsettings.json file +1. Add the Oracle.EntityFrameworkCore assembly from NuGet Gallery. +2. Populate the Oracle User Id, Password, and Data Source information in the appsettings.json file. 3. Use EF Core migrations to create the Blogs table and populate it with some data. When you then run this sample app, the web page will then return results. diff --git a/samples/dotnet-core/ef-core/keyless-entity-types-views/README.md b/samples/dotnet-core/ef-core/keyless-entity-types-views/README.md new file mode 100644 index 00000000..bc5fc987 --- /dev/null +++ b/samples/dotnet-core/ef-core/keyless-entity-types-views/README.md @@ -0,0 +1,14 @@ +This C# sample code shows how to use Oracle Entity Framework Core with keyless entity types with relational and materialized views. It auto-generates the necessary schema objects. + +This sample uses Oracle EF Core 3.1 provider, which is available as a free download on [NuGet Gallery](https://www.nuget.org/packages/Oracle.EntityFrameworkCore/). + +To use the sample code, enter the User Id, Password, and Data Source values for the Oracle database connection string. + +Ensure the EF Core user has the database privileges to create the necessary schema objects to run the sample code. If you have granted the privileges in the [Oracle EF Core Getting Started sample](https://github.com/oracle/dotnet-db-samples/tree/master/samples/dotnet-core/ef-core/get-started) already, then you only need to grant view creation privileges: +* GRANT CREATE VIEW TO "<Oracle User>" +* GRANT CREATE MATERIALIZED VIEW TO "<Oracle User>" + +To scaffold views, add the Microsoft.EntityFrameworkCore.Tools package from NuGet Gallery. Then, run this command from the Package Manager Console: +* Scaffold-DbContext "User Id=<Oracle User>;Password=<Password>;Data Source=<Data Source>;" Oracle.EntityFrameworkCore -OutputDir Models + +Note: There are no EF Core migration APIs specifically for database view DDL. To perform view DDL, execute SQL, such as using the ExecuteSqlRaw method as the sample code does. diff --git a/samples/dotnet-core/ef-core/keyless-entity-types-views/keyless-entity-types-views.cs b/samples/dotnet-core/ef-core/keyless-entity-types-views/keyless-entity-types-views.cs new file mode 100644 index 00000000..2841284f --- /dev/null +++ b/samples/dotnet-core/ef-core/keyless-entity-types-views/keyless-entity-types-views.cs @@ -0,0 +1,193 @@ +/* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. */ +/* Copyright (c) .NET Foundation */ + +/****************************************************************************** + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + *****************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.EntityFrameworkCore; + +namespace Oracle_KET_Views +{ + public class Program + { + private static void Main() + { + SetupDatabase(); + + using (var db = new BloggingContext()) + { + #region Query + var postCounts = db.BlogPostCounts.ToList(); + + Console.WriteLine("View Results:"); + foreach (var postCount in postCounts) + { + Console.WriteLine($"{postCount.BlogName} has {postCount.PostCount} posts."); + } + + Console.WriteLine(); + Console.WriteLine("Materialized View Results:"); + var mvPostCounts = db.MVBlogPostCounts.ToList(); + + foreach (var mvPostCount in mvPostCounts) + { + Console.WriteLine($"{mvPostCount.BlogName} has {mvPostCount.PostCount} posts."); + } + + #endregion + } + } + + private static void SetupDatabase() + { + using (var db = new BloggingContext()) + { + if (db.Database.EnsureCreated()) + { + db.Blogs.Add( + new Blog + { + Name = "Fish Blog", + Url = "http://sample.com/blogs/fish", + Posts = new List + { + new Post { Title = "Fish care 101" }, + new Post { Title = "Caring for tropical fish" }, + new Post { Title = "Types of ornamental fish" } + } + }); + + db.Blogs.Add( + new Blog + { + Name = "Cats Blog", + Url = "http://sample.com/blogs/cats", + Posts = new List + { + new Post { Title = "Cat care 101" }, + new Post { Title = "Caring for tropical cats" }, + new Post { Title = "Types of ornamental cats" } + } + }); + + db.Blogs.Add( + new Blog + { + Name = "Catfish Blog", + Url = "http://sample.com/blogs/catfish", + Posts = new List + { + new Post { Title = "Catfish care 101" }, + new Post { Title = "History of the catfish name" } + } + }); + + db.SaveChanges(); + + #region View + db.Database.ExecuteSqlRaw( + "CREATE VIEW \"View_BlogPostCounts\" AS " + + "SELECT b.\"Name\", Count(p.\"PostId\") as \"PostCount\" " + + "FROM \"Blogs\" b " + + "JOIN \"Posts\" p on p.\"BlogId\" = b.\"BlogId\" " + + "GROUP BY b.\"Name\";"); + #endregion + + #region MaterializedView + db.Database.ExecuteSqlRaw( + "CREATE MATERIALIZED VIEW \"MView_BlogPostCounts\" " + + "BUILD IMMEDIATE REFRESH FORCE ON DEMAND AS " + + "SELECT b.\"Name\", Count(p.\"PostId\") as \"PostCount\" " + + "FROM \"Blogs\" b " + + "JOIN \"Posts\" p on p.\"BlogId\" = b.\"BlogId\" " + + "GROUP BY b.\"Name\";"); + #endregion + } + } + } + } + + public class BloggingContext : DbContext + { + public DbSet Blogs { get; set; } + public DbSet Posts { get; set; } + + #region DbSet + public DbSet BlogPostCounts { get; set; } + public DbSet MVBlogPostCounts { get; set; } + #endregion + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + // Enter User Id, Password, and Data Source values + optionsBuilder + .UseOracle( + @"User Id=;Password=;Data Source="); + } + + #region Configuration + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder + .Entity(eb => + { + eb.HasNoKey(); + eb.ToView("View_BlogPostCounts"); + eb.Property(v => v.BlogName).HasColumnName("Name"); + }) + .Entity(eb => + { + eb.HasNoKey(); + eb.ToView("MView_BlogPostCounts"); + eb.Property(v => v.BlogName).HasColumnName("Name"); + }); + } + #endregion + } + + #region Entities + public class Blog + { + public int BlogId { get; set; } + public string Name { get; set; } + public string Url { get; set; } + public ICollection Posts { get; set; } + } + + public class Post + { + public int PostId { get; set; } + public string Title { get; set; } + public string Content { get; set; } + public int BlogId { get; set; } + } + #endregion + + #region KeylessEntityType + public class BlogPostsCount + { + public string BlogName { get; set; } + public int PostCount { get; set; } + } + public class MVBlogPostsCount + { + public string BlogName { get; set; } + public int PostCount { get; set; } + } + #endregion +} diff --git a/samples/dotnet-core/ef-core/stored-procedure/return-ref-cursor.cs b/samples/dotnet-core/ef-core/stored-procedure/return-ref-cursor.cs index 17ac8e4e..e1abb9c3 100644 --- a/samples/dotnet-core/ef-core/stored-procedure/return-ref-cursor.cs +++ b/samples/dotnet-core/ef-core/stored-procedure/return-ref-cursor.cs @@ -1,4 +1,4 @@ -/* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. */ +/* Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved. */ /****************************************************************************** * @@ -77,8 +77,10 @@ static void Main(string[] args) using (var db = new BloggingContext()) { // Use anonymous PL/SQL to call stored procedure and return result set + // Comment and uncomment the FromSql* extension method depending on the .NET Core version used var blogs = db.Blogs - .FromSql("BEGIN GETALLBLOGS_IMPLICIT(); END;") + .FromSqlRaw("BEGIN GETALLBLOGS_IMPLICIT(); END;") // .NET Core 3.x syntax + //.FromSql("BEGIN GETALLBLOGS_IMPLICIT(); END;") // .NET Core 2.x syntax .ToList() .OrderBy(Blog => Blog.BlogId); } @@ -90,8 +92,10 @@ static void Main(string[] args) var allblogs = new OracleParameter("blogparam", OracleDbType.RefCursor, ParameterDirection.Output); // Use anonymous PL/SQL to call stored procedure, bind output parameter, and return result set + // Comment and uncomment the FromSql* extension method depending on the .NET Core version used var blogs = db.Blogs - .FromSql("BEGIN GETALLBLOGS(:blogparam); END;", new object[] { allblogs }) + .FromSqlRaw("BEGIN GETALLBLOGS(:blogparam); END;", new object[] { allblogs }) // .NET Core 3.x syntax + //.FromSql("BEGIN GETALLBLOGS(:blogparam); END;", new object[] { allblogs }) // .NET Core 2.x syntax .ToList() .OrderBy(Blog => Blog.BlogId); } diff --git a/samples/event-handler/src/RowUpdate.vb b/samples/event-handler/src/RowUpdate.vb index 39d6b373..99ffb2f3 100644 --- a/samples/event-handler/src/RowUpdate.vb +++ b/samples/event-handler/src/RowUpdate.vb @@ -30,596 +30,596 @@ 'that handle events generated by widgets placed on the main form. '************************************************************************** -Imports System.Threading -Public Class RowUpdate - Inherits System.Windows.Forms.Form - Protected dba As DBAccess - Protected statusbool As Boolean - -#Region " Windows Form Designer generated code " - - Public Sub New() - MyBase.New() - - 'This call is required by the Windows Form Designer. - InitializeComponent() - - 'Add any initialization after the InitializeComponent() call - 'Create instance of the database access helper class and pass the reference - 'of status window to this object - dba = New DBAccess(StatusBox) - End Sub - - 'Form overrides dispose to clean up the component list. - Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) - If disposing Then - If Not (components Is Nothing) Then - components.Dispose() - End If - End If - MyBase.Dispose(disposing) - End Sub - - 'Required by the Windows Form Designer - Private components As System.ComponentModel.IContainer - - 'NOTE: The following procedure is required by the Windows Form Designer - 'It can be modified using the Windows Form Designer. - 'Do not modify it using the code editor. - Friend WithEvents Label1 As System.Windows.Forms.Label - Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox - Friend WithEvents Connection As System.Windows.Forms.GroupBox - Friend WithEvents UserNameLabel As System.Windows.Forms.Label - Friend WithEvents UserName As System.Windows.Forms.TextBox - Friend WithEvents PasswordLabel As System.Windows.Forms.Label - Friend WithEvents Password As System.Windows.Forms.TextBox - Friend WithEvents ConnectStringLabel As System.Windows.Forms.Label - Friend WithEvents ButtonConnect As System.Windows.Forms.Button - Friend WithEvents ButtonExit As System.Windows.Forms.Button - Friend WithEvents StatusLabel As System.Windows.Forms.Label - Friend WithEvents Status As System.Windows.Forms.Label - Friend WithEvents StatusBox As System.Windows.Forms.TextBox - Friend WithEvents DataSource As System.Windows.Forms.TextBox - Friend WithEvents Label2 As System.Windows.Forms.Label - Friend WithEvents ButtonUpdate As System.Windows.Forms.Button - Friend WithEvents GroupBoxupdating1 As System.Windows.Forms.GroupBox - Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox - Friend WithEvents UpdatingEnabled As System.Windows.Forms.RadioButton - Friend WithEvents UpdatingDisabled As System.Windows.Forms.RadioButton - Friend WithEvents UpdatedEnabled As System.Windows.Forms.RadioButton - Friend WithEvents UpdatedDisabled As System.Windows.Forms.RadioButton - Friend WithEvents ButtonApply As System.Windows.Forms.Button - Friend WithEvents CountryGrid As System.Windows.Forms.DataGrid - Friend WithEvents DataGridTableStyle1 As System.Windows.Forms.DataGridTableStyle - Friend WithEvents TextBoxCountryname As System.Windows.Forms.DataGridTextBoxColumn - Friend WithEvents TextBoxpopulation As System.Windows.Forms.DataGridTextBoxColumn - Friend WithEvents TextBoxLanguage As System.Windows.Forms.DataGridTextBoxColumn - Friend WithEvents TextBoxCurrency As System.Windows.Forms.DataGridTextBoxColumn - Friend WithEvents ButtonDisconnect As System.Windows.Forms.Button - Private Sub InitializeComponent() - Me.Label1 = New System.Windows.Forms.Label - Me.GroupBox1 = New System.Windows.Forms.GroupBox - Me.StatusBox = New System.Windows.Forms.TextBox - Me.UserNameLabel = New System.Windows.Forms.Label - Me.UserName = New System.Windows.Forms.TextBox - Me.PasswordLabel = New System.Windows.Forms.Label - Me.Password = New System.Windows.Forms.TextBox - Me.Connection = New System.Windows.Forms.GroupBox - Me.ButtonDisconnect = New System.Windows.Forms.Button - Me.Status = New System.Windows.Forms.Label - Me.StatusLabel = New System.Windows.Forms.Label - Me.ButtonExit = New System.Windows.Forms.Button - Me.ButtonConnect = New System.Windows.Forms.Button - Me.DataSource = New System.Windows.Forms.TextBox - Me.ConnectStringLabel = New System.Windows.Forms.Label - Me.Label2 = New System.Windows.Forms.Label - Me.ButtonUpdate = New System.Windows.Forms.Button - Me.GroupBoxupdating1 = New System.Windows.Forms.GroupBox - Me.UpdatingDisabled = New System.Windows.Forms.RadioButton - Me.UpdatingEnabled = New System.Windows.Forms.RadioButton - Me.GroupBox2 = New System.Windows.Forms.GroupBox - Me.UpdatedDisabled = New System.Windows.Forms.RadioButton - Me.UpdatedEnabled = New System.Windows.Forms.RadioButton - Me.ButtonApply = New System.Windows.Forms.Button - Me.CountryGrid = New System.Windows.Forms.DataGrid - Me.DataGridTableStyle1 = New System.Windows.Forms.DataGridTableStyle - Me.TextBoxCountryname = New System.Windows.Forms.DataGridTextBoxColumn - Me.TextBoxpopulation = New System.Windows.Forms.DataGridTextBoxColumn - Me.TextBoxLanguage = New System.Windows.Forms.DataGridTextBoxColumn - Me.TextBoxCurrency = New System.Windows.Forms.DataGridTextBoxColumn - Me.GroupBox1.SuspendLayout() - Me.Connection.SuspendLayout() - Me.GroupBoxupdating1.SuspendLayout() - Me.GroupBox2.SuspendLayout() - CType(Me.CountryGrid, System.ComponentModel.ISupportInitialize).BeginInit() - Me.SuspendLayout() - ' - 'Label1 - ' - Me.Label1.Font = New System.Drawing.Font("Arial", 16.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) - Me.Label1.Location = New System.Drawing.Point(24, 8) - Me.Label1.Name = "Label1" - Me.Label1.Size = New System.Drawing.Size(496, 24) - Me.Label1.TabIndex = 0 - Me.Label1.Text = "Row Update Event Handler Application" - Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter - ' - 'GroupBox1 - ' - Me.GroupBox1.Controls.Add(Me.StatusBox) - Me.GroupBox1.Location = New System.Drawing.Point(8, 336) - Me.GroupBox1.Name = "GroupBox1" - Me.GroupBox1.Size = New System.Drawing.Size(544, 184) - Me.GroupBox1.TabIndex = 1 - Me.GroupBox1.TabStop = False - Me.GroupBox1.Text = "Status Window" - ' - 'StatusBox - ' - Me.StatusBox.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) - Me.StatusBox.Location = New System.Drawing.Point(8, 16) - Me.StatusBox.Multiline = True - Me.StatusBox.Name = "StatusBox" - Me.StatusBox.ReadOnly = True - Me.StatusBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical - Me.StatusBox.Size = New System.Drawing.Size(528, 160) - Me.StatusBox.TabIndex = 35 - ' - 'UserNameLabel - ' - Me.UserNameLabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.25!) - Me.UserNameLabel.Location = New System.Drawing.Point(16, 56) - Me.UserNameLabel.Name = "UserNameLabel" - Me.UserNameLabel.Size = New System.Drawing.Size(80, 16) - Me.UserNameLabel.TabIndex = 0 - Me.UserNameLabel.Text = "User Name" - ' - 'UserName - ' - Me.UserName.Location = New System.Drawing.Point(96, 56) - Me.UserName.Name = "UserName" - Me.UserName.Size = New System.Drawing.Size(88, 20) - Me.UserName.TabIndex = 0 - Me.UserName.Text = "scott" - ' - 'PasswordLabel - ' - Me.PasswordLabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.25!) - Me.PasswordLabel.Location = New System.Drawing.Point(192, 56) - Me.PasswordLabel.Name = "PasswordLabel" - Me.PasswordLabel.Size = New System.Drawing.Size(72, 24) - Me.PasswordLabel.TabIndex = 0 - Me.PasswordLabel.Text = "Password" - ' - 'Password - ' - Me.Password.Location = New System.Drawing.Point(264, 56) - Me.Password.Name = "Password" - Me.Password.Size = New System.Drawing.Size(80, 20) - Me.Password.TabIndex = 1 - Me.Password.Text = "tiger" - ' - 'Connection - ' - Me.Connection.Controls.Add(Me.ButtonDisconnect) - Me.Connection.Controls.Add(Me.Status) - Me.Connection.Controls.Add(Me.StatusLabel) - Me.Connection.Controls.Add(Me.ButtonExit) - Me.Connection.Controls.Add(Me.ButtonConnect) - Me.Connection.Controls.Add(Me.DataSource) - Me.Connection.Controls.Add(Me.ConnectStringLabel) - Me.Connection.Location = New System.Drawing.Point(8, 40) - Me.Connection.Name = "Connection" - Me.Connection.Size = New System.Drawing.Size(544, 80) - Me.Connection.TabIndex = 0 - Me.Connection.TabStop = False - Me.Connection.Text = "Connection Details" - ' - 'ButtonDisconnect - ' - Me.ButtonDisconnect.Enabled = False - Me.ButtonDisconnect.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) - Me.ButtonDisconnect.Location = New System.Drawing.Point(336, 48) - Me.ButtonDisconnect.Name = "ButtonDisconnect" - Me.ButtonDisconnect.Size = New System.Drawing.Size(88, 24) - Me.ButtonDisconnect.TabIndex = 2 - Me.ButtonDisconnect.Text = "Disconnect " - ' - 'Status - ' - Me.Status.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) - Me.Status.ForeColor = System.Drawing.Color.Red - Me.Status.ImageAlign = System.Drawing.ContentAlignment.BottomCenter - Me.Status.Location = New System.Drawing.Point(80, 56) - Me.Status.Name = "Status" - Me.Status.Size = New System.Drawing.Size(120, 16) - Me.Status.TabIndex = 0 - Me.Status.Text = "Not Connected" - ' - 'StatusLabel - ' - Me.StatusLabel.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) - Me.StatusLabel.Location = New System.Drawing.Point(16, 56) - Me.StatusLabel.Name = "StatusLabel" - Me.StatusLabel.Size = New System.Drawing.Size(48, 16) - Me.StatusLabel.TabIndex = 0 - Me.StatusLabel.Text = "Status: " - ' - 'ButtonExit - ' - Me.ButtonExit.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) - Me.ButtonExit.Location = New System.Drawing.Point(448, 48) - Me.ButtonExit.Name = "ButtonExit" - Me.ButtonExit.Size = New System.Drawing.Size(88, 24) - Me.ButtonExit.TabIndex = 2 - Me.ButtonExit.Text = "Exit" - ' - 'ButtonConnect - ' - Me.ButtonConnect.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) - Me.ButtonConnect.Location = New System.Drawing.Point(224, 48) - Me.ButtonConnect.Name = "ButtonConnect" - Me.ButtonConnect.Size = New System.Drawing.Size(88, 24) - Me.ButtonConnect.TabIndex = 1 - Me.ButtonConnect.Text = "Connect " - ' - 'DataSource - ' - Me.DataSource.Location = New System.Drawing.Point(448, 16) - Me.DataSource.Name = "DataSource" - Me.DataSource.Size = New System.Drawing.Size(88, 20) - Me.DataSource.TabIndex = 0 - Me.DataSource.Text = "oracle" - ' - 'ConnectStringLabel - ' - Me.ConnectStringLabel.Font = New System.Drawing.Font("Arial", 10.25!) - Me.ConnectStringLabel.Location = New System.Drawing.Point(344, 16) - Me.ConnectStringLabel.Name = "ConnectStringLabel" - Me.ConnectStringLabel.Size = New System.Drawing.Size(104, 24) - Me.ConnectStringLabel.TabIndex = 4 - Me.ConnectStringLabel.Text = "Data Source" - ' - 'Label2 - ' - Me.Label2.Font = New System.Drawing.Font("Arial", 10.25!, System.Drawing.FontStyle.Bold) - Me.Label2.Location = New System.Drawing.Point(216, 8) - Me.Label2.Name = "Label2" - Me.Label2.Size = New System.Drawing.Size(96, 24) - Me.Label2.TabIndex = 0 - Me.Label2.Text = "Source Code " - ' - 'ButtonUpdate - ' - Me.ButtonUpdate.Enabled = False - Me.ButtonUpdate.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold) - Me.ButtonUpdate.Location = New System.Drawing.Point(456, 248) - Me.ButtonUpdate.Name = "ButtonUpdate" - Me.ButtonUpdate.Size = New System.Drawing.Size(88, 24) - Me.ButtonUpdate.TabIndex = 2 - Me.ButtonUpdate.Text = "Update" - ' - 'GroupBoxupdating1 - ' - Me.GroupBoxupdating1.Controls.Add(Me.UpdatingDisabled) - Me.GroupBoxupdating1.Controls.Add(Me.UpdatingEnabled) - Me.GroupBoxupdating1.Location = New System.Drawing.Point(8, 280) - Me.GroupBoxupdating1.Name = "GroupBoxupdating1" - Me.GroupBoxupdating1.Size = New System.Drawing.Size(208, 48) - Me.GroupBoxupdating1.TabIndex = 10 - Me.GroupBoxupdating1.TabStop = False - Me.GroupBoxupdating1.Text = "OracleRowUpdatingEventHandler" - ' - 'UpdatingDisabled - ' - Me.UpdatingDisabled.Enabled = False - Me.UpdatingDisabled.Location = New System.Drawing.Point(112, 24) - Me.UpdatingDisabled.Name = "UpdatingDisabled" - Me.UpdatingDisabled.Size = New System.Drawing.Size(72, 16) - Me.UpdatingDisabled.TabIndex = 1 - Me.UpdatingDisabled.Text = "Disabled" - ' - 'UpdatingEnabled - ' - Me.UpdatingEnabled.Checked = True - Me.UpdatingEnabled.Enabled = False - Me.UpdatingEnabled.Location = New System.Drawing.Point(24, 24) - Me.UpdatingEnabled.Name = "UpdatingEnabled" - Me.UpdatingEnabled.Size = New System.Drawing.Size(112, 16) - Me.UpdatingEnabled.TabIndex = 0 - Me.UpdatingEnabled.TabStop = True - Me.UpdatingEnabled.Text = "Enabled" - ' - 'GroupBox2 - ' - Me.GroupBox2.Controls.Add(Me.UpdatedDisabled) - Me.GroupBox2.Controls.Add(Me.UpdatedEnabled) - Me.GroupBox2.Location = New System.Drawing.Point(240, 280) - Me.GroupBox2.Name = "GroupBox2" - Me.GroupBox2.Size = New System.Drawing.Size(208, 48) - Me.GroupBox2.TabIndex = 11 - Me.GroupBox2.TabStop = False - Me.GroupBox2.Text = "OracleRowUpdatedEventHandler" - ' - 'UpdatedDisabled - ' - Me.UpdatedDisabled.Enabled = False - Me.UpdatedDisabled.Location = New System.Drawing.Point(96, 24) - Me.UpdatedDisabled.Name = "UpdatedDisabled" - Me.UpdatedDisabled.Size = New System.Drawing.Size(72, 16) - Me.UpdatedDisabled.TabIndex = 1 - Me.UpdatedDisabled.Text = "Disabled" - ' - 'UpdatedEnabled - ' - Me.UpdatedEnabled.Checked = True - Me.UpdatedEnabled.Enabled = False - Me.UpdatedEnabled.Location = New System.Drawing.Point(16, 24) - Me.UpdatedEnabled.Name = "UpdatedEnabled" - Me.UpdatedEnabled.Size = New System.Drawing.Size(104, 16) - Me.UpdatedEnabled.TabIndex = 0 - Me.UpdatedEnabled.TabStop = True - Me.UpdatedEnabled.Text = "Enabled" - ' - 'ButtonApply - ' - Me.ButtonApply.Enabled = False - Me.ButtonApply.Location = New System.Drawing.Point(456, 304) - Me.ButtonApply.Name = "ButtonApply" - Me.ButtonApply.Size = New System.Drawing.Size(88, 24) - Me.ButtonApply.TabIndex = 3 - Me.ButtonApply.Text = "Apply" - ' - 'CountryGrid - ' - Me.CountryGrid.CaptionText = "Country Table" - Me.CountryGrid.DataMember = "" - Me.CountryGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText - Me.CountryGrid.Location = New System.Drawing.Point(8, 136) - Me.CountryGrid.Name = "CountryGrid" - Me.CountryGrid.PreferredColumnWidth = 100 - Me.CountryGrid.Size = New System.Drawing.Size(440, 136) - Me.CountryGrid.TabIndex = 4 - Me.CountryGrid.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {Me.DataGridTableStyle1}) - ' - 'DataGridTableStyle1 - ' - Me.DataGridTableStyle1.DataGrid = Me.CountryGrid - Me.DataGridTableStyle1.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.TextBoxCountryname, Me.TextBoxpopulation, Me.TextBoxLanguage, Me.TextBoxCurrency}) - Me.DataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText - ' - 'TextBoxCountryname - ' - Me.TextBoxCountryname.Format = "" - Me.TextBoxCountryname.FormatInfo = Nothing - Me.TextBoxCountryname.MappingName = "COUNTRYNAME" - Me.TextBoxCountryname.ReadOnly = True - Me.TextBoxCountryname.Width = 20 - ' - 'TextBoxpopulation - ' - Me.TextBoxpopulation.Format = "" - Me.TextBoxpopulation.FormatInfo = Nothing - Me.TextBoxpopulation.MappingName = "POPULATION" - Me.TextBoxpopulation.ReadOnly = True - Me.TextBoxpopulation.Width = 20 - ' - 'TextBoxLanguage - ' - Me.TextBoxLanguage.Format = "" - Me.TextBoxLanguage.FormatInfo = Nothing - Me.TextBoxLanguage.MappingName = "LANGUAGE" - Me.TextBoxLanguage.NullText = "NULL" - Me.TextBoxLanguage.Width = 20 - ' - 'TextBoxCurrency - ' - Me.TextBoxCurrency.Format = "" - Me.TextBoxCurrency.FormatInfo = Nothing - Me.TextBoxCurrency.MappingName = "CURRENCY" - Me.TextBoxCurrency.NullText = "NULL" - Me.TextBoxCurrency.Width = 20 - ' - 'RowUpdate - ' - Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) - Me.ClientSize = New System.Drawing.Size(552, 514) - Me.Controls.Add(Me.CountryGrid) - Me.Controls.Add(Me.ButtonApply) - Me.Controls.Add(Me.GroupBox2) - Me.Controls.Add(Me.GroupBoxupdating1) - Me.Controls.Add(Me.ButtonUpdate) - Me.Controls.Add(Me.Password) - Me.Controls.Add(Me.PasswordLabel) - Me.Controls.Add(Me.UserName) - Me.Controls.Add(Me.UserNameLabel) - Me.Controls.Add(Me.GroupBox1) - Me.Controls.Add(Me.Label1) - Me.Controls.Add(Me.Connection) - Me.Controls.Add(Me.Label2) - Me.MaximizeBox = False - Me.MaximumSize = New System.Drawing.Size(568, 552) - Me.MinimumSize = New System.Drawing.Size(568, 552) - Me.Name = "RowUpdate" - Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen - Me.Text = "Row Update Event Handler Application" - Me.GroupBox1.ResumeLayout(False) - Me.GroupBox1.PerformLayout() - Me.Connection.ResumeLayout(False) - Me.Connection.PerformLayout() - Me.GroupBoxupdating1.ResumeLayout(False) - Me.GroupBox2.ResumeLayout(False) - CType(Me.CountryGrid, System.ComponentModel.ISupportInitialize).EndInit() - Me.ResumeLayout(False) - Me.PerformLayout() - - End Sub - -#End Region - - '************************************************************************** - 'This method handles the Connect button click event. With the help of DBAccess - 'class it tries to connect to the database. If connection is obtained then - 'other GUI components are enabled. - '************************************************************************** - Private Sub ButtonConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonConnect.Click - - ButtonExit.Enabled = False - Dim tempStr As String = UserName.Text - Dim flag As Boolean = True - 'Check if Username width is more than 0 characters - If (tempStr.Length = 0) Then - flag = False - MessageBox.Show("Username cannot be a null String", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error) - Return - End If - tempStr = Password.Text - 'Check if Password width is more than 0 characters - If (tempStr.Length = 0) Then - flag = False - MessageBox.Show("Password cannot be a null String", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error) - Return - End If - tempStr = DataSource.Text - 'Check if dataSource width is more than 0 characters - If (tempStr.Length = 0) Then - flag = False - MessageBox.Show("DataSource cannot be a null String", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error) - Return - End If - - If (flag = True) Then - 'Trying to connect disable connect button - ButtonConnect.Enabled = False - 'Try to connect to the database - dba.connect(UserName.Text, Password.Text, DataSource.Text) - 'If no exception is thrown set status to true - statusbool = True - End If - - 'Check if the program is connected to the database and enable user - 'controls if it is connected. - flag = dba.isConnected - If (flag = True) Then - Status.Text = "Connected" - Status.ForeColor = Color.Green - Status.Update() - dba.CreateTable() - dba.PopulateDataGrid(CountryGrid) - ButtonUpdate.Enabled = True - UpdatingEnabled.Enabled = True - UpdatingDisabled.Enabled = True - UpdatedEnabled.Enabled = True - UpdatedDisabled.Enabled = True - ButtonApply.Enabled = True - ButtonConnect.Enabled = False - ButtonDisconnect.Enabled = True - ButtonExit.Enabled = False - CountryGrid.Enabled = True - ButtonUpdate.Enabled = True - ButtonApply.Enabled = True - ButtonExit.Enabled = False - Else - 'Not connected to database enable connect button - Status.Text = "Not Connected" - Status.ForeColor = Color.Red - ButtonConnect.Enabled = True - ButtonDisconnect.Enabled = False - ButtonUpdate.Enabled = False - ButtonApply.Enabled = False - ButtonExit.Enabled = True - End If - - End Sub - - '************************************************************************** - 'This method handles the Exit button click event. Closes the connection and - 'exits the application. - '************************************************************************** - Private Sub ButtonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonExit.Click - 'Update status text and color - Status.Text = "Exiting, Please wait" - Status.ForeColor = Color.Red - Status.Update() - Thread.CurrentThread.Sleep(1500) - 'Exit the application - Application.Exit() - End Sub - - '************************************************************************** - 'This method handles the Update button click event. Updates the database with - 'the modified DataGrid entries. - '************************************************************************** - Private Sub ButtonUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click - 'Update the database - dba.UpdateRecords() - End Sub - - '************************************************************************** - 'This method handles the Apply button click event. Either registers or - 'de-registers the event handlers depending on radio button states. - '************************************************************************** - Private Sub ButtonApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonApply.Click - - 'Check the radio buttons that are selected and call appropriate methods. - If (UpdatingEnabled.Checked = True) Then - dba.AddUpdatingHandler() - End If - - If (UpdatingDisabled.Checked = True) Then - dba.RemoveUpdatingHandler() - End If - - If (UpdatedEnabled.Checked = True) Then - dba.AddUpdatedHandler() - End If - - If (UpdatedDisabled.Checked = True) Then - dba.RemoveUpdatedHandler() - End If - StatusBox.AppendText("Event Handlers Updated" + Environment.NewLine) - StatusBox.Update() - End Sub - - '************************************************************************** - 'This method prevents insertion of new row - '************************************************************************** - Private Sub CountryGrid_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CountryGrid.CurrentCellChanged - If (CountryGrid.CurrentCell.RowNumber > 3) Then - CountryGrid.CurrentCell = New DataGridCell(3, CountryGrid.CurrentCell.ColumnNumber) - End If - End Sub - - '************************************************************************** - 'This method is called when users press Disconnect button - '************************************************************************** - Private Sub ButtonDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDisconnect.Click - ButtonDisconnect.Enabled = False - CountryGrid.Enabled = False - dba.RemoveUpdatedHandler() - dba.RemoveUpdatingHandler() - ButtonUpdate.Enabled = False - ButtonApply.Enabled = False - dba.closeConnection() - Status.Text = "Not Connected" - Status.ForeColor = Color.Red - ButtonExit.Enabled = True - ButtonConnect.Enabled = True - ButtonExit.Enabled = True - End Sub - - '************************************************************************** - 'This method is called when user closes the form - '************************************************************************** - Private Sub Form_Close(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closed - ButtonUpdate.Enabled = False - ButtonApply.Enabled = False - ButtonExit.Enabled = False - ButtonConnect.Enabled = False - ButtonDisconnect.Enabled = False - dba.closeConnection() - Application.Exit() - End Sub - - -End Class +Imports System.Threading +Public Class RowUpdate + Inherits System.Windows.Forms.Form + Protected dba As DBAccess + Protected statusbool As Boolean + +#Region " Windows Form Designer generated code " + + Public Sub New() + MyBase.New() + + 'This call is required by the Windows Form Designer. + InitializeComponent() + + 'Add any initialization after the InitializeComponent() call + 'Create instance of the database access helper class and pass the reference + 'of status window to this object + dba = New DBAccess(StatusBox) + End Sub + + 'Form overrides dispose to clean up the component list. + Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) + If disposing Then + If Not (components Is Nothing) Then + components.Dispose() + End If + End If + MyBase.Dispose(disposing) + End Sub + + 'Required by the Windows Form Designer + Private components As System.ComponentModel.IContainer + + 'NOTE: The following procedure is required by the Windows Form Designer + 'It can be modified using the Windows Form Designer. + 'Do not modify it using the code editor. + Friend WithEvents Label1 As System.Windows.Forms.Label + Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox + Friend WithEvents Connection As System.Windows.Forms.GroupBox + Friend WithEvents UserNameLabel As System.Windows.Forms.Label + Friend WithEvents UserName As System.Windows.Forms.TextBox + Friend WithEvents PasswordLabel As System.Windows.Forms.Label + Friend WithEvents Password As System.Windows.Forms.TextBox + Friend WithEvents ConnectStringLabel As System.Windows.Forms.Label + Friend WithEvents ButtonConnect As System.Windows.Forms.Button + Friend WithEvents ButtonExit As System.Windows.Forms.Button + Friend WithEvents StatusLabel As System.Windows.Forms.Label + Friend WithEvents Status As System.Windows.Forms.Label + Friend WithEvents StatusBox As System.Windows.Forms.TextBox + Friend WithEvents DataSource As System.Windows.Forms.TextBox + Friend WithEvents Label2 As System.Windows.Forms.Label + Friend WithEvents ButtonUpdate As System.Windows.Forms.Button + Friend WithEvents GroupBoxupdating1 As System.Windows.Forms.GroupBox + Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox + Friend WithEvents UpdatingEnabled As System.Windows.Forms.RadioButton + Friend WithEvents UpdatingDisabled As System.Windows.Forms.RadioButton + Friend WithEvents UpdatedEnabled As System.Windows.Forms.RadioButton + Friend WithEvents UpdatedDisabled As System.Windows.Forms.RadioButton + Friend WithEvents ButtonApply As System.Windows.Forms.Button + Friend WithEvents CountryGrid As System.Windows.Forms.DataGrid + Friend WithEvents DataGridTableStyle1 As System.Windows.Forms.DataGridTableStyle + Friend WithEvents TextBoxCountryname As System.Windows.Forms.DataGridTextBoxColumn + Friend WithEvents TextBoxpopulation As System.Windows.Forms.DataGridTextBoxColumn + Friend WithEvents TextBoxLanguage As System.Windows.Forms.DataGridTextBoxColumn + Friend WithEvents TextBoxCurrency As System.Windows.Forms.DataGridTextBoxColumn + Friend WithEvents ButtonDisconnect As System.Windows.Forms.Button + Private Sub InitializeComponent() + Me.Label1 = New System.Windows.Forms.Label + Me.GroupBox1 = New System.Windows.Forms.GroupBox + Me.StatusBox = New System.Windows.Forms.TextBox + Me.UserNameLabel = New System.Windows.Forms.Label + Me.UserName = New System.Windows.Forms.TextBox + Me.PasswordLabel = New System.Windows.Forms.Label + Me.Password = New System.Windows.Forms.TextBox + Me.Connection = New System.Windows.Forms.GroupBox + Me.ButtonDisconnect = New System.Windows.Forms.Button + Me.Status = New System.Windows.Forms.Label + Me.StatusLabel = New System.Windows.Forms.Label + Me.ButtonExit = New System.Windows.Forms.Button + Me.ButtonConnect = New System.Windows.Forms.Button + Me.DataSource = New System.Windows.Forms.TextBox + Me.ConnectStringLabel = New System.Windows.Forms.Label + Me.Label2 = New System.Windows.Forms.Label + Me.ButtonUpdate = New System.Windows.Forms.Button + Me.GroupBoxupdating1 = New System.Windows.Forms.GroupBox + Me.UpdatingDisabled = New System.Windows.Forms.RadioButton + Me.UpdatingEnabled = New System.Windows.Forms.RadioButton + Me.GroupBox2 = New System.Windows.Forms.GroupBox + Me.UpdatedDisabled = New System.Windows.Forms.RadioButton + Me.UpdatedEnabled = New System.Windows.Forms.RadioButton + Me.ButtonApply = New System.Windows.Forms.Button + Me.CountryGrid = New System.Windows.Forms.DataGrid + Me.DataGridTableStyle1 = New System.Windows.Forms.DataGridTableStyle + Me.TextBoxCountryname = New System.Windows.Forms.DataGridTextBoxColumn + Me.TextBoxpopulation = New System.Windows.Forms.DataGridTextBoxColumn + Me.TextBoxLanguage = New System.Windows.Forms.DataGridTextBoxColumn + Me.TextBoxCurrency = New System.Windows.Forms.DataGridTextBoxColumn + Me.GroupBox1.SuspendLayout() + Me.Connection.SuspendLayout() + Me.GroupBoxupdating1.SuspendLayout() + Me.GroupBox2.SuspendLayout() + CType(Me.CountryGrid, System.ComponentModel.ISupportInitialize).BeginInit() + Me.SuspendLayout() + ' + 'Label1 + ' + Me.Label1.Font = New System.Drawing.Font("Arial", 16.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) + Me.Label1.Location = New System.Drawing.Point(24, 8) + Me.Label1.Name = "Label1" + Me.Label1.Size = New System.Drawing.Size(496, 24) + Me.Label1.TabIndex = 0 + Me.Label1.Text = "Row Update Event Handler Application" + Me.Label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter + ' + 'GroupBox1 + ' + Me.GroupBox1.Controls.Add(Me.StatusBox) + Me.GroupBox1.Location = New System.Drawing.Point(8, 336) + Me.GroupBox1.Name = "GroupBox1" + Me.GroupBox1.Size = New System.Drawing.Size(544, 184) + Me.GroupBox1.TabIndex = 1 + Me.GroupBox1.TabStop = False + Me.GroupBox1.Text = "Status Window" + ' + 'StatusBox + ' + Me.StatusBox.Font = New System.Drawing.Font("Verdana", 9.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) + Me.StatusBox.Location = New System.Drawing.Point(8, 16) + Me.StatusBox.Multiline = True + Me.StatusBox.Name = "StatusBox" + Me.StatusBox.ReadOnly = True + Me.StatusBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical + Me.StatusBox.Size = New System.Drawing.Size(528, 160) + Me.StatusBox.TabIndex = 35 + ' + 'UserNameLabel + ' + Me.UserNameLabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.25!) + Me.UserNameLabel.Location = New System.Drawing.Point(16, 56) + Me.UserNameLabel.Name = "UserNameLabel" + Me.UserNameLabel.Size = New System.Drawing.Size(80, 16) + Me.UserNameLabel.TabIndex = 0 + Me.UserNameLabel.Text = "User Name" + ' + 'UserName + ' + Me.UserName.Location = New System.Drawing.Point(96, 56) + Me.UserName.Name = "UserName" + Me.UserName.Size = New System.Drawing.Size(88, 20) + Me.UserName.TabIndex = 0 + Me.UserName.Text = "scott" + ' + 'PasswordLabel + ' + Me.PasswordLabel.Font = New System.Drawing.Font("Microsoft Sans Serif", 10.25!) + Me.PasswordLabel.Location = New System.Drawing.Point(192, 56) + Me.PasswordLabel.Name = "PasswordLabel" + Me.PasswordLabel.Size = New System.Drawing.Size(72, 24) + Me.PasswordLabel.TabIndex = 0 + Me.PasswordLabel.Text = "Password" + ' + 'Password + ' + Me.Password.Location = New System.Drawing.Point(264, 56) + Me.Password.Name = "Password" + Me.Password.Size = New System.Drawing.Size(80, 20) + Me.Password.TabIndex = 1 + Me.Password.Text = "" + ' + 'Connection + ' + Me.Connection.Controls.Add(Me.ButtonDisconnect) + Me.Connection.Controls.Add(Me.Status) + Me.Connection.Controls.Add(Me.StatusLabel) + Me.Connection.Controls.Add(Me.ButtonExit) + Me.Connection.Controls.Add(Me.ButtonConnect) + Me.Connection.Controls.Add(Me.DataSource) + Me.Connection.Controls.Add(Me.ConnectStringLabel) + Me.Connection.Location = New System.Drawing.Point(8, 40) + Me.Connection.Name = "Connection" + Me.Connection.Size = New System.Drawing.Size(544, 80) + Me.Connection.TabIndex = 0 + Me.Connection.TabStop = False + Me.Connection.Text = "Connection Details" + ' + 'ButtonDisconnect + ' + Me.ButtonDisconnect.Enabled = False + Me.ButtonDisconnect.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) + Me.ButtonDisconnect.Location = New System.Drawing.Point(336, 48) + Me.ButtonDisconnect.Name = "ButtonDisconnect" + Me.ButtonDisconnect.Size = New System.Drawing.Size(88, 24) + Me.ButtonDisconnect.TabIndex = 2 + Me.ButtonDisconnect.Text = "Disconnect " + ' + 'Status + ' + Me.Status.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) + Me.Status.ForeColor = System.Drawing.Color.Red + Me.Status.ImageAlign = System.Drawing.ContentAlignment.BottomCenter + Me.Status.Location = New System.Drawing.Point(80, 56) + Me.Status.Name = "Status" + Me.Status.Size = New System.Drawing.Size(120, 16) + Me.Status.TabIndex = 0 + Me.Status.Text = "Not Connected" + ' + 'StatusLabel + ' + Me.StatusLabel.Font = New System.Drawing.Font("Arial", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) + Me.StatusLabel.Location = New System.Drawing.Point(16, 56) + Me.StatusLabel.Name = "StatusLabel" + Me.StatusLabel.Size = New System.Drawing.Size(48, 16) + Me.StatusLabel.TabIndex = 0 + Me.StatusLabel.Text = "Status: " + ' + 'ButtonExit + ' + Me.ButtonExit.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) + Me.ButtonExit.Location = New System.Drawing.Point(448, 48) + Me.ButtonExit.Name = "ButtonExit" + Me.ButtonExit.Size = New System.Drawing.Size(88, 24) + Me.ButtonExit.TabIndex = 2 + Me.ButtonExit.Text = "Exit" + ' + 'ButtonConnect + ' + Me.ButtonConnect.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) + Me.ButtonConnect.Location = New System.Drawing.Point(224, 48) + Me.ButtonConnect.Name = "ButtonConnect" + Me.ButtonConnect.Size = New System.Drawing.Size(88, 24) + Me.ButtonConnect.TabIndex = 1 + Me.ButtonConnect.Text = "Connect " + ' + 'DataSource + ' + Me.DataSource.Location = New System.Drawing.Point(448, 16) + Me.DataSource.Name = "DataSource" + Me.DataSource.Size = New System.Drawing.Size(88, 20) + Me.DataSource.TabIndex = 0 + Me.DataSource.Text = "oracle" + ' + 'ConnectStringLabel + ' + Me.ConnectStringLabel.Font = New System.Drawing.Font("Arial", 10.25!) + Me.ConnectStringLabel.Location = New System.Drawing.Point(344, 16) + Me.ConnectStringLabel.Name = "ConnectStringLabel" + Me.ConnectStringLabel.Size = New System.Drawing.Size(104, 24) + Me.ConnectStringLabel.TabIndex = 4 + Me.ConnectStringLabel.Text = "Data Source" + ' + 'Label2 + ' + Me.Label2.Font = New System.Drawing.Font("Arial", 10.25!, System.Drawing.FontStyle.Bold) + Me.Label2.Location = New System.Drawing.Point(216, 8) + Me.Label2.Name = "Label2" + Me.Label2.Size = New System.Drawing.Size(96, 24) + Me.Label2.TabIndex = 0 + Me.Label2.Text = "Source Code " + ' + 'ButtonUpdate + ' + Me.ButtonUpdate.Enabled = False + Me.ButtonUpdate.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold) + Me.ButtonUpdate.Location = New System.Drawing.Point(456, 248) + Me.ButtonUpdate.Name = "ButtonUpdate" + Me.ButtonUpdate.Size = New System.Drawing.Size(88, 24) + Me.ButtonUpdate.TabIndex = 2 + Me.ButtonUpdate.Text = "Update" + ' + 'GroupBoxupdating1 + ' + Me.GroupBoxupdating1.Controls.Add(Me.UpdatingDisabled) + Me.GroupBoxupdating1.Controls.Add(Me.UpdatingEnabled) + Me.GroupBoxupdating1.Location = New System.Drawing.Point(8, 280) + Me.GroupBoxupdating1.Name = "GroupBoxupdating1" + Me.GroupBoxupdating1.Size = New System.Drawing.Size(208, 48) + Me.GroupBoxupdating1.TabIndex = 10 + Me.GroupBoxupdating1.TabStop = False + Me.GroupBoxupdating1.Text = "OracleRowUpdatingEventHandler" + ' + 'UpdatingDisabled + ' + Me.UpdatingDisabled.Enabled = False + Me.UpdatingDisabled.Location = New System.Drawing.Point(112, 24) + Me.UpdatingDisabled.Name = "UpdatingDisabled" + Me.UpdatingDisabled.Size = New System.Drawing.Size(72, 16) + Me.UpdatingDisabled.TabIndex = 1 + Me.UpdatingDisabled.Text = "Disabled" + ' + 'UpdatingEnabled + ' + Me.UpdatingEnabled.Checked = True + Me.UpdatingEnabled.Enabled = False + Me.UpdatingEnabled.Location = New System.Drawing.Point(24, 24) + Me.UpdatingEnabled.Name = "UpdatingEnabled" + Me.UpdatingEnabled.Size = New System.Drawing.Size(112, 16) + Me.UpdatingEnabled.TabIndex = 0 + Me.UpdatingEnabled.TabStop = True + Me.UpdatingEnabled.Text = "Enabled" + ' + 'GroupBox2 + ' + Me.GroupBox2.Controls.Add(Me.UpdatedDisabled) + Me.GroupBox2.Controls.Add(Me.UpdatedEnabled) + Me.GroupBox2.Location = New System.Drawing.Point(240, 280) + Me.GroupBox2.Name = "GroupBox2" + Me.GroupBox2.Size = New System.Drawing.Size(208, 48) + Me.GroupBox2.TabIndex = 11 + Me.GroupBox2.TabStop = False + Me.GroupBox2.Text = "OracleRowUpdatedEventHandler" + ' + 'UpdatedDisabled + ' + Me.UpdatedDisabled.Enabled = False + Me.UpdatedDisabled.Location = New System.Drawing.Point(96, 24) + Me.UpdatedDisabled.Name = "UpdatedDisabled" + Me.UpdatedDisabled.Size = New System.Drawing.Size(72, 16) + Me.UpdatedDisabled.TabIndex = 1 + Me.UpdatedDisabled.Text = "Disabled" + ' + 'UpdatedEnabled + ' + Me.UpdatedEnabled.Checked = True + Me.UpdatedEnabled.Enabled = False + Me.UpdatedEnabled.Location = New System.Drawing.Point(16, 24) + Me.UpdatedEnabled.Name = "UpdatedEnabled" + Me.UpdatedEnabled.Size = New System.Drawing.Size(104, 16) + Me.UpdatedEnabled.TabIndex = 0 + Me.UpdatedEnabled.TabStop = True + Me.UpdatedEnabled.Text = "Enabled" + ' + 'ButtonApply + ' + Me.ButtonApply.Enabled = False + Me.ButtonApply.Location = New System.Drawing.Point(456, 304) + Me.ButtonApply.Name = "ButtonApply" + Me.ButtonApply.Size = New System.Drawing.Size(88, 24) + Me.ButtonApply.TabIndex = 3 + Me.ButtonApply.Text = "Apply" + ' + 'CountryGrid + ' + Me.CountryGrid.CaptionText = "Country Table" + Me.CountryGrid.DataMember = "" + Me.CountryGrid.HeaderForeColor = System.Drawing.SystemColors.ControlText + Me.CountryGrid.Location = New System.Drawing.Point(8, 136) + Me.CountryGrid.Name = "CountryGrid" + Me.CountryGrid.PreferredColumnWidth = 100 + Me.CountryGrid.Size = New System.Drawing.Size(440, 136) + Me.CountryGrid.TabIndex = 4 + Me.CountryGrid.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {Me.DataGridTableStyle1}) + ' + 'DataGridTableStyle1 + ' + Me.DataGridTableStyle1.DataGrid = Me.CountryGrid + Me.DataGridTableStyle1.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.TextBoxCountryname, Me.TextBoxpopulation, Me.TextBoxLanguage, Me.TextBoxCurrency}) + Me.DataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText + ' + 'TextBoxCountryname + ' + Me.TextBoxCountryname.Format = "" + Me.TextBoxCountryname.FormatInfo = Nothing + Me.TextBoxCountryname.MappingName = "COUNTRYNAME" + Me.TextBoxCountryname.ReadOnly = True + Me.TextBoxCountryname.Width = 20 + ' + 'TextBoxpopulation + ' + Me.TextBoxpopulation.Format = "" + Me.TextBoxpopulation.FormatInfo = Nothing + Me.TextBoxpopulation.MappingName = "POPULATION" + Me.TextBoxpopulation.ReadOnly = True + Me.TextBoxpopulation.Width = 20 + ' + 'TextBoxLanguage + ' + Me.TextBoxLanguage.Format = "" + Me.TextBoxLanguage.FormatInfo = Nothing + Me.TextBoxLanguage.MappingName = "LANGUAGE" + Me.TextBoxLanguage.NullText = "NULL" + Me.TextBoxLanguage.Width = 20 + ' + 'TextBoxCurrency + ' + Me.TextBoxCurrency.Format = "" + Me.TextBoxCurrency.FormatInfo = Nothing + Me.TextBoxCurrency.MappingName = "CURRENCY" + Me.TextBoxCurrency.NullText = "NULL" + Me.TextBoxCurrency.Width = 20 + ' + 'RowUpdate + ' + Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) + Me.ClientSize = New System.Drawing.Size(552, 514) + Me.Controls.Add(Me.CountryGrid) + Me.Controls.Add(Me.ButtonApply) + Me.Controls.Add(Me.GroupBox2) + Me.Controls.Add(Me.GroupBoxupdating1) + Me.Controls.Add(Me.ButtonUpdate) + Me.Controls.Add(Me.Password) + Me.Controls.Add(Me.PasswordLabel) + Me.Controls.Add(Me.UserName) + Me.Controls.Add(Me.UserNameLabel) + Me.Controls.Add(Me.GroupBox1) + Me.Controls.Add(Me.Label1) + Me.Controls.Add(Me.Connection) + Me.Controls.Add(Me.Label2) + Me.MaximizeBox = False + Me.MaximumSize = New System.Drawing.Size(568, 552) + Me.MinimumSize = New System.Drawing.Size(568, 552) + Me.Name = "RowUpdate" + Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen + Me.Text = "Row Update Event Handler Application" + Me.GroupBox1.ResumeLayout(False) + Me.GroupBox1.PerformLayout() + Me.Connection.ResumeLayout(False) + Me.Connection.PerformLayout() + Me.GroupBoxupdating1.ResumeLayout(False) + Me.GroupBox2.ResumeLayout(False) + CType(Me.CountryGrid, System.ComponentModel.ISupportInitialize).EndInit() + Me.ResumeLayout(False) + Me.PerformLayout() + + End Sub + +#End Region + + '************************************************************************** + 'This method handles the Connect button click event. With the help of DBAccess + 'class it tries to connect to the database. If connection is obtained then + 'other GUI components are enabled. + '************************************************************************** + Private Sub ButtonConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonConnect.Click + + ButtonExit.Enabled = False + Dim tempStr As String = UserName.Text + Dim flag As Boolean = True + 'Check if Username width is more than 0 characters + If (tempStr.Length = 0) Then + flag = False + MessageBox.Show("Username cannot be a null String", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error) + Return + End If + tempStr = Password.Text + 'Check if Password width is more than 0 characters + If (tempStr.Length = 0) Then + flag = False + MessageBox.Show("Password cannot be a null String", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error) + Return + End If + tempStr = DataSource.Text + 'Check if dataSource width is more than 0 characters + If (tempStr.Length = 0) Then + flag = False + MessageBox.Show("DataSource cannot be a null String", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error) + Return + End If + + If (flag = True) Then + 'Trying to connect disable connect button + ButtonConnect.Enabled = False + 'Try to connect to the database + dba.connect(UserName.Text, Password.Text, DataSource.Text) + 'If no exception is thrown set status to true + statusbool = True + End If + + 'Check if the program is connected to the database and enable user + 'controls if it is connected. + flag = dba.isConnected + If (flag = True) Then + Status.Text = "Connected" + Status.ForeColor = Color.Green + Status.Update() + dba.CreateTable() + dba.PopulateDataGrid(CountryGrid) + ButtonUpdate.Enabled = True + UpdatingEnabled.Enabled = True + UpdatingDisabled.Enabled = True + UpdatedEnabled.Enabled = True + UpdatedDisabled.Enabled = True + ButtonApply.Enabled = True + ButtonConnect.Enabled = False + ButtonDisconnect.Enabled = True + ButtonExit.Enabled = False + CountryGrid.Enabled = True + ButtonUpdate.Enabled = True + ButtonApply.Enabled = True + ButtonExit.Enabled = False + Else + 'Not connected to database enable connect button + Status.Text = "Not Connected" + Status.ForeColor = Color.Red + ButtonConnect.Enabled = True + ButtonDisconnect.Enabled = False + ButtonUpdate.Enabled = False + ButtonApply.Enabled = False + ButtonExit.Enabled = True + End If + + End Sub + + '************************************************************************** + 'This method handles the Exit button click event. Closes the connection and + 'exits the application. + '************************************************************************** + Private Sub ButtonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonExit.Click + 'Update status text and color + Status.Text = "Exiting, Please wait" + Status.ForeColor = Color.Red + Status.Update() + Thread.CurrentThread.Sleep(1500) + 'Exit the application + Application.Exit() + End Sub + + '************************************************************************** + 'This method handles the Update button click event. Updates the database with + 'the modified DataGrid entries. + '************************************************************************** + Private Sub ButtonUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonUpdate.Click + 'Update the database + dba.UpdateRecords() + End Sub + + '************************************************************************** + 'This method handles the Apply button click event. Either registers or + 'de-registers the event handlers depending on radio button states. + '************************************************************************** + Private Sub ButtonApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonApply.Click + + 'Check the radio buttons that are selected and call appropriate methods. + If (UpdatingEnabled.Checked = True) Then + dba.AddUpdatingHandler() + End If + + If (UpdatingDisabled.Checked = True) Then + dba.RemoveUpdatingHandler() + End If + + If (UpdatedEnabled.Checked = True) Then + dba.AddUpdatedHandler() + End If + + If (UpdatedDisabled.Checked = True) Then + dba.RemoveUpdatedHandler() + End If + StatusBox.AppendText("Event Handlers Updated" + Environment.NewLine) + StatusBox.Update() + End Sub + + '************************************************************************** + 'This method prevents insertion of new row + '************************************************************************** + Private Sub CountryGrid_CurrentCellChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CountryGrid.CurrentCellChanged + If (CountryGrid.CurrentCell.RowNumber > 3) Then + CountryGrid.CurrentCell = New DataGridCell(3, CountryGrid.CurrentCell.ColumnNumber) + End If + End Sub + + '************************************************************************** + 'This method is called when users press Disconnect button + '************************************************************************** + Private Sub ButtonDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDisconnect.Click + ButtonDisconnect.Enabled = False + CountryGrid.Enabled = False + dba.RemoveUpdatedHandler() + dba.RemoveUpdatingHandler() + ButtonUpdate.Enabled = False + ButtonApply.Enabled = False + dba.closeConnection() + Status.Text = "Not Connected" + Status.ForeColor = Color.Red + ButtonExit.Enabled = True + ButtonConnect.Enabled = True + ButtonExit.Enabled = True + End Sub + + '************************************************************************** + 'This method is called when user closes the form + '************************************************************************** + Private Sub Form_Close(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closed + ButtonUpdate.Enabled = False + ButtonApply.Enabled = False + ButtonExit.Enabled = False + ButtonConnect.Enabled = False + ButtonDisconnect.Enabled = False + dba.closeConnection() + Application.Exit() + End Sub + + +End Class diff --git a/samples/lob/Sample2.cs b/samples/lob/Sample2.cs index ac9d4028..58e40c93 100644 --- a/samples/lob/Sample2.cs +++ b/samples/lob/Sample2.cs @@ -15,139 +15,139 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample2 -{ - /// - /// Sample 2: Demonstrates how an OracleClob object is obtained - /// as an output parameter of an anonymous PL/SQL block - /// - class Sample2 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup - Setup(con); - - // Set the command - OracleCommand cmd = new OracleCommand( - "begin select story into :1 from multimedia_tab where thekey = 1; end;"); - cmd.Connection = con; - cmd.CommandType = CommandType.Text; - - // Bind a parameter - OracleParameter param = cmd.Parameters.Add("clobdata", - OracleDbType.Clob); - param.Direction = ParameterDirection.Output; - - // Execute command - try - { - cmd.ExecuteNonQuery(); - - // Obtain LOB data as a .NET Type. - // cmd.Parameters[0].Value is an object of OracleClob. - // OracleClob.Value property retuns CLOB data as a string. - string lob_data = (string) ((OracleClob)(cmd.Parameters[0].Value)).Value; - - // Print out the text - Console.WriteLine("Data is: " + lob_data); - } - catch (Exception e) - { - Console.WriteLine(e.Message); - } - finally - { - // Dispose OracleCommand object - cmd.Dispose(); - - // Close and Dispose OracleConnection object - con.Close(); - con.Dispose(); - } - } - - /// - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("", con); - - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample2 +{ + /// + /// Sample 2: Demonstrates how an OracleClob object is obtained + /// as an output parameter of an anonymous PL/SQL block + /// + class Sample2 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup + Setup(con); + + // Set the command + OracleCommand cmd = new OracleCommand( + "begin select story into :1 from multimedia_tab where thekey = 1; end;"); + cmd.Connection = con; + cmd.CommandType = CommandType.Text; + + // Bind a parameter + OracleParameter param = cmd.Parameters.Add("clobdata", + OracleDbType.Clob); + param.Direction = ParameterDirection.Output; + + // Execute command + try + { + cmd.ExecuteNonQuery(); + + // Obtain LOB data as a .NET Type. + // cmd.Parameters[0].Value is an object of OracleClob. + // OracleClob.Value property retuns CLOB data as a string. + string lob_data = (string) ((OracleClob)(cmd.Parameters[0].Value)).Value; + + // Print out the text + Console.WriteLine("Data is: " + lob_data); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + finally + { + // Dispose OracleCommand object + cmd.Dispose(); + + // Close and Dispose OracleConnection object + con.Close(); + con.Dispose(); + } + } + + /// + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("", con); + + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + } +} diff --git a/samples/lob/Sample3.cs b/samples/lob/Sample3.cs index 817440b9..2b8dd3e8 100644 --- a/samples/lob/Sample3.cs +++ b/samples/lob/Sample3.cs @@ -15,155 +15,155 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample3 -{ - /// - /// Sample 3: Demonstrates how an OracleClob object is obtained - /// from an output parameter of a stored procedure - /// - class Sample3 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup - Setup(con); - - // Set the command - OracleCommand cmd = new OracleCommand("", con); - cmd.CommandText = "SelectStory"; - cmd.CommandType = CommandType.StoredProcedure; - - // Bind the OraLob Object - OracleParameter param = cmd.Parameters.Add("clobdata", - OracleDbType.Clob); - param.Direction = ParameterDirection.Output; - - // Execute command - try - { - cmd.ExecuteNonQuery(); - - // Obtain LOB data as a .NET Type. - // cmd.Parameters[0].value is an OracleClob object. - // OracleClob.Value property retuns CLOB data as a string. - string lob_data = (string) ((OracleClob)(cmd.Parameters[0].Value)).Value; - - // Print out the text - Console.WriteLine("Data is: " + lob_data); - } - catch (Exception e) - { - Console.WriteLine(e.Message); - } - finally - { - // Dispose OracleCommand object - cmd.Dispose(); - - // Close and Dispose OracleConnection object - con.Close(); - con.Dispose(); - } - } - - /// - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("", con); - - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - // Build a SQL that creates stored procedure - StringBuilder sql = new StringBuilder(); - sql.Append("create or replace procedure SelectStory ( "); - sql.Append("clob_data OUT CLOB) as "); - sql.Append("begin "); - sql.Append(" select story into clob_data from multimedia_tab where thekey = 1; "); - sql.Append("end SelectStory;"); - cmd.CommandText = sql.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample3 +{ + /// + /// Sample 3: Demonstrates how an OracleClob object is obtained + /// from an output parameter of a stored procedure + /// + class Sample3 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup + Setup(con); + + // Set the command + OracleCommand cmd = new OracleCommand("", con); + cmd.CommandText = "SelectStory"; + cmd.CommandType = CommandType.StoredProcedure; + + // Bind the OraLob Object + OracleParameter param = cmd.Parameters.Add("clobdata", + OracleDbType.Clob); + param.Direction = ParameterDirection.Output; + + // Execute command + try + { + cmd.ExecuteNonQuery(); + + // Obtain LOB data as a .NET Type. + // cmd.Parameters[0].value is an OracleClob object. + // OracleClob.Value property retuns CLOB data as a string. + string lob_data = (string) ((OracleClob)(cmd.Parameters[0].Value)).Value; + + // Print out the text + Console.WriteLine("Data is: " + lob_data); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + } + finally + { + // Dispose OracleCommand object + cmd.Dispose(); + + // Close and Dispose OracleConnection object + con.Close(); + con.Dispose(); + } + } + + /// + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("", con); + + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + // Build a SQL that creates stored procedure + StringBuilder sql = new StringBuilder(); + sql.Append("create or replace procedure SelectStory ( "); + sql.Append("clob_data OUT CLOB) as "); + sql.Append("begin "); + sql.Append(" select story into clob_data from multimedia_tab where thekey = 1; "); + sql.Append("end SelectStory;"); + cmd.CommandText = sql.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + } +} diff --git a/samples/lob/Sample4.cs b/samples/lob/Sample4.cs index de66d69e..f8ca9fea 100644 --- a/samples/lob/Sample4.cs +++ b/samples/lob/Sample4.cs @@ -15,152 +15,152 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample4 -{ - /// - /// Sample 4: Demonstrates how the LOB column data can be - /// read as a .NET type by utilizing stream reads. - /// l - class Sample4 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup - Setup(con); - - // Set the command - OracleCommand cmd = new OracleCommand( - "select story from multimedia_tab where thekey = 1"); - cmd.Connection = con; - cmd.CommandType = CommandType.Text; - - OracleDataReader reader; - try - { - // Create DataReader - reader = cmd.ExecuteReader(); - - // Read the first row - while(reader.Read()) - { - // Set the OracleClob object to the CLOB selected - OracleClob clob = reader.GetOracleClob(0); - - // Read data all data - Byte [] clob_data = new Byte[120]; - Int64 amountRead = 0; - int readSize = 8; - Int64 totalRead = 0; - - do - { - amountRead = clob.Read(clob_data, (int)totalRead, readSize); - Console.WriteLine("Actual read: {0} bytes", amountRead); - totalRead += amountRead; - } while(amountRead > 0); - - Console.WriteLine("Total number of bytes read: {0}", totalRead); - - // Dispose OracleClob object - clob.Dispose(); - } - } - catch (Exception e) - { - Console.WriteLine("Exception:" + e.Message); - } - finally - { - // Dispose OracleCommand object - cmd.Dispose(); - - // Close and Dispose OracleConnection object - con.Close(); - con.Dispose(); - } - } - - /// - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("", con); - - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample4 +{ + /// + /// Sample 4: Demonstrates how the LOB column data can be + /// read as a .NET type by utilizing stream reads. + /// l + class Sample4 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup + Setup(con); + + // Set the command + OracleCommand cmd = new OracleCommand( + "select story from multimedia_tab where thekey = 1"); + cmd.Connection = con; + cmd.CommandType = CommandType.Text; + + OracleDataReader reader; + try + { + // Create DataReader + reader = cmd.ExecuteReader(); + + // Read the first row + while(reader.Read()) + { + // Set the OracleClob object to the CLOB selected + OracleClob clob = reader.GetOracleClob(0); + + // Read data all data + Byte [] clob_data = new Byte[120]; + Int64 amountRead = 0; + int readSize = 8; + Int64 totalRead = 0; + + do + { + amountRead = clob.Read(clob_data, (int)totalRead, readSize); + Console.WriteLine("Actual read: {0} bytes", amountRead); + totalRead += amountRead; + } while(amountRead > 0); + + Console.WriteLine("Total number of bytes read: {0}", totalRead); + + // Dispose OracleClob object + clob.Dispose(); + } + } + catch (Exception e) + { + Console.WriteLine("Exception:" + e.Message); + } + finally + { + // Dispose OracleCommand object + cmd.Dispose(); + + // Close and Dispose OracleConnection object + con.Close(); + con.Dispose(); + } + } + + /// + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("", con); + + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + } +} diff --git a/samples/lob/Sample5.cs b/samples/lob/Sample5.cs index 5bce6778..b4fd802b 100644 --- a/samples/lob/Sample5.cs +++ b/samples/lob/Sample5.cs @@ -15,169 +15,169 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample5 -{ - /// - /// Sample 5: Demonstrates how to bind an OracleClob object - /// as a parameter. This sample also refetches the newly - /// updated CLOB data using an OracleDataReader and an - /// OracleClob object. - /// - class Sample5 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup - Setup(con); - - // Set the command - OracleCommand cmd = new OracleCommand( - "update multimedia_tab set story = :1 where thekey = 1"); - cmd.Connection = con; - cmd.CommandType = CommandType.Text; - - // Create an OracleClob object, specifying no caching and not a NCLOB - OracleClob clob = new OracleClob(con, false, false); - - // Write data to the OracleClob object, clob, which is a temporary LOB - string str = "this is a new story"; - clob.Write(str.ToCharArray(), 0, str.Length); - - // Bind a parameter with OracleDbType.Clob - cmd.Parameters.Add("clobdata", - OracleDbType.Clob, - clob, - ParameterDirection.Input); - - try - { - // Execute command - cmd.ExecuteNonQuery(); - - // A new command text - cmd.CommandText = "select thekey, story from multimedia_tab where thekey = 1"; - - // Create DataReader - OracleDataReader reader = null; - try - { - reader = cmd.ExecuteReader(); - } - catch (Exception e) - { - Console.WriteLine(e.Message); - Console.WriteLine(e.StackTrace); - } - - // Read the first row - reader.Read(); - - // Get an OracleClob object from the DataReader. Column index is 0-based. - // clob is no more a temporary LOB. It's now a persistent LOB. - clob = reader.GetOracleClob(1); - - // Display the new data using Value property - Console.WriteLine(clob.Value); - } - catch (Exception e) - { - Console.WriteLine("Exception:" + e.Message); - } - finally - { - // Dispose OracleClob object - clob.Dispose(); - - // Dispose OracleCommand object - cmd.Dispose(); - - // Close and Dispose OracleConnection object - con.Close(); - con.Dispose(); - } - } - - /// - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("", con); - - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample5 +{ + /// + /// Sample 5: Demonstrates how to bind an OracleClob object + /// as a parameter. This sample also refetches the newly + /// updated CLOB data using an OracleDataReader and an + /// OracleClob object. + /// + class Sample5 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup + Setup(con); + + // Set the command + OracleCommand cmd = new OracleCommand( + "update multimedia_tab set story = :1 where thekey = 1"); + cmd.Connection = con; + cmd.CommandType = CommandType.Text; + + // Create an OracleClob object, specifying no caching and not a NCLOB + OracleClob clob = new OracleClob(con, false, false); + + // Write data to the OracleClob object, clob, which is a temporary LOB + string str = "this is a new story"; + clob.Write(str.ToCharArray(), 0, str.Length); + + // Bind a parameter with OracleDbType.Clob + cmd.Parameters.Add("clobdata", + OracleDbType.Clob, + clob, + ParameterDirection.Input); + + try + { + // Execute command + cmd.ExecuteNonQuery(); + + // A new command text + cmd.CommandText = "select thekey, story from multimedia_tab where thekey = 1"; + + // Create DataReader + OracleDataReader reader = null; + try + { + reader = cmd.ExecuteReader(); + } + catch (Exception e) + { + Console.WriteLine(e.Message); + Console.WriteLine(e.StackTrace); + } + + // Read the first row + reader.Read(); + + // Get an OracleClob object from the DataReader. Column index is 0-based. + // clob is no more a temporary LOB. It's now a persistent LOB. + clob = reader.GetOracleClob(1); + + // Display the new data using Value property + Console.WriteLine(clob.Value); + } + catch (Exception e) + { + Console.WriteLine("Exception:" + e.Message); + } + finally + { + // Dispose OracleClob object + clob.Dispose(); + + // Dispose OracleCommand object + cmd.Dispose(); + + // Close and Dispose OracleConnection object + con.Close(); + con.Dispose(); + } + } + + /// + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("", con); + + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + } +} diff --git a/samples/lob/Sample6.cs b/samples/lob/Sample6.cs index a4363757..b515d663 100644 --- a/samples/lob/Sample6.cs +++ b/samples/lob/Sample6.cs @@ -15,143 +15,143 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using System.Threading; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample6 -{ - /// - /// Sample6: Demonstrates LOB updates using row-level locking. - /// - class Sample6 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup - Setup(con); - - OracleTransaction txn = con.BeginTransaction(); - OracleCommand cmd = new OracleCommand("",con); - - try - { - // Select the LOB with the primary key - // The primary key will be used for row-level locking - cmd.CommandText = "select STORY, THEKEY from multimedia_tab where THEKEY = 1"; - - OracleDataReader reader = cmd.ExecuteReader(); - reader.Read(); - OracleClob clob = reader.GetOracleClobForUpdate(0); // Lock the row - Console.WriteLine("Old Data: {0}", clob.Value); - - // Modify the CLOB column of the row - string ending = " The end."; - clob.Append(ending.ToCharArray(), 0, ending.Length); - - // Release the lock - txn.Commit(); - - // Fetch the new data; transaction or locking not required. - cmd.CommandText = "select STORY from multimedia_tab where THEKEY = 1"; - reader = cmd.ExecuteReader(); - reader.Read(); - clob = reader.GetOracleClob(0); - Console.WriteLine("New Data: {0}", clob.Value); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - finally - { - // Dispose OracleCommand object - cmd.Dispose(); - - // Close and Dispose OracleConnection object - con.Close(); - con.Dispose(); - } - } - - /// - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("", con); - - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using System.Threading; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample6 +{ + /// + /// Sample6: Demonstrates LOB updates using row-level locking. + /// + class Sample6 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup + Setup(con); + + OracleTransaction txn = con.BeginTransaction(); + OracleCommand cmd = new OracleCommand("",con); + + try + { + // Select the LOB with the primary key + // The primary key will be used for row-level locking + cmd.CommandText = "select STORY, THEKEY from multimedia_tab where THEKEY = 1"; + + OracleDataReader reader = cmd.ExecuteReader(); + reader.Read(); + OracleClob clob = reader.GetOracleClobForUpdate(0); // Lock the row + Console.WriteLine("Old Data: {0}", clob.Value); + + // Modify the CLOB column of the row + string ending = " The end."; + clob.Append(ending.ToCharArray(), 0, ending.Length); + + // Release the lock + txn.Commit(); + + // Fetch the new data; transaction or locking not required. + cmd.CommandText = "select STORY from multimedia_tab where THEKEY = 1"; + reader = cmd.ExecuteReader(); + reader.Read(); + clob = reader.GetOracleClob(0); + Console.WriteLine("New Data: {0}", clob.Value); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + finally + { + // Dispose OracleCommand object + cmd.Dispose(); + + // Close and Dispose OracleConnection object + con.Close(); + con.Dispose(); + } + } + + /// + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("", con); + + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + } +} diff --git a/samples/lob/Sample7.cs b/samples/lob/Sample7.cs index db4febec..16fdf351 100644 --- a/samples/lob/Sample7.cs +++ b/samples/lob/Sample7.cs @@ -15,142 +15,142 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using System.Threading; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample7 -{ - /// - /// Sample7: Demonstrates LOB updates using result set locking. - /// - class Sample7 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup - Setup(con); - - OracleTransaction txn = con.BeginTransaction(); - OracleCommand cmd = new OracleCommand("",con); - - try - { - // Lock the result set using FOR UPDATE clause - cmd.CommandText = "select STORY from multimedia_tab for update"; - - OracleDataReader reader = cmd.ExecuteReader(); - reader.Read(); - OracleClob clob = reader.GetOracleClob(0); - Console.WriteLine("Old Data: {0}", clob.Value); - - // Modify the CLOB column of the row - string ending = " The end."; - clob.Append(ending.ToCharArray(), 0, ending.Length); - - // Release the lock - txn.Commit(); - - // Fetch the new data; transaction or locking not required. - cmd.CommandText = "select STORY from multimedia_tab where THEKEY = 1"; - reader = cmd.ExecuteReader(); - reader.Read(); - clob = reader.GetOracleClob(0); - Console.WriteLine("New Data: {0}", clob.Value); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - finally - { - // Dispose OracleCommand object - cmd.Dispose(); - - // Close and Dispose OracleConnection object - con.Close(); - con.Dispose(); - } - } - - /// - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("", con); - - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using System.Threading; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample7 +{ + /// + /// Sample7: Demonstrates LOB updates using result set locking. + /// + class Sample7 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup + Setup(con); + + OracleTransaction txn = con.BeginTransaction(); + OracleCommand cmd = new OracleCommand("",con); + + try + { + // Lock the result set using FOR UPDATE clause + cmd.CommandText = "select STORY from multimedia_tab for update"; + + OracleDataReader reader = cmd.ExecuteReader(); + reader.Read(); + OracleClob clob = reader.GetOracleClob(0); + Console.WriteLine("Old Data: {0}", clob.Value); + + // Modify the CLOB column of the row + string ending = " The end."; + clob.Append(ending.ToCharArray(), 0, ending.Length); + + // Release the lock + txn.Commit(); + + // Fetch the new data; transaction or locking not required. + cmd.CommandText = "select STORY from multimedia_tab where THEKEY = 1"; + reader = cmd.ExecuteReader(); + reader.Read(); + clob = reader.GetOracleClob(0); + Console.WriteLine("New Data: {0}", clob.Value); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + finally + { + // Dispose OracleCommand object + cmd.Dispose(); + + // Close and Dispose OracleConnection object + con.Close(); + con.Dispose(); + } + } + + /// + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("", con); + + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + } +} diff --git a/samples/lob/sample1.cs b/samples/lob/sample1.cs index 2966279b..a6e9830e 100644 --- a/samples/lob/sample1.cs +++ b/samples/lob/sample1.cs @@ -15,135 +15,135 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample1 -{ - /// - /// Sample 1: Demonstrates how to populate and obtain LOB data - /// from a DataSet. - /// - class Sample1 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup the table & Data - Setup(con); - - // Create the OracleCommand - OracleCommand cmd = new OracleCommand("select story from multimedia_tab"); - cmd.Connection = con; - cmd.CommandType = CommandType.Text; - - // Create the OracleDataAdapter - OracleDataAdapter da = new OracleDataAdapter(cmd); - - // Populate a DataSet - DataSet ds = new DataSet(); - try - { - da.FillSchema(ds, SchemaType.Source, "Media"); - - // Populate the DataSet with LOB data - da.Fill(ds, "Media"); - - // Obtain LOB data from the database and print it out - Console.WriteLine(ds.Tables["Media"].Rows[0]["story"]); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - finally - { - // Dispose OracleCommand object - cmd.Dispose(); - - // Close and Dispose OracleConnection object - con.Close(); - con.Dispose(); - } - } - - /// - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("", con); - - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample1 +{ + /// + /// Sample 1: Demonstrates how to populate and obtain LOB data + /// from a DataSet. + /// + class Sample1 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup the table & Data + Setup(con); + + // Create the OracleCommand + OracleCommand cmd = new OracleCommand("select story from multimedia_tab"); + cmd.Connection = con; + cmd.CommandType = CommandType.Text; + + // Create the OracleDataAdapter + OracleDataAdapter da = new OracleDataAdapter(cmd); + + // Populate a DataSet + DataSet ds = new DataSet(); + try + { + da.FillSchema(ds, SchemaType.Source, "Media"); + + // Populate the DataSet with LOB data + da.Fill(ds, "Media"); + + // Obtain LOB data from the database and print it out + Console.WriteLine(ds.Tables["Media"].Rows[0]["story"]); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + finally + { + // Dispose OracleCommand object + cmd.Dispose(); + + // Close and Dispose OracleConnection object + con.Close(); + con.Dispose(); + } + } + + /// + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("", con); + + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + } +} diff --git a/samples/ref-cursor/Sample3.cs b/samples/ref-cursor/Sample3.cs index efc3bb9f..700fee54 100644 --- a/samples/ref-cursor/Sample3.cs +++ b/samples/ref-cursor/Sample3.cs @@ -15,249 +15,249 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample3 -{ - /// - /// Sample 3: Demonstrates how multiple REF Cursors can be accessed - /// by a single OracleDataReader - /// - class Sample3 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup - Setup(con); - - // Set the command - OracleCommand cmd = new OracleCommand("TEST.Get3Cur", con); - cmd.CommandType = CommandType.StoredProcedure; - - // Bind - // select * from multimedia_tab - OracleParameter p1 = cmd.Parameters.Add("refcursor1", - OracleDbType.RefCursor); - p1.Direction = ParameterDirection.ReturnValue; - - // select * from emp - OracleParameter p2 = cmd.Parameters.Add("refcursor2", - OracleDbType.RefCursor); - p2.Direction = ParameterDirection.Output; - - // select * from dept - OracleParameter p3 = cmd.Parameters.Add("refcursor3", - OracleDbType.RefCursor); - p3.Direction = ParameterDirection.Output; - - // Execute command - OracleDataReader reader; - try - { - reader = cmd.ExecuteReader(); - - // Print out the field count of each REF Cursor - // for "select * from SCOTT.MULTIMEDIA_TAB", - // "select * from SCOTT.EMP", and "select * from DEPT"; - do - { - Console.WriteLine("Field count: " + reader.FieldCount); - } while (reader.NextResult()); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - finally - { - // Dispose OracleCommand object - cmd.Dispose(); - - // Close and Dispose OracleConnection object - con.Close(); - con.Dispose(); - } - } - - /// - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("",con); - - // Create multimedia table - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - // Create Package Header - blr = new StringBuilder(); - blr.Append("CREATE OR REPLACE PACKAGE TEST is "); - blr.Append("TYPE refcursor is ref cursor;"); - blr.Append("FUNCTION Ret1Cur return refCursor;"); - - blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor);"); - - blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor,"); - blr.Append("p_cursor2 out refCursor)"); - blr.Append("return refCursor;"); - - blr.Append("FUNCTION Get1Cur return refCursor;"); - - blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR,"); - blr.Append("clipid in NUMBER);"); - - blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor);"); - - blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,myStory out VARCHAR2);"); - blr.Append("end TEST;"); - - cmd.CommandText = blr.ToString(); - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - // Create Package Body - blr = new StringBuilder(); - - blr.Append("create or replace package body TEST is "); - - blr.Append("FUNCTION Ret1Cur return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("return (p_cursor); "); - blr.Append("END Ret1Cur; "); - - blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor) is "); - blr.Append("BEGIN "); - blr.Append("OPEN p_cursor1 for select * from emp; "); - blr.Append("END Get1CurOut; "); - - blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor, "); - blr.Append("p_cursor2 out refCursor)"); - blr.Append("return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("open p_cursor1 for select * from emp; "); - blr.Append("open p_cursor2 for select * from dept; "); - blr.Append("return (p_cursor); "); - blr.Append("END Get3Cur; "); - - blr.Append("FUNCTION Get1Cur return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("return (p_cursor); "); - blr.Append("END Get1Cur; "); - - blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR, "); - blr.Append("clipid in NUMBER) is "); - blr.Append("BEGIN "); - blr.Append("Update multimedia_tab set story = new_story where thekey = clipid; "); - blr.Append("END UpdateRefCur; "); - - blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor) is "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for "); - blr.Append("Select story from multimedia_tab where thekey = 1; "); - blr.Append("END GetStoryForClip1; "); - - blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,"); - blr.Append("myStory out VARCHAR2) is "); - blr.Append("BEGIN "); - blr.Append("FETCH p_cursor into myStory; "); - blr.Append("END GetRefCurData; "); - - blr.Append("end TEST;"); - - cmd.CommandText = blr.ToString(); - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample3 +{ + /// + /// Sample 3: Demonstrates how multiple REF Cursors can be accessed + /// by a single OracleDataReader + /// + class Sample3 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup + Setup(con); + + // Set the command + OracleCommand cmd = new OracleCommand("TEST.Get3Cur", con); + cmd.CommandType = CommandType.StoredProcedure; + + // Bind + // select * from multimedia_tab + OracleParameter p1 = cmd.Parameters.Add("refcursor1", + OracleDbType.RefCursor); + p1.Direction = ParameterDirection.ReturnValue; + + // select * from emp + OracleParameter p2 = cmd.Parameters.Add("refcursor2", + OracleDbType.RefCursor); + p2.Direction = ParameterDirection.Output; + + // select * from dept + OracleParameter p3 = cmd.Parameters.Add("refcursor3", + OracleDbType.RefCursor); + p3.Direction = ParameterDirection.Output; + + // Execute command + OracleDataReader reader; + try + { + reader = cmd.ExecuteReader(); + + // Print out the field count of each REF Cursor + // for "select * from SCOTT.MULTIMEDIA_TAB", + // "select * from SCOTT.EMP", and "select * from DEPT"; + do + { + Console.WriteLine("Field count: " + reader.FieldCount); + } while (reader.NextResult()); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + finally + { + // Dispose OracleCommand object + cmd.Dispose(); + + // Close and Dispose OracleConnection object + con.Close(); + con.Dispose(); + } + } + + /// + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("",con); + + // Create multimedia table + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + // Create Package Header + blr = new StringBuilder(); + blr.Append("CREATE OR REPLACE PACKAGE TEST is "); + blr.Append("TYPE refcursor is ref cursor;"); + blr.Append("FUNCTION Ret1Cur return refCursor;"); + + blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor);"); + + blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor,"); + blr.Append("p_cursor2 out refCursor)"); + blr.Append("return refCursor;"); + + blr.Append("FUNCTION Get1Cur return refCursor;"); + + blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR,"); + blr.Append("clipid in NUMBER);"); + + blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor);"); + + blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,myStory out VARCHAR2);"); + blr.Append("end TEST;"); + + cmd.CommandText = blr.ToString(); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + // Create Package Body + blr = new StringBuilder(); + + blr.Append("create or replace package body TEST is "); + + blr.Append("FUNCTION Ret1Cur return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("return (p_cursor); "); + blr.Append("END Ret1Cur; "); + + blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor) is "); + blr.Append("BEGIN "); + blr.Append("OPEN p_cursor1 for select * from emp; "); + blr.Append("END Get1CurOut; "); + + blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor, "); + blr.Append("p_cursor2 out refCursor)"); + blr.Append("return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("open p_cursor1 for select * from emp; "); + blr.Append("open p_cursor2 for select * from dept; "); + blr.Append("return (p_cursor); "); + blr.Append("END Get3Cur; "); + + blr.Append("FUNCTION Get1Cur return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("return (p_cursor); "); + blr.Append("END Get1Cur; "); + + blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR, "); + blr.Append("clipid in NUMBER) is "); + blr.Append("BEGIN "); + blr.Append("Update multimedia_tab set story = new_story where thekey = clipid; "); + blr.Append("END UpdateRefCur; "); + + blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor) is "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for "); + blr.Append("Select story from multimedia_tab where thekey = 1; "); + blr.Append("END GetStoryForClip1; "); + + blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,"); + blr.Append("myStory out VARCHAR2) is "); + blr.Append("BEGIN "); + blr.Append("FETCH p_cursor into myStory; "); + blr.Append("END GetRefCurData; "); + + blr.Append("end TEST;"); + + cmd.CommandText = blr.ToString(); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + } +} diff --git a/samples/ref-cursor/Sample4.cs b/samples/ref-cursor/Sample4.cs index a86a74c1..b6c16e59 100644 --- a/samples/ref-cursor/Sample4.cs +++ b/samples/ref-cursor/Sample4.cs @@ -15,263 +15,263 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample4 -{ - /// - /// Sample 4: Demonstrates how a DataSet can be populated from a - /// REF Cursor. The sample also demonstrates how a REF - /// Cursor can be updated. - /// - class Sample4 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup - Setup(con); - - // Set the command - OracleCommand cmd = new OracleCommand("TEST.Ret1Cur", con); - cmd.CommandType = CommandType.StoredProcedure; - - // Bind - // TEST.Ret1Cur is a function so ParameterDirection is ReturnValue. - OracleParameter param = cmd.Parameters.Add("refcursor", - OracleDbType.RefCursor); - param.Direction = ParameterDirection.ReturnValue; - - // Create an OracleDataAdapter - OracleDataAdapter da = new OracleDataAdapter(cmd); - - try - { - // 1. Demostrate populating a DataSet with RefCursor - // Populate a DataSet - DataSet ds = new DataSet(); - da.FillSchema(ds, SchemaType.Source, "myRefCursor"); - da.Fill(ds, "myRefCursor"); - - // Obtain the row which we want to modify - DataRow[] rowsWanted = ds.Tables["myRefCursor"].Select("THEKEY = 1"); - - // 2. Demostrate how to update with RefCursor - // Update the "story" column - rowsWanted[0]["story"] = "New story"; - - // Setup the update command on the DataAdapter - OracleCommand updcmd = new OracleCommand("TEST.UpdateREFCur", con); - updcmd.CommandType = CommandType.StoredProcedure; - - OracleParameter param1 = updcmd.Parameters.Add("myStory", - OracleDbType.Varchar2, 32); - param1.SourceVersion = DataRowVersion.Current; - param1.SourceColumn = "STORY"; - OracleParameter param2 = updcmd.Parameters.Add("myClipId", - OracleDbType.Decimal); - param2.SourceColumn = "THEKEY"; - param2.SourceVersion = DataRowVersion.Original; - - da.UpdateCommand = updcmd; - - // Update - da.Update(ds, "myRefCursor"); - Console.WriteLine("Data has been updated."); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - finally - { - // Dispose OracleCommand object - cmd.Dispose(); - - // Close and Dispose OracleConnection object - con.Close(); - con.Dispose(); - } - } - - /// - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("",con); - - // Create multimedia table - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - // Create Package Header - blr = new StringBuilder(); - blr.Append("CREATE OR REPLACE PACKAGE TEST is "); - blr.Append("TYPE refcursor is ref cursor;"); - blr.Append("FUNCTION Ret1Cur return refCursor;"); - - blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor);"); - - blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor,"); - blr.Append("p_cursor2 out refCursor)"); - blr.Append("return refCursor;"); - - blr.Append("FUNCTION Get1Cur return refCursor;"); - - blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR,"); - blr.Append("clipid in NUMBER);"); - - blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor);"); - - blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,myStory out VARCHAR2);"); - blr.Append("end TEST;"); - - cmd.CommandText = blr.ToString(); - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - // Create Package Body - blr = new StringBuilder(); - - blr.Append("create or replace package body TEST is "); - - blr.Append("FUNCTION Ret1Cur return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("return (p_cursor); "); - blr.Append("END Ret1Cur; "); - - blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor) is "); - blr.Append("BEGIN "); - blr.Append("OPEN p_cursor1 for select * from emp; "); - blr.Append("END Get1CurOut; "); - - blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor, "); - blr.Append("p_cursor2 out refCursor)"); - blr.Append("return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("open p_cursor1 for select * from emp; "); - blr.Append("open p_cursor2 for select * from dept; "); - blr.Append("return (p_cursor); "); - blr.Append("END Get3Cur; "); - - blr.Append("FUNCTION Get1Cur return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("return (p_cursor); "); - blr.Append("END Get1Cur; "); - - blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR, "); - blr.Append("clipid in NUMBER) is "); - blr.Append("BEGIN "); - blr.Append("Update multimedia_tab set story = new_story where thekey = clipid; "); - blr.Append("END UpdateRefCur; "); - - blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor) is "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for "); - blr.Append("Select story from multimedia_tab where thekey = 1; "); - blr.Append("END GetStoryForClip1; "); - - blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,"); - blr.Append("myStory out VARCHAR2) is "); - blr.Append("BEGIN "); - blr.Append("FETCH p_cursor into myStory; "); - blr.Append("END GetRefCurData; "); - - blr.Append("end TEST;"); - - cmd.CommandText = blr.ToString(); - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample4 +{ + /// + /// Sample 4: Demonstrates how a DataSet can be populated from a + /// REF Cursor. The sample also demonstrates how a REF + /// Cursor can be updated. + /// + class Sample4 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup + Setup(con); + + // Set the command + OracleCommand cmd = new OracleCommand("TEST.Ret1Cur", con); + cmd.CommandType = CommandType.StoredProcedure; + + // Bind + // TEST.Ret1Cur is a function so ParameterDirection is ReturnValue. + OracleParameter param = cmd.Parameters.Add("refcursor", + OracleDbType.RefCursor); + param.Direction = ParameterDirection.ReturnValue; + + // Create an OracleDataAdapter + OracleDataAdapter da = new OracleDataAdapter(cmd); + + try + { + // 1. Demostrate populating a DataSet with RefCursor + // Populate a DataSet + DataSet ds = new DataSet(); + da.FillSchema(ds, SchemaType.Source, "myRefCursor"); + da.Fill(ds, "myRefCursor"); + + // Obtain the row which we want to modify + DataRow[] rowsWanted = ds.Tables["myRefCursor"].Select("THEKEY = 1"); + + // 2. Demostrate how to update with RefCursor + // Update the "story" column + rowsWanted[0]["story"] = "New story"; + + // Setup the update command on the DataAdapter + OracleCommand updcmd = new OracleCommand("TEST.UpdateREFCur", con); + updcmd.CommandType = CommandType.StoredProcedure; + + OracleParameter param1 = updcmd.Parameters.Add("myStory", + OracleDbType.Varchar2, 32); + param1.SourceVersion = DataRowVersion.Current; + param1.SourceColumn = "STORY"; + OracleParameter param2 = updcmd.Parameters.Add("myClipId", + OracleDbType.Decimal); + param2.SourceColumn = "THEKEY"; + param2.SourceVersion = DataRowVersion.Original; + + da.UpdateCommand = updcmd; + + // Update + da.Update(ds, "myRefCursor"); + Console.WriteLine("Data has been updated."); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + finally + { + // Dispose OracleCommand object + cmd.Dispose(); + + // Close and Dispose OracleConnection object + con.Close(); + con.Dispose(); + } + } + + /// + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("",con); + + // Create multimedia table + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + // Create Package Header + blr = new StringBuilder(); + blr.Append("CREATE OR REPLACE PACKAGE TEST is "); + blr.Append("TYPE refcursor is ref cursor;"); + blr.Append("FUNCTION Ret1Cur return refCursor;"); + + blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor);"); + + blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor,"); + blr.Append("p_cursor2 out refCursor)"); + blr.Append("return refCursor;"); + + blr.Append("FUNCTION Get1Cur return refCursor;"); + + blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR,"); + blr.Append("clipid in NUMBER);"); + + blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor);"); + + blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,myStory out VARCHAR2);"); + blr.Append("end TEST;"); + + cmd.CommandText = blr.ToString(); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + // Create Package Body + blr = new StringBuilder(); + + blr.Append("create or replace package body TEST is "); + + blr.Append("FUNCTION Ret1Cur return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("return (p_cursor); "); + blr.Append("END Ret1Cur; "); + + blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor) is "); + blr.Append("BEGIN "); + blr.Append("OPEN p_cursor1 for select * from emp; "); + blr.Append("END Get1CurOut; "); + + blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor, "); + blr.Append("p_cursor2 out refCursor)"); + blr.Append("return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("open p_cursor1 for select * from emp; "); + blr.Append("open p_cursor2 for select * from dept; "); + blr.Append("return (p_cursor); "); + blr.Append("END Get3Cur; "); + + blr.Append("FUNCTION Get1Cur return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("return (p_cursor); "); + blr.Append("END Get1Cur; "); + + blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR, "); + blr.Append("clipid in NUMBER) is "); + blr.Append("BEGIN "); + blr.Append("Update multimedia_tab set story = new_story where thekey = clipid; "); + blr.Append("END UpdateRefCur; "); + + blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor) is "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for "); + blr.Append("Select story from multimedia_tab where thekey = 1; "); + blr.Append("END GetStoryForClip1; "); + + blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,"); + blr.Append("myStory out VARCHAR2) is "); + blr.Append("BEGIN "); + blr.Append("FETCH p_cursor into myStory; "); + blr.Append("END GetRefCurData; "); + + blr.Append("end TEST;"); + + cmd.CommandText = blr.ToString(); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + } +} diff --git a/samples/ref-cursor/Sample5.cs b/samples/ref-cursor/Sample5.cs index 09e44ee4..0b3b72cc 100644 --- a/samples/ref-cursor/Sample5.cs +++ b/samples/ref-cursor/Sample5.cs @@ -15,238 +15,238 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample5 -{ - /// - /// Sample 5: Demonstrates how a DataSet can be populated from an - /// OracleRefCursor object. - /// - class Sample5 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup - Setup(con); - - // Set the command - OracleCommand cmd = new OracleCommand("TEST.Get1Cur", con); - cmd.CommandType = CommandType.StoredProcedure; - - // Bind - cmd.Parameters.Add("refcursor1", OracleDbType.RefCursor); - cmd.Parameters[0].Direction = ParameterDirection.ReturnValue; - - try - { - // Execute command; Have the parameters populated - cmd.ExecuteNonQuery(); - - // Create the OracleDataAdapter - OracleDataAdapter da = new OracleDataAdapter(cmd); - - // Populate a DataSet with refcursor1. - DataSet ds = new DataSet(); - da.Fill(ds, "refcursor1", (OracleRefCursor)(cmd.Parameters["refcursor1"].Value)); - - // Print out the field count the REF Cursor - Console.WriteLine("Field count: " + ds.Tables["refcursor1"].Columns.Count); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - finally - { - // Dispose OracleCommand object - cmd.Dispose(); - - // Close and Dispose OracleConnection object - con.Close(); - con.Dispose(); - } - } - - /// - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("",con); - - // Create multimedia table - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - // Create Package Header - blr = new StringBuilder(); - blr.Append("CREATE OR REPLACE PACKAGE TEST is "); - blr.Append("TYPE refcursor is ref cursor;"); - blr.Append("FUNCTION Ret1Cur return refCursor;"); - - blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor);"); - - blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor,"); - blr.Append("p_cursor2 out refCursor)"); - blr.Append("return refCursor;"); - - blr.Append("FUNCTION Get1Cur return refCursor;"); - - blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR,"); - blr.Append("clipid in NUMBER);"); - - blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor);"); - - blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,myStory out VARCHAR2);"); - blr.Append("end TEST;"); - - cmd.CommandText = blr.ToString(); - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - // Create Package Body - blr = new StringBuilder(); - - blr.Append("create or replace package body TEST is "); - - blr.Append("FUNCTION Ret1Cur return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("return (p_cursor); "); - blr.Append("END Ret1Cur; "); - - blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor) is "); - blr.Append("BEGIN "); - blr.Append("OPEN p_cursor1 for select * from emp; "); - blr.Append("END Get1CurOut; "); - - blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor, "); - blr.Append("p_cursor2 out refCursor)"); - blr.Append("return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("open p_cursor1 for select * from emp; "); - blr.Append("open p_cursor2 for select * from dept; "); - blr.Append("return (p_cursor); "); - blr.Append("END Get3Cur; "); - - blr.Append("FUNCTION Get1Cur return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("return (p_cursor); "); - blr.Append("END Get1Cur; "); - - blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR, "); - blr.Append("clipid in NUMBER) is "); - blr.Append("BEGIN "); - blr.Append("Update multimedia_tab set story = new_story where thekey = clipid; "); - blr.Append("END UpdateRefCur; "); - - blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor) is "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for "); - blr.Append("Select story from multimedia_tab where thekey = 1; "); - blr.Append("END GetStoryForClip1; "); - - blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,"); - blr.Append("myStory out VARCHAR2) is "); - blr.Append("BEGIN "); - blr.Append("FETCH p_cursor into myStory; "); - blr.Append("END GetRefCurData; "); - - blr.Append("end TEST;"); - - cmd.CommandText = blr.ToString(); - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample5 +{ + /// + /// Sample 5: Demonstrates how a DataSet can be populated from an + /// OracleRefCursor object. + /// + class Sample5 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup + Setup(con); + + // Set the command + OracleCommand cmd = new OracleCommand("TEST.Get1Cur", con); + cmd.CommandType = CommandType.StoredProcedure; + + // Bind + cmd.Parameters.Add("refcursor1", OracleDbType.RefCursor); + cmd.Parameters[0].Direction = ParameterDirection.ReturnValue; + + try + { + // Execute command; Have the parameters populated + cmd.ExecuteNonQuery(); + + // Create the OracleDataAdapter + OracleDataAdapter da = new OracleDataAdapter(cmd); + + // Populate a DataSet with refcursor1. + DataSet ds = new DataSet(); + da.Fill(ds, "refcursor1", (OracleRefCursor)(cmd.Parameters["refcursor1"].Value)); + + // Print out the field count the REF Cursor + Console.WriteLine("Field count: " + ds.Tables["refcursor1"].Columns.Count); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + finally + { + // Dispose OracleCommand object + cmd.Dispose(); + + // Close and Dispose OracleConnection object + con.Close(); + con.Dispose(); + } + } + + /// + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("",con); + + // Create multimedia table + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + // Create Package Header + blr = new StringBuilder(); + blr.Append("CREATE OR REPLACE PACKAGE TEST is "); + blr.Append("TYPE refcursor is ref cursor;"); + blr.Append("FUNCTION Ret1Cur return refCursor;"); + + blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor);"); + + blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor,"); + blr.Append("p_cursor2 out refCursor)"); + blr.Append("return refCursor;"); + + blr.Append("FUNCTION Get1Cur return refCursor;"); + + blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR,"); + blr.Append("clipid in NUMBER);"); + + blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor);"); + + blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,myStory out VARCHAR2);"); + blr.Append("end TEST;"); + + cmd.CommandText = blr.ToString(); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + // Create Package Body + blr = new StringBuilder(); + + blr.Append("create or replace package body TEST is "); + + blr.Append("FUNCTION Ret1Cur return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("return (p_cursor); "); + blr.Append("END Ret1Cur; "); + + blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor) is "); + blr.Append("BEGIN "); + blr.Append("OPEN p_cursor1 for select * from emp; "); + blr.Append("END Get1CurOut; "); + + blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor, "); + blr.Append("p_cursor2 out refCursor)"); + blr.Append("return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("open p_cursor1 for select * from emp; "); + blr.Append("open p_cursor2 for select * from dept; "); + blr.Append("return (p_cursor); "); + blr.Append("END Get3Cur; "); + + blr.Append("FUNCTION Get1Cur return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("return (p_cursor); "); + blr.Append("END Get1Cur; "); + + blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR, "); + blr.Append("clipid in NUMBER) is "); + blr.Append("BEGIN "); + blr.Append("Update multimedia_tab set story = new_story where thekey = clipid; "); + blr.Append("END UpdateRefCur; "); + + blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor) is "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for "); + blr.Append("Select story from multimedia_tab where thekey = 1; "); + blr.Append("END GetStoryForClip1; "); + + blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,"); + blr.Append("myStory out VARCHAR2) is "); + blr.Append("BEGIN "); + blr.Append("FETCH p_cursor into myStory; "); + blr.Append("END GetRefCurData; "); + + blr.Append("end TEST;"); + + cmd.CommandText = blr.ToString(); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + } +} diff --git a/samples/ref-cursor/Sample6.cs b/samples/ref-cursor/Sample6.cs index 2d32e490..6c69a2e5 100644 --- a/samples/ref-cursor/Sample6.cs +++ b/samples/ref-cursor/Sample6.cs @@ -15,282 +15,282 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample6 -{ - /// - /// Sample 6: Demonstrates how to populate a DataSet with - /// multiple REF Cursors selectively - /// - class Sample6 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup - Setup(con); - - // Get 3 RefCursors - OracleCommand cmd = new OracleCommand("TEST.Get3Cur", con); - cmd.CommandType = CommandType.StoredProcedure; - - OracleRefCursor[] refCursors = Get3RefCursors(cmd); - - try - { - // Create 2 DataTable in a DataSet - DataSet ds = new DataSet(); - ds.Tables.Add(new DataTable("refcur0")); - ds.Tables.Add(new DataTable("refcur2")); - - // Use Adapter.Fill to populate the DataTable using - // only two of the three OracleRefCursor objects - OracleDataAdapter adpt = new OracleDataAdapter(); - adpt.Fill(ds.Tables["refcur0"], refCursors[0]); - adpt.Fill(ds.Tables["refcur2"], refCursors[2]); - - // Display the Row count of each DataTable - Console.WriteLine("Row Count:{0}", ds.Tables["refcur0"].Rows.Count); - Console.WriteLine("Row Count:{0}", ds.Tables["refcur2"].Rows.Count); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - finally - { - // Dispose OracleCommand object - cmd.Dispose(); - - // Close and Dispose OracleConnection object - con.Close(); - con.Dispose(); - } - } - - /// - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("",con); - - // Create multimedia table - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - // Create Package Header - blr = new StringBuilder(); - blr.Append("CREATE OR REPLACE PACKAGE TEST is "); - blr.Append("TYPE refcursor is ref cursor;"); - blr.Append("FUNCTION Ret1Cur return refCursor;"); - - blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor);"); - - blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor,"); - blr.Append("p_cursor2 out refCursor)"); - blr.Append("return refCursor;"); - - blr.Append("FUNCTION Get1Cur return refCursor;"); - - blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR,"); - blr.Append("clipid in NUMBER);"); - - blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor);"); - - blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,myStory out VARCHAR2);"); - blr.Append("end TEST;"); - - cmd.CommandText = blr.ToString(); - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - // Create Package Body - blr = new StringBuilder(); - - blr.Append("create or replace package body TEST is "); - - blr.Append("FUNCTION Ret1Cur return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("return (p_cursor); "); - blr.Append("END Ret1Cur; "); - - blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor) is "); - blr.Append("BEGIN "); - blr.Append("OPEN p_cursor1 for select * from emp; "); - blr.Append("END Get1CurOut; "); - - blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor, "); - blr.Append("p_cursor2 out refCursor)"); - blr.Append("return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("open p_cursor1 for select * from emp; "); - blr.Append("open p_cursor2 for select * from dept; "); - blr.Append("return (p_cursor); "); - blr.Append("END Get3Cur; "); - - blr.Append("FUNCTION Get1Cur return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("return (p_cursor); "); - blr.Append("END Get1Cur; "); - - blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR, "); - blr.Append("clipid in NUMBER) is "); - blr.Append("BEGIN "); - blr.Append("Update multimedia_tab set story = new_story where thekey = clipid; "); - blr.Append("END UpdateRefCur; "); - - blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor) is "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for "); - blr.Append("Select story from multimedia_tab where thekey = 1; "); - blr.Append("END GetStoryForClip1; "); - - blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,"); - blr.Append("myStory out VARCHAR2) is "); - blr.Append("BEGIN "); - blr.Append("FETCH p_cursor into myStory; "); - blr.Append("END GetRefCurData; "); - - blr.Append("end TEST;"); - - cmd.CommandText = blr.ToString(); - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - - /// - /// Get 3 Ref Cursors with a PL/SQL - /// - /// - /// - public static OracleRefCursor[] Get3RefCursors(OracleCommand cmd) - { - // 1. Get 3 OracleParameters as REF CURSORs - // Set the command - - - // Bind - // select * from multimedia_tab - OracleParameter p1 = cmd.Parameters.Add("refcursor1", - OracleDbType.RefCursor); - p1.Direction = ParameterDirection.ReturnValue; - - // select * from emp - OracleParameter p2 = cmd.Parameters.Add("refcursor2", - OracleDbType.RefCursor); - p2.Direction = ParameterDirection.Output; - - // select * from dept - OracleParameter p3 = cmd.Parameters.Add("refcursor3", - OracleDbType.RefCursor); - p3.Direction = ParameterDirection.Output; - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - OracleRefCursor[] refCursors = new OracleRefCursor[3]; - refCursors[0] = (OracleRefCursor)p1.Value; - refCursors[1] = (OracleRefCursor)p2.Value; - refCursors[2] = (OracleRefCursor)p3.Value; - - return refCursors; - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample6 +{ + /// + /// Sample 6: Demonstrates how to populate a DataSet with + /// multiple REF Cursors selectively + /// + class Sample6 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup + Setup(con); + + // Get 3 RefCursors + OracleCommand cmd = new OracleCommand("TEST.Get3Cur", con); + cmd.CommandType = CommandType.StoredProcedure; + + OracleRefCursor[] refCursors = Get3RefCursors(cmd); + + try + { + // Create 2 DataTable in a DataSet + DataSet ds = new DataSet(); + ds.Tables.Add(new DataTable("refcur0")); + ds.Tables.Add(new DataTable("refcur2")); + + // Use Adapter.Fill to populate the DataTable using + // only two of the three OracleRefCursor objects + OracleDataAdapter adpt = new OracleDataAdapter(); + adpt.Fill(ds.Tables["refcur0"], refCursors[0]); + adpt.Fill(ds.Tables["refcur2"], refCursors[2]); + + // Display the Row count of each DataTable + Console.WriteLine("Row Count:{0}", ds.Tables["refcur0"].Rows.Count); + Console.WriteLine("Row Count:{0}", ds.Tables["refcur2"].Rows.Count); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + finally + { + // Dispose OracleCommand object + cmd.Dispose(); + + // Close and Dispose OracleConnection object + con.Close(); + con.Dispose(); + } + } + + /// + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("",con); + + // Create multimedia table + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + // Create Package Header + blr = new StringBuilder(); + blr.Append("CREATE OR REPLACE PACKAGE TEST is "); + blr.Append("TYPE refcursor is ref cursor;"); + blr.Append("FUNCTION Ret1Cur return refCursor;"); + + blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor);"); + + blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor,"); + blr.Append("p_cursor2 out refCursor)"); + blr.Append("return refCursor;"); + + blr.Append("FUNCTION Get1Cur return refCursor;"); + + blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR,"); + blr.Append("clipid in NUMBER);"); + + blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor);"); + + blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,myStory out VARCHAR2);"); + blr.Append("end TEST;"); + + cmd.CommandText = blr.ToString(); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + // Create Package Body + blr = new StringBuilder(); + + blr.Append("create or replace package body TEST is "); + + blr.Append("FUNCTION Ret1Cur return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("return (p_cursor); "); + blr.Append("END Ret1Cur; "); + + blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor) is "); + blr.Append("BEGIN "); + blr.Append("OPEN p_cursor1 for select * from emp; "); + blr.Append("END Get1CurOut; "); + + blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor, "); + blr.Append("p_cursor2 out refCursor)"); + blr.Append("return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("open p_cursor1 for select * from emp; "); + blr.Append("open p_cursor2 for select * from dept; "); + blr.Append("return (p_cursor); "); + blr.Append("END Get3Cur; "); + + blr.Append("FUNCTION Get1Cur return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("return (p_cursor); "); + blr.Append("END Get1Cur; "); + + blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR, "); + blr.Append("clipid in NUMBER) is "); + blr.Append("BEGIN "); + blr.Append("Update multimedia_tab set story = new_story where thekey = clipid; "); + blr.Append("END UpdateRefCur; "); + + blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor) is "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for "); + blr.Append("Select story from multimedia_tab where thekey = 1; "); + blr.Append("END GetStoryForClip1; "); + + blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,"); + blr.Append("myStory out VARCHAR2) is "); + blr.Append("BEGIN "); + blr.Append("FETCH p_cursor into myStory; "); + blr.Append("END GetRefCurData; "); + + blr.Append("end TEST;"); + + cmd.CommandText = blr.ToString(); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + + /// + /// Get 3 Ref Cursors with a PL/SQL + /// + /// + /// + public static OracleRefCursor[] Get3RefCursors(OracleCommand cmd) + { + // 1. Get 3 OracleParameters as REF CURSORs + // Set the command + + + // Bind + // select * from multimedia_tab + OracleParameter p1 = cmd.Parameters.Add("refcursor1", + OracleDbType.RefCursor); + p1.Direction = ParameterDirection.ReturnValue; + + // select * from emp + OracleParameter p2 = cmd.Parameters.Add("refcursor2", + OracleDbType.RefCursor); + p2.Direction = ParameterDirection.Output; + + // select * from dept + OracleParameter p3 = cmd.Parameters.Add("refcursor3", + OracleDbType.RefCursor); + p3.Direction = ParameterDirection.Output; + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + OracleRefCursor[] refCursors = new OracleRefCursor[3]; + refCursors[0] = (OracleRefCursor)p1.Value; + refCursors[1] = (OracleRefCursor)p2.Value; + refCursors[2] = (OracleRefCursor)p3.Value; + + return refCursors; + } + } +} diff --git a/samples/ref-cursor/Sample7.cs b/samples/ref-cursor/Sample7.cs index ad024b42..460cd2d2 100644 --- a/samples/ref-cursor/Sample7.cs +++ b/samples/ref-cursor/Sample7.cs @@ -15,281 +15,281 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample7 -{ - /// - /// Sample 7: Demonstrates how to selectively obtain - /// OracleDataReader objects from the REF Cursors - /// - class Sample7 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup - Setup(con); - - // Get 3 RefCursors - OracleCommand cmd = new OracleCommand("TEST.Get3Cur", con); - cmd.CommandType = CommandType.StoredProcedure; - - OracleRefCursor[] refCursors = Get3RefCursors(cmd); - - try - { - // Obtain an OracleDataReader for the RefCursors except - // for the first one. - for(int i=1; i - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("",con); - - // Create multimedia table - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - // Create Package Header - blr = new StringBuilder(); - blr.Append("CREATE OR REPLACE PACKAGE TEST is "); - blr.Append("TYPE refcursor is ref cursor;"); - blr.Append("FUNCTION Ret1Cur return refCursor;"); - - blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor);"); - - blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor,"); - blr.Append("p_cursor2 out refCursor)"); - blr.Append("return refCursor;"); - - blr.Append("FUNCTION Get1Cur return refCursor;"); - - blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR,"); - blr.Append("clipid in NUMBER);"); - - blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor);"); - - blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,myStory out VARCHAR2);"); - blr.Append("end TEST;"); - - cmd.CommandText = blr.ToString(); - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - // Create Package Body - blr = new StringBuilder(); - - blr.Append("create or replace package body TEST is "); - - blr.Append("FUNCTION Ret1Cur return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("return (p_cursor); "); - blr.Append("END Ret1Cur; "); - - blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor) is "); - blr.Append("BEGIN "); - blr.Append("OPEN p_cursor1 for select * from emp; "); - blr.Append("END Get1CurOut; "); - - blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor, "); - blr.Append("p_cursor2 out refCursor)"); - blr.Append("return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("open p_cursor1 for select * from emp; "); - blr.Append("open p_cursor2 for select * from dept; "); - blr.Append("return (p_cursor); "); - blr.Append("END Get3Cur; "); - - blr.Append("FUNCTION Get1Cur return refCursor is "); - blr.Append("p_cursor refCursor; "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for select * from multimedia_tab; "); - blr.Append("return (p_cursor); "); - blr.Append("END Get1Cur; "); - - blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR, "); - blr.Append("clipid in NUMBER) is "); - blr.Append("BEGIN "); - blr.Append("Update multimedia_tab set story = new_story where thekey = clipid; "); - blr.Append("END UpdateRefCur; "); - - blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor) is "); - blr.Append("BEGIN "); - blr.Append("open p_cursor for "); - blr.Append("Select story from multimedia_tab where thekey = 1; "); - blr.Append("END GetStoryForClip1; "); - - blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,"); - blr.Append("myStory out VARCHAR2) is "); - blr.Append("BEGIN "); - blr.Append("FETCH p_cursor into myStory; "); - blr.Append("END GetRefCurData; "); - - blr.Append("end TEST;"); - - cmd.CommandText = blr.ToString(); - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - - /// - /// Get 3 Ref Cursors with a PL/SQL - /// - /// - /// - public static OracleRefCursor[] Get3RefCursors(OracleCommand cmd) - { - // 1. Get 3 OracleParameters as REF CURSORs - // Set the command - - - // Bind - // select * from multimedia_tab - OracleParameter p1 = cmd.Parameters.Add("refcursor1", - OracleDbType.RefCursor); - p1.Direction = ParameterDirection.ReturnValue; - - // select * from emp - OracleParameter p2 = cmd.Parameters.Add("refcursor2", - OracleDbType.RefCursor); - p2.Direction = ParameterDirection.Output; - - // select * from dept - OracleParameter p3 = cmd.Parameters.Add("refcursor3", - OracleDbType.RefCursor); - p3.Direction = ParameterDirection.Output; - - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - OracleRefCursor[] refCursors = new OracleRefCursor[3]; - refCursors[0] = (OracleRefCursor)p1.Value; - refCursors[1] = (OracleRefCursor)p2.Value; - refCursors[2] = (OracleRefCursor)p3.Value; - - return refCursors; - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample7 +{ + /// + /// Sample 7: Demonstrates how to selectively obtain + /// OracleDataReader objects from the REF Cursors + /// + class Sample7 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup + Setup(con); + + // Get 3 RefCursors + OracleCommand cmd = new OracleCommand("TEST.Get3Cur", con); + cmd.CommandType = CommandType.StoredProcedure; + + OracleRefCursor[] refCursors = Get3RefCursors(cmd); + + try + { + // Obtain an OracleDataReader for the RefCursors except + // for the first one. + for(int i=1; i + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("",con); + + // Create multimedia table + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + // Create Package Header + blr = new StringBuilder(); + blr.Append("CREATE OR REPLACE PACKAGE TEST is "); + blr.Append("TYPE refcursor is ref cursor;"); + blr.Append("FUNCTION Ret1Cur return refCursor;"); + + blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor);"); + + blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor,"); + blr.Append("p_cursor2 out refCursor)"); + blr.Append("return refCursor;"); + + blr.Append("FUNCTION Get1Cur return refCursor;"); + + blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR,"); + blr.Append("clipid in NUMBER);"); + + blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor);"); + + blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,myStory out VARCHAR2);"); + blr.Append("end TEST;"); + + cmd.CommandText = blr.ToString(); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + // Create Package Body + blr = new StringBuilder(); + + blr.Append("create or replace package body TEST is "); + + blr.Append("FUNCTION Ret1Cur return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("return (p_cursor); "); + blr.Append("END Ret1Cur; "); + + blr.Append("PROCEDURE Get1CurOut(p_cursor1 out refCursor) is "); + blr.Append("BEGIN "); + blr.Append("OPEN p_cursor1 for select * from emp; "); + blr.Append("END Get1CurOut; "); + + blr.Append("FUNCTION Get3Cur (p_cursor1 out refCursor, "); + blr.Append("p_cursor2 out refCursor)"); + blr.Append("return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("open p_cursor1 for select * from emp; "); + blr.Append("open p_cursor2 for select * from dept; "); + blr.Append("return (p_cursor); "); + blr.Append("END Get3Cur; "); + + blr.Append("FUNCTION Get1Cur return refCursor is "); + blr.Append("p_cursor refCursor; "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for select * from multimedia_tab; "); + blr.Append("return (p_cursor); "); + blr.Append("END Get1Cur; "); + + blr.Append("PROCEDURE UpdateRefCur(new_story in VARCHAR, "); + blr.Append("clipid in NUMBER) is "); + blr.Append("BEGIN "); + blr.Append("Update multimedia_tab set story = new_story where thekey = clipid; "); + blr.Append("END UpdateRefCur; "); + + blr.Append("PROCEDURE GetStoryForClip1(p_cursor out refCursor) is "); + blr.Append("BEGIN "); + blr.Append("open p_cursor for "); + blr.Append("Select story from multimedia_tab where thekey = 1; "); + blr.Append("END GetStoryForClip1; "); + + blr.Append("PROCEDURE GetRefCurData (p_cursor out refCursor,"); + blr.Append("myStory out VARCHAR2) is "); + blr.Append("BEGIN "); + blr.Append("FETCH p_cursor into myStory; "); + blr.Append("END GetRefCurData; "); + + blr.Append("end TEST;"); + + cmd.CommandText = blr.ToString(); + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + + /// + /// Get 3 Ref Cursors with a PL/SQL + /// + /// + /// + public static OracleRefCursor[] Get3RefCursors(OracleCommand cmd) + { + // 1. Get 3 OracleParameters as REF CURSORs + // Set the command + + + // Bind + // select * from multimedia_tab + OracleParameter p1 = cmd.Parameters.Add("refcursor1", + OracleDbType.RefCursor); + p1.Direction = ParameterDirection.ReturnValue; + + // select * from emp + OracleParameter p2 = cmd.Parameters.Add("refcursor2", + OracleDbType.RefCursor); + p2.Direction = ParameterDirection.Output; + + // select * from dept + OracleParameter p3 = cmd.Parameters.Add("refcursor3", + OracleDbType.RefCursor); + p3.Direction = ParameterDirection.Output; + + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + OracleRefCursor[] refCursors = new OracleRefCursor[3]; + refCursors[0] = (OracleRefCursor)p1.Value; + refCursors[1] = (OracleRefCursor)p2.Value; + refCursors[2] = (OracleRefCursor)p3.Value; + + return refCursors; + } + } +} diff --git a/samples/ref-cursor/sample1.cs b/samples/ref-cursor/sample1.cs index a7181d37..7f4de580 100644 --- a/samples/ref-cursor/sample1.cs +++ b/samples/ref-cursor/sample1.cs @@ -35,7 +35,7 @@ class Sample1 /// static void Main(string[] args) { - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; + string constr = "User Id=scott;Password=;Data Source=oracle"; // Connect OracleConnection con = Connect(constr); diff --git a/samples/ref-cursor/sample2.cs b/samples/ref-cursor/sample2.cs index 6f5906e2..0ff65e4c 100644 --- a/samples/ref-cursor/sample2.cs +++ b/samples/ref-cursor/sample2.cs @@ -15,146 +15,146 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using System.Data; -using System.Text; -using Oracle.ManagedDataAccess.Client; -using Oracle.ManagedDataAccess.Types; - -namespace Sample2 -{ - /// - /// Sample 2: Demonstrates how a REF Cursor is obtained as an - /// OracleDataReader through the use of an OracleRefCursor object. - /// - class Sample2 - { - /// - /// The main entry point for the application. - /// - static void Main(string[] args) - { - // Connect - string constr = "User Id=scott;Password=tiger;Data Source=oracle"; - OracleConnection con = Connect(constr); - - // Setup - Setup(con); - - // Set the command - OracleCommand cmd = new OracleCommand( - "begin open :1 for select * from multimedia_tab where thekey = 1; end;", - con); - - cmd.CommandType = CommandType.Text; - - // Bind - OracleParameter oparam = cmd.Parameters.Add("refcur", OracleDbType.RefCursor); - oparam.Direction = ParameterDirection.Output; - - try - { - // Execute command - cmd.ExecuteNonQuery(); - - // Obtain the OracleDataReader from the REF Cursor parameter - // oparam.Value returns an OracleRefCursor object. - // GetDataReader is a method of OracleRefCursor that returns an OracleDataReader object. - OracleDataReader reader = (OracleDataReader)((OracleRefCursor)(oparam.Value)).GetDataReader(); - - // show the first row - reader.Read(); - - // Print out SCOTT.MULTIMEDIA_TAB THEKEY column - Console.WriteLine("THEKEY: {0}", reader.GetDecimal(0)); - - // Print out SCOTT.MULTIMEDIA_TAB STORY column - Console.WriteLine("STORY : {0}", reader.GetString(1)); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - finally - { - // Dispose OracleCommand object - cmd.Dispose(); - - // Close and Dispose OracleConnection object - con.Close(); - con.Dispose(); - } - } - - /// - /// Wrapper for Opening a new Connection - /// - /// - /// - public static OracleConnection Connect(string connectStr) - { - OracleConnection con = new OracleConnection(connectStr); - try - { - con.Open(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - return con; - } - - /// - /// Setup the necessary Tables & Test Data - /// - /// - public static void Setup(OracleConnection con) - { - StringBuilder blr; - OracleCommand cmd = new OracleCommand("",con); - - // Create multimedia table - blr = new StringBuilder(); - blr.Append("DROP TABLE multimedia_tab"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch - { - } - - blr = new StringBuilder(); - blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); - blr.Append("story CLOB, sound BLOB)"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - - blr = new StringBuilder(); - blr.Append("INSERT INTO multimedia_tab values("); - blr.Append("1,"); - blr.Append("'This is a long story. Once upon a time ...',"); - blr.Append("'656667686970717273747576777879808182838485')"); - cmd.CommandText = blr.ToString(); - try - { - cmd.ExecuteNonQuery(); - } - catch (Exception e) - { - Console.WriteLine("Error: {0}", e.Message); - } - } - } -} + *****************************************************************************/ + +using System; +using System.Data; +using System.Text; +using Oracle.ManagedDataAccess.Client; +using Oracle.ManagedDataAccess.Types; + +namespace Sample2 +{ + /// + /// Sample 2: Demonstrates how a REF Cursor is obtained as an + /// OracleDataReader through the use of an OracleRefCursor object. + /// + class Sample2 + { + /// + /// The main entry point for the application. + /// + static void Main(string[] args) + { + // Connect + string constr = "User Id=scott;Password=;Data Source=oracle"; + OracleConnection con = Connect(constr); + + // Setup + Setup(con); + + // Set the command + OracleCommand cmd = new OracleCommand( + "begin open :1 for select * from multimedia_tab where thekey = 1; end;", + con); + + cmd.CommandType = CommandType.Text; + + // Bind + OracleParameter oparam = cmd.Parameters.Add("refcur", OracleDbType.RefCursor); + oparam.Direction = ParameterDirection.Output; + + try + { + // Execute command + cmd.ExecuteNonQuery(); + + // Obtain the OracleDataReader from the REF Cursor parameter + // oparam.Value returns an OracleRefCursor object. + // GetDataReader is a method of OracleRefCursor that returns an OracleDataReader object. + OracleDataReader reader = (OracleDataReader)((OracleRefCursor)(oparam.Value)).GetDataReader(); + + // show the first row + reader.Read(); + + // Print out SCOTT.MULTIMEDIA_TAB THEKEY column + Console.WriteLine("THEKEY: {0}", reader.GetDecimal(0)); + + // Print out SCOTT.MULTIMEDIA_TAB STORY column + Console.WriteLine("STORY : {0}", reader.GetString(1)); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + finally + { + // Dispose OracleCommand object + cmd.Dispose(); + + // Close and Dispose OracleConnection object + con.Close(); + con.Dispose(); + } + } + + /// + /// Wrapper for Opening a new Connection + /// + /// + /// + public static OracleConnection Connect(string connectStr) + { + OracleConnection con = new OracleConnection(connectStr); + try + { + con.Open(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + return con; + } + + /// + /// Setup the necessary Tables & Test Data + /// + /// + public static void Setup(OracleConnection con) + { + StringBuilder blr; + OracleCommand cmd = new OracleCommand("",con); + + // Create multimedia table + blr = new StringBuilder(); + blr.Append("DROP TABLE multimedia_tab"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch + { + } + + blr = new StringBuilder(); + blr.Append("CREATE TABLE multimedia_tab(thekey NUMBER(4) PRIMARY KEY,"); + blr.Append("story CLOB, sound BLOB)"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + + blr = new StringBuilder(); + blr.Append("INSERT INTO multimedia_tab values("); + blr.Append("1,"); + blr.Append("'This is a long story. Once upon a time ...',"); + blr.Append("'656667686970717273747576777879808182838485')"); + cmd.CommandText = blr.ToString(); + try + { + cmd.ExecuteNonQuery(); + } + catch (Exception e) + { + Console.WriteLine("Error: {0}", e.Message); + } + } + } +} diff --git a/samples/statement-cache/StatementCache.cs b/samples/statement-cache/StatementCache.cs index e5b328d2..32ea19be 100644 --- a/samples/statement-cache/StatementCache.cs +++ b/samples/statement-cache/StatementCache.cs @@ -38,7 +38,7 @@ static void Main(string[] args) { // Connection String with Statement Caching not enabled - string constr = "User Id=scott;Password=tiger;Data Source=oracle;Statement Cache Size=0;Self Tuning=false"; + string constr = "User Id=scott;Password=;Data Source=oracle;Statement Cache Size=0;Self Tuning=false"; Console.WriteLine("Executing 5 Statements 1000 times each, please wait... "); @@ -53,7 +53,7 @@ static void Main(string[] args) // Hence cache size should be chosen depending on the number of statements // that the application repeatedly executes // Cache size should not exceed the size of OPEN_CURSORS as defined in init.ora - constr = "User Id=scott;Password=tiger;Data Source=oracle;Statement Cache Size=5;Self Tuning=false"; + constr = "User Id=scott;Password=;Data Source=oracle;Statement Cache Size=5;Self Tuning=false"; // Execute some statements with caching enabled and retrieve the time taken double totalSecCachingOn = StatementCache.MeasurePerformance(constr); diff --git a/samples/transaction/enlist/psfEnlistTransaction.cs b/samples/transaction/enlist/psfEnlistTransaction.cs index 14e19886..6a02efc7 100644 --- a/samples/transaction/enlist/psfEnlistTransaction.cs +++ b/samples/transaction/enlist/psfEnlistTransaction.cs @@ -15,62 +15,62 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using Oracle.ManagedDataAccess.Client; -using System.Data; -using System.Data.Common; -using System.Transactions; - -class psfEnlistTransaction -{ - static void Main() - { - int retVal = 0; - string providerName = "Oracle.ManagedDataAccess.Client"; - string constr = - @"User Id=scott;Password=tiger;Data Source=oracle;enlist=dynamic"; - - // Get the provider factory. - DbProviderFactory factory = DbProviderFactories.GetFactory(providerName); - - try - { - // Create a committable transaction object. - CommittableTransaction cmtTx = new CommittableTransaction(); - - // Open a connection to the DB. - DbConnection conn1 = factory.CreateConnection(); - conn1.ConnectionString = constr; - conn1.Open(); - - // enlist the connection with the commitable transaction. - conn1.EnlistTransaction(cmtTx); - - // Create a command to execute the sql statement. - DbCommand cmd1 = factory.CreateCommand(); - cmd1.Connection = conn1; - cmd1.CommandText = @"insert into dept (deptno, dname, loc) - values (99, 'st', 'lex')"; - - // Execute the SQL statement to insert one row in DB. - retVal = cmd1.ExecuteNonQuery(); - Console.WriteLine("Rows to be affected by cmd1: {0}", retVal); - - // commit/rollback the transaction. - cmtTx.Commit(); // commits the txn. - //cmtTx.Rollback(); // rolls back the txn. - - // close and dispose the connection - conn1.Close(); - conn1.Dispose(); - cmd1.Dispose(); - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - Console.WriteLine(ex.StackTrace); - } - } -} + *****************************************************************************/ + +using System; +using Oracle.ManagedDataAccess.Client; +using System.Data; +using System.Data.Common; +using System.Transactions; + +class psfEnlistTransaction +{ + static void Main() + { + int retVal = 0; + string providerName = "Oracle.ManagedDataAccess.Client"; + string constr = + @"User Id=scott;Password=;Data Source=oracle;enlist=dynamic"; + + // Get the provider factory. + DbProviderFactory factory = DbProviderFactories.GetFactory(providerName); + + try + { + // Create a committable transaction object. + CommittableTransaction cmtTx = new CommittableTransaction(); + + // Open a connection to the DB. + DbConnection conn1 = factory.CreateConnection(); + conn1.ConnectionString = constr; + conn1.Open(); + + // enlist the connection with the commitable transaction. + conn1.EnlistTransaction(cmtTx); + + // Create a command to execute the sql statement. + DbCommand cmd1 = factory.CreateCommand(); + cmd1.Connection = conn1; + cmd1.CommandText = @"insert into dept (deptno, dname, loc) + values (99, 'st', 'lex')"; + + // Execute the SQL statement to insert one row in DB. + retVal = cmd1.ExecuteNonQuery(); + Console.WriteLine("Rows to be affected by cmd1: {0}", retVal); + + // commit/rollback the transaction. + cmtTx.Commit(); // commits the txn. + //cmtTx.Rollback(); // rolls back the txn. + + // close and dispose the connection + conn1.Close(); + conn1.Dispose(); + cmd1.Dispose(); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + Console.WriteLine(ex.StackTrace); + } + } +} diff --git a/samples/transaction/transaction-scope/psfTxnScope.cs b/samples/transaction/transaction-scope/psfTxnScope.cs index 49ae352d..4401a49d 100644 --- a/samples/transaction/transaction-scope/psfTxnScope.cs +++ b/samples/transaction/transaction-scope/psfTxnScope.cs @@ -15,66 +15,66 @@ * See the License for the specific language governing permissions and * limitations under the License. * - *****************************************************************************/ - -using System; -using Oracle.ManagedDataAccess.Client; -using System.Data; -using System.Data.Common; -using System.Transactions; - -class psfTxnScope -{ - static void Main() - { - int retVal = 0; - string providerName = "Oracle.ManagedDataAccess.Client"; - string constr = - @"User Id=scott;Password=tiger;Data Source=oracle;"; - - // Get the provider factory. - DbProviderFactory factory = DbProviderFactories.GetFactory(providerName); - - try - { - // Create a TransactionScope object, (It will start an ambient - // transaction automatically). - using (TransactionScope scope = new TransactionScope()) - { - // Create first connection object. - using (DbConnection conn1 = factory.CreateConnection()) - { - // Set connection string and open the connection. this connection - // will be automatically enlisted in a distributed transaction. - conn1.ConnectionString = constr; - conn1.Open(); - - // Create a command to execute the sql statement. - DbCommand cmd1 = factory.CreateCommand(); - cmd1.Connection = conn1; - cmd1.CommandText = @"insert into dept (deptno, dname, loc) - values (99, 'st', 'lex')"; - - // Execute the SQL statement to insert one row in DB. - retVal = cmd1.ExecuteNonQuery(); - Console.WriteLine("Rows to be affected by cmd1: {0}", retVal); - - // Close the connection and dispose the command object. - conn1.Close(); - conn1.Dispose(); - cmd1.Dispose(); - } - - // The Complete method commits the transaction. If an exception has - // been thrown or Complete is not called then the transaction is - // rolled back. - scope.Complete(); - } - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - Console.WriteLine(ex.StackTrace); - } - } -} + *****************************************************************************/ + +using System; +using Oracle.ManagedDataAccess.Client; +using System.Data; +using System.Data.Common; +using System.Transactions; + +class psfTxnScope +{ + static void Main() + { + int retVal = 0; + string providerName = "Oracle.ManagedDataAccess.Client"; + string constr = + @"User Id=scott;Password=;Data Source=oracle;"; + + // Get the provider factory. + DbProviderFactory factory = DbProviderFactories.GetFactory(providerName); + + try + { + // Create a TransactionScope object, (It will start an ambient + // transaction automatically). + using (TransactionScope scope = new TransactionScope()) + { + // Create first connection object. + using (DbConnection conn1 = factory.CreateConnection()) + { + // Set connection string and open the connection. this connection + // will be automatically enlisted in a distributed transaction. + conn1.ConnectionString = constr; + conn1.Open(); + + // Create a command to execute the sql statement. + DbCommand cmd1 = factory.CreateCommand(); + cmd1.Connection = conn1; + cmd1.CommandText = @"insert into dept (deptno, dname, loc) + values (99, 'st', 'lex')"; + + // Execute the SQL statement to insert one row in DB. + retVal = cmd1.ExecuteNonQuery(); + Console.WriteLine("Rows to be affected by cmd1: {0}", retVal); + + // Close the connection and dispose the command object. + conn1.Close(); + conn1.Dispose(); + cmd1.Dispose(); + } + + // The Complete method commits the transaction. If an exception has + // been thrown or Complete is not called then the transaction is + // rolled back. + scope.Complete(); + } + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + Console.WriteLine(ex.StackTrace); + } + } +} diff --git a/schemas/scott.sql b/schemas/scott.sql index 116fc938..f843ba32 100644 --- a/schemas/scott.sql +++ b/schemas/scott.sql @@ -18,6 +18,8 @@ REM scott.sql Rem Rem DESCRIPTION Rem SCOTT is a database user whose schema is used for Oracle code demonstrations +Rem Be sure to replace on lines 31 and 34 with your preferred password. +Rem Historically, "tiger" has been SCOTT schema's password. SET TERMOUT OFF @@ -26,10 +28,10 @@ SET ECHO OFF rem CONGDON Invoked in RDBMS at build time. 29-DEC-1988 rem OATES: Created: 16-Feb-83 -GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE TO SCOTT IDENTIFIED BY TIGER; +GRANT CONNECT,RESOURCE,UNLIMITED TABLESPACE TO SCOTT IDENTIFIED BY ; ALTER USER SCOTT DEFAULT TABLESPACE USERS; ALTER USER SCOTT TEMPORARY TABLESPACE TEMP; -CONNECT SCOTT/TIGER +CONNECT SCOTT/ DROP TABLE DEPT; CREATE TABLE DEPT (DEPTNO NUMBER(2) CONSTRAINT PK_DEPT PRIMARY KEY, diff --git a/session-demos/2019/odtvscodescreenshots/readmeoverview.png b/session-demos/2019/odtvscodescreenshots/readmeoverview.png new file mode 100644 index 00000000..e3137acc Binary files /dev/null and b/session-demos/2019/odtvscodescreenshots/readmeoverview.png differ diff --git a/session-demos/2021/cicqn-json/README.md b/session-demos/2021/cicqn-json/README.md new file mode 100644 index 00000000..c818dcf8 --- /dev/null +++ b/session-demos/2021/cicqn-json/README.md @@ -0,0 +1,28 @@ +# ODP.NET Client Initiated Continuous Query Notification and JSON Data Type Code Sample +This C# sample console app uses ODP.NET Core 21c to demonstrate two new Oracle Database 21c features: +* Client Initiated Continuous Query Notification (CICQN) +* Native JSON binary data type (OSON) + +Learn more about [ODP.NET CICQN and JSON data type in this blog post](https://medium.com/@alex.keh/introducing-odp-net-21c-ef-core-5-json-and-more-ea0843e89dea). + +These features require Oracle Database 21c and ODP.NET 21c or higher. You can download +[ODP.NET 21c from NuGet Gallery](https://www.nuget.org/packages/Oracle.ManagedDataAccess.Core/3.21.1). +Oracle Database 21c can be deployed in minutes using a [free Oracle Autonomous Database](https://www.oracle.com/cloud/free/). + +Setup instructions: +1. The database administrator executes "GRANT CHANGE NOTIFICATION TO <USER>" so that the app can use CICQN. +2. Run the setup.sql file scripts to create the J_PURCHASEORDER table and insert a JSON document into the user's schema. +3. Populate the Constants class in the C# app with your app-specific values. + +The sample code retrieves the JSON data and shows the results on the console. While the app is idle, +another user can update the JSON data by running the following update statement in SQL Developer or Oracle +Developer Tools for Visual Studio. + +``` +UPDATE j_purchaseorder SET po_document = json_transform(po_document, SET '$.LastUpdated' = SYSDATE); +``` + +CICQN will then notify the application an update to the result occurred. The event handler will then re-query the database +for the new results. It will then display the results with the new LastUpdated JSON value. + +The update statement can be run repeatedly with the new JSON update returned every time. diff --git a/session-demos/2021/cicqn-json/cicqn-json.cs b/session-demos/2021/cicqn-json/cicqn-json.cs new file mode 100644 index 00000000..d55d7af0 --- /dev/null +++ b/session-demos/2021/cicqn-json/cicqn-json.cs @@ -0,0 +1,146 @@ +/* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. */ + +/****************************************************************************** + * + * You may not use the identified files except in compliance with The MIT + * License (the "License.") + * + * You may obtain a copy of the License at + * https://github.com/oracle/Oracle.NET/blob/master/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + *****************************************************************************/ + +using System; +using System.Data; +using Oracle.ManagedDataAccess.Client; + +namespace ODP.NET_CICQN_JSON_21c +{ + //This app demonstrates how to use Client Initiated Continquous Query Notification (CICQN) and + // JSON (OSON) data type with Oracle Database 21c. Works with autonomous, cloud, or on-premises DB. + + //Setup steps: + //1) "GRANT CHANGE NOTIFICATION TO " to use CICQN + //2) Create the J_PURCHASEORDER table and insert a JSON document into it. See SQL script. + //3) Use ODP.NET 21c and Oracle Database 21c to run the console app code. + //4) Populate the Constants class below with your app-specific values and run. + + class Program + { + static class Constants + { + //Enter your user id, password, and DB info, such as net service name, + // Easy Connect Plus, or connect descriptor + public const string ConString = "User Id=;Password=;Data Source=;Connection Timeout=30;"; + + //Enter directories where your *.ora files and your wallet are located, if applicable + public const string TnsDir = @""; + public const string WalletDir = @""; + + //Set the query to execute and JSON column to retrieve + public const string Query = "select PO_DOCUMENT from J_PURCHASEORDER"; + public const string JsonColumn = "PO_DOCUMENT"; + } + + static void Main() + { + //Directory where your cloud or database credentials are located, if applicable + OracleConfiguration.TnsAdmin = Constants.TnsDir; + OracleConfiguration.WalletLocation = Constants.WalletDir; + + //Turn on Client Initiated Continuous Query Notification + OracleConfiguration.UseClientInitiatedCQN = true; + + using (OracleConnection con = new OracleConnection(Constants.ConString)) + { + using (OracleCommand cmd = con.CreateCommand()) + { + try + { + con.Open(); + Console.WriteLine("Successfully connected to Oracle Database"); + Console.WriteLine(); + + //CQN setup + OracleDependency dep = new OracleDependency(cmd); + cmd.Notification.IsNotifiedOnce = false; + dep.OnChange += new OnChangeEventHandler(JSON_Notification); + + //Retrieve purchase order stored as JSON (OSON) type + //Store JSON data as string in disconnected DataSet + cmd.CommandText = Constants.Query; + OracleDataAdapter da = new OracleDataAdapter(cmd); + using (DataSet ds = new DataSet()) + { + da.Fill(ds); + foreach (DataTable table in ds.Tables) + { + foreach (DataRow row in table.Rows) + { + //Output the query result to the console + Console.WriteLine(row[Constants.JsonColumn].ToString()); + } + } + + //While result set is disconnected from database, modify the purchase + // order data through ODT or SQL*Plus, such as with the following SQL: + //UPDATE j_purchaseorder SET po_document = json_transform(po_document, SET '$.LastUpdated' = SYSDATE); + //Changing the data on database triggers the CICQN event handler. + //Each time the update statement runs, a new notification will be sent to the app. + + Console.ReadLine(); + } + da.Dispose(); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + } + } + public static void JSON_Notification(object src, OracleNotificationEventArgs args) + { + //Each time event handler launches, it retrieves the updated purchase order details + //Note that the LastUpdated entry has been changed. + Console.WriteLine(); + Console.WriteLine("Change detected."); + + using (OracleConnection con = new OracleConnection(Constants.ConString)) + { + using (OracleCommand cmd = con.CreateCommand()) + { + try + { + con.Open(); + cmd.CommandText = Constants.Query; + OracleDataAdapter da = new OracleDataAdapter(cmd); + using (DataSet ds = new DataSet()) + { + da.Fill(ds); + foreach (DataTable table in ds.Tables) + { + foreach (DataRow row in table.Rows) + { + Console.WriteLine(row[Constants.JsonColumn].ToString()); + } + } + } + da.Dispose(); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + } + } + } +} diff --git a/session-demos/2021/cicqn-json/setup.sql b/session-demos/2021/cicqn-json/setup.sql new file mode 100644 index 00000000..8356f114 --- /dev/null +++ b/session-demos/2021/cicqn-json/setup.sql @@ -0,0 +1,17 @@ +CREATE TABLE j_purchaseorder + (id VARCHAR2 (32) NOT NULL PRIMARY KEY, + date_loaded TIMESTAMP (6) WITH TIME ZONE, + po_document JSON); + +INSERT INTO j_purchaseorder + VALUES (SYS_GUID(), + to_date('30-DEC-2014'), + '{"PONumber" : 1600, + "Reference" : "ABULL-20140421", + "Requestor" : "Alexis Bull", + "User" : "ABULL", + "CostCenter" : "A50", + "ShippingInstructions" : "Mail package", + "Special Instructions" : null, + "AllowPartialShipment" : true, + "LineItems" : "Hardware"}'); diff --git a/video-demos/IntroVisualStudioAlwaysFreeADB/DataReader.cs b/video-demos/IntroVisualStudioAlwaysFreeADB/DataReader.cs new file mode 100644 index 00000000..50ee6e0a --- /dev/null +++ b/video-demos/IntroVisualStudioAlwaysFreeADB/DataReader.cs @@ -0,0 +1,75 @@ +/* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved. */ + +/****************************************************************************** + * + * You may not use the identified files except in compliance with The MIT + * License (the "License.") + * + * You may obtain a copy of the License at + * https://github.com/oracle/Oracle.NET/blob/master/LICENSE + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + *****************************************************************************/ + +using System; +using Oracle.ManagedDataAccess.Client; + +namespace VSADBDemo +{ + class Program + { + static void Main(string[] args) + { + //Demo: Basic ODP.NET Managed application to connect, query, and return + // results from an OracleDataReader to a console + + //Create a connection to Oracle + string conString = "User Id=hr;Password=mypassword;" + + + "Data Source=myalias;"; + + using (OracleConnection con = new OracleConnection(conString)) + { + using (OracleCommand cmd = con.CreateCommand()) + { + try + { + con.Open(); + cmd.BindByName = true; + + //Use the command to display employee names from + // the EMPLOYEES table + cmd.CommandText = "select first_name from employees where department_id = :id"; + + // Assign id to the department number 50 + OracleParameter id = new OracleParameter("id", 50); + cmd.Parameters.Add(id); + + //Execute the command and use DataReader to display the data + OracleDataReader reader = cmd.ExecuteReader(); + while (reader.Read()) + { + Console.WriteLine("Employee First Name: " + reader.GetString(0)); + } + + Console.WriteLine(); + Console.WriteLine("Press 'Enter' to continue"); + + reader.Dispose(); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + Console.ReadLine(); + } + } + } + } +} diff --git a/video-demos/IntroVisualStudioAlwaysFreeADB/hr.sql b/video-demos/IntroVisualStudioAlwaysFreeADB/hr.sql new file mode 100644 index 00000000..6ac1898f --- /dev/null +++ b/video-demos/IntroVisualStudioAlwaysFreeADB/hr.sql @@ -0,0 +1,2931 @@ +Rem +Rem $Header: hr_cre.sql 29-aug-2002.11:44:03 hyeh Exp $ +Rem +Rem hr_cre.sql +Rem +Rem Copyright (c) 2001, 2015, Oracle Corporation. All rights reserved. +Rem +Rem Permission is hereby granted, free of charge, to any person obtaining +Rem a copy of this software and associated documentation files (the +Rem "Software"), to deal in the Software without restriction, including +Rem without limitation the rights to use, copy, modify, merge, publish, +Rem distribute, sublicense, and/or sell copies of the Software, and to +Rem permit persons to whom the Software is furnished to do so, subject to +Rem the following conditions: +Rem +Rem The above copyright notice and this permission notice shall be +Rem included in all copies or substantial portions of the Software. +Rem +Rem THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +Rem EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +Rem MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +Rem NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +Rem LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +Rem OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +Rem WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Rem +Rem NAME +Rem hr_cre.sql - Create data objects for HR schema +Rem +Rem DESCRIPTION +Rem This script creates six tables, associated constraints +Rem and indexes in the human resources (HR) schema. +Rem +Rem NOTES +Rem +Rem CREATED by Nancy Greenberg, Nagavalli Pataballa - 06/01/00 +Rem +Rem MODIFIED (MM/DD/YY) +Rem hyeh 08/29/02 - hyeh_mv_comschema_to_rdbms +Rem ahunold 09/14/00 - Added emp_details_view +Rem ahunold 02/20/01 - New header +Rem vpatabal 03/02/01 - Added regions table, modified regions +Rem column in countries table to NUMBER. +Rem Added foreign key from countries table +Rem to regions table on region_id. +Rem Removed currency name, currency symbol +Rem columns from the countries table. +Rem Removed dn columns from employees and +Rem departments tables. +Rem Added sequences. +Rem Removed not null constraint from +Rem salary column of the employees table. + +SET FEEDBACK 1 +SET NUMWIDTH 10 +SET LINESIZE 80 +SET TRIMSPOOL ON +SET TAB OFF +SET PAGESIZE 100 +SET ECHO OFF + +REM ******************************************************************** +REM Create the REGIONS table to hold region information for locations +REM HR.LOCATIONS table has a foreign key to this table. + +Prompt ****** Creating REGIONS table .... + +CREATE TABLE regions + ( region_id NUMBER + CONSTRAINT region_id_nn NOT NULL + , region_name VARCHAR2(25) + ); + +CREATE UNIQUE INDEX reg_id_pk +ON regions (region_id); + +ALTER TABLE regions +ADD ( CONSTRAINT reg_id_pk + PRIMARY KEY (region_id) + ) ; + +REM ******************************************************************** +REM Create the COUNTRIES table to hold country information for customers +REM and company locations. +REM OE.CUSTOMERS table and HR.LOCATIONS have a foreign key to this table. + +Prompt ****** Creating COUNTRIES table .... + +CREATE TABLE countries + ( country_id CHAR(2) + CONSTRAINT country_id_nn NOT NULL + , country_name VARCHAR2(40) + , region_id NUMBER + , CONSTRAINT country_c_id_pk + PRIMARY KEY (country_id) + ) + ORGANIZATION INDEX; + +ALTER TABLE countries +ADD ( CONSTRAINT countr_reg_fk + FOREIGN KEY (region_id) + REFERENCES regions(region_id) + ) ; + +REM ******************************************************************** +REM Create the LOCATIONS table to hold address information for company departments. +REM HR.DEPARTMENTS has a foreign key to this table. + +Prompt ****** Creating LOCATIONS table .... + +CREATE TABLE locations + ( location_id NUMBER(4) + , street_address VARCHAR2(40) + , postal_code VARCHAR2(12) + , city VARCHAR2(30) + CONSTRAINT loc_city_nn NOT NULL + , state_province VARCHAR2(25) + , country_id CHAR(2) + ) ; + +CREATE UNIQUE INDEX loc_id_pk +ON locations (location_id) ; + +ALTER TABLE locations +ADD ( CONSTRAINT loc_id_pk + PRIMARY KEY (location_id) + , CONSTRAINT loc_c_id_fk + FOREIGN KEY (country_id) + REFERENCES countries(country_id) + ) ; + +Rem Useful for any subsequent addition of rows to locations table +Rem Starts with 3300 + +CREATE SEQUENCE locations_seq + START WITH 3300 + INCREMENT BY 100 + MAXVALUE 9900 + NOCACHE + NOCYCLE; + +REM ******************************************************************** +REM Create the DEPARTMENTS table to hold company department information. +REM HR.EMPLOYEES and HR.JOB_HISTORY have a foreign key to this table. + +Prompt ****** Creating DEPARTMENTS table .... + +CREATE TABLE departments + ( department_id NUMBER(4) + , department_name VARCHAR2(30) + CONSTRAINT dept_name_nn NOT NULL + , manager_id NUMBER(6) + , location_id NUMBER(4) + ) ; + +CREATE UNIQUE INDEX dept_id_pk +ON departments (department_id) ; + +ALTER TABLE departments +ADD ( CONSTRAINT dept_id_pk + PRIMARY KEY (department_id) + , CONSTRAINT dept_loc_fk + FOREIGN KEY (location_id) + REFERENCES locations (location_id) + ) ; + +Rem Useful for any subsequent addition of rows to departments table +Rem Starts with 280 + +CREATE SEQUENCE departments_seq + START WITH 280 + INCREMENT BY 10 + MAXVALUE 9990 + NOCACHE + NOCYCLE; + +REM ******************************************************************** +REM Create the JOBS table to hold the different names of job roles within the company. +REM HR.EMPLOYEES has a foreign key to this table. + +Prompt ****** Creating JOBS table .... + +CREATE TABLE jobs + ( job_id VARCHAR2(10) + , job_title VARCHAR2(35) + CONSTRAINT job_title_nn NOT NULL + , min_salary NUMBER(6) + , max_salary NUMBER(6) + ) ; + +CREATE UNIQUE INDEX job_id_pk +ON jobs (job_id) ; + +ALTER TABLE jobs +ADD ( CONSTRAINT job_id_pk + PRIMARY KEY(job_id) + ) ; + +REM ******************************************************************** +REM Create the EMPLOYEES table to hold the employee personnel +REM information for the company. +REM HR.EMPLOYEES has a self referencing foreign key to this table. + +Prompt ****** Creating EMPLOYEES table .... + +CREATE TABLE employees + ( employee_id NUMBER(6) + , first_name VARCHAR2(20) + , last_name VARCHAR2(25) + CONSTRAINT emp_last_name_nn NOT NULL + , email VARCHAR2(25) + CONSTRAINT emp_email_nn NOT NULL + , phone_number VARCHAR2(20) + , hire_date DATE + CONSTRAINT emp_hire_date_nn NOT NULL + , job_id VARCHAR2(10) + CONSTRAINT emp_job_nn NOT NULL + , salary NUMBER(8,2) + , commission_pct NUMBER(2,2) + , manager_id NUMBER(6) + , department_id NUMBER(4) + , CONSTRAINT emp_salary_min + CHECK (salary > 0) + , CONSTRAINT emp_email_uk + UNIQUE (email) + ) ; + +CREATE UNIQUE INDEX emp_emp_id_pk +ON employees (employee_id) ; + + +ALTER TABLE employees +ADD ( CONSTRAINT emp_emp_id_pk + PRIMARY KEY (employee_id) + , CONSTRAINT emp_dept_fk + FOREIGN KEY (department_id) + REFERENCES departments + , CONSTRAINT emp_job_fk + FOREIGN KEY (job_id) + REFERENCES jobs (job_id) + , CONSTRAINT emp_manager_fk + FOREIGN KEY (manager_id) + REFERENCES employees + ) ; + +ALTER TABLE departments +ADD ( CONSTRAINT dept_mgr_fk + FOREIGN KEY (manager_id) + REFERENCES employees (employee_id) + ) ; + + +Rem Useful for any subsequent addition of rows to employees table +Rem Starts with 207 + + +CREATE SEQUENCE employees_seq + START WITH 207 + INCREMENT BY 1 + NOCACHE + NOCYCLE; + +REM ******************************************************************** +REM Create the JOB_HISTORY table to hold the history of jobs that +REM employees have held in the past. +REM HR.JOBS, HR_DEPARTMENTS, and HR.EMPLOYEES have a foreign key to this table. + +Prompt ****** Creating JOB_HISTORY table .... + +CREATE TABLE job_history + ( employee_id NUMBER(6) + CONSTRAINT jhist_employee_nn NOT NULL + , start_date DATE + CONSTRAINT jhist_start_date_nn NOT NULL + , end_date DATE + CONSTRAINT jhist_end_date_nn NOT NULL + , job_id VARCHAR2(10) + CONSTRAINT jhist_job_nn NOT NULL + , department_id NUMBER(4) + , CONSTRAINT jhist_date_interval + CHECK (end_date > start_date) + ) ; + +CREATE UNIQUE INDEX jhist_emp_id_st_date_pk +ON job_history (employee_id, start_date) ; + +ALTER TABLE job_history +ADD ( CONSTRAINT jhist_emp_id_st_date_pk + PRIMARY KEY (employee_id, start_date) + , CONSTRAINT jhist_job_fk + FOREIGN KEY (job_id) + REFERENCES jobs + , CONSTRAINT jhist_emp_fk + FOREIGN KEY (employee_id) + REFERENCES employees + , CONSTRAINT jhist_dept_fk + FOREIGN KEY (department_id) + REFERENCES departments + ) ; + +REM ******************************************************************** +REM Create the EMP_DETAILS_VIEW that joins the employees, jobs, +REM departments, jobs, countries, and locations table to provide details +REM about employees. + +Prompt ****** Creating EMP_DETAILS_VIEW view ... + +CREATE OR REPLACE VIEW emp_details_view + (employee_id, + job_id, + manager_id, + department_id, + location_id, + country_id, + first_name, + last_name, + salary, + commission_pct, + department_name, + job_title, + city, + state_province, + country_name, + region_name) +AS SELECT + e.employee_id, + e.job_id, + e.manager_id, + e.department_id, + d.location_id, + l.country_id, + e.first_name, + e.last_name, + e.salary, + e.commission_pct, + d.department_name, + j.job_title, + l.city, + l.state_province, + c.country_name, + r.region_name +FROM + employees e, + departments d, + jobs j, + locations l, + countries c, + regions r +WHERE e.department_id = d.department_id + AND d.location_id = l.location_id + AND l.country_id = c.country_id + AND c.region_id = r.region_id + AND j.job_id = e.job_id +WITH READ ONLY; + +COMMIT; +rem +rem Header: hr_popul.sql 09-jan-01 +rem +rem Copyright (c) 2001, 2015, Oracle. All rights reserved. +rem +rem Permission is hereby granted, free of charge, to any person obtaining +rem a copy of this software and associated documentation files (the +rem "Software"), to deal in the Software without restriction, including +rem without limitation the rights to use, copy, modify, merge, publish, +rem distribute, sublicense, and/or sell copies of the Software, and to +rem permit persons to whom the Software is furnished to do so, subject to +rem the following conditions: +rem +rem The above copyright notice and this permission notice shall be +rem included in all copies or substantial portions of the Software. +rem +rem THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +rem EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +rem MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +rem NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +rem LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +rem OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +rem WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +rem +rem Owner : ahunold +rem +rem NAME +rem hr_popul.sql - Populate script for HR schema +rem +rem DESCRIPTON +rem +rem +rem NOTES +rem There is a circular foreign key reference between +rem EMPLOYESS and DEPARTMENTS. That's why we disable +rem the FK constraints here +rem +rem CREATED +rem Nancy Greenberg, Nagavalli Pataballa - 06/01/00 +rem +rem MODIFIED (MM/DD/YY) +rem celsbern 08/07/08 - fixing date strings to use all numbers, no month +rem names +rem cbauwens 02/13/08 - employees.hire_date rolled forward 8 years +rem job_history start_date end_date rolled forward 8 years +rem hyeh 08/29/02 - hyeh_mv_comschema_to_rdbms +rem ahunold 03/07/01 - small data errors corrected +rem - Modified region values of countries table +rem - Replaced ID sequence values for employees +rem and departments tables with numbers +rem - Moved create sequence statements to hr_cre +rem - Removed dn values for employees and +rem departments tables +rem - Removed currency columns values from +rem countries table +rem ngreenbe - Updated employee 178 for no department +rem pnathan - Insert new rows to job_history table +rem ahunold 02/20/01 - NLS_LANGUAGE, replacing non American +rem ahunold 01/09/01 - checkin ADE + +SET VERIFY OFF +ALTER SESSION SET NLS_LANGUAGE=American; + +REM ***************************insert data into the REGIONS table + +Prompt ****** Populating REGIONS table .... + +INSERT INTO regions VALUES + ( 1 + , 'Europe' + ); + +INSERT INTO regions VALUES + ( 2 + , 'Americas' + ); + +INSERT INTO regions VALUES + ( 3 + , 'Asia' + ); + +INSERT INTO regions VALUES + ( 4 + , 'Middle East and Africa' + ); + +REM ***************************insert data into the COUNTRIES table + +Prompt ****** Populating COUNTIRES table .... + +INSERT INTO countries VALUES + ( 'IT' + , 'Italy' + , 1 + ); + +INSERT INTO countries VALUES + ( 'JP' + , 'Japan' + , 3 + ); + +INSERT INTO countries VALUES + ( 'US' + , 'United States of America' + , 2 + ); + +INSERT INTO countries VALUES + ( 'CA' + , 'Canada' + , 2 + ); + +INSERT INTO countries VALUES + ( 'CN' + , 'China' + , 3 + ); + +INSERT INTO countries VALUES + ( 'IN' + , 'India' + , 3 + ); + +INSERT INTO countries VALUES + ( 'AU' + , 'Australia' + , 3 + ); + +INSERT INTO countries VALUES + ( 'ZW' + , 'Zimbabwe' + , 4 + ); + +INSERT INTO countries VALUES + ( 'SG' + , 'Singapore' + , 3 + ); + +INSERT INTO countries VALUES + ( 'UK' + , 'United Kingdom' + , 1 + ); + +INSERT INTO countries VALUES + ( 'FR' + , 'France' + , 1 + ); + +INSERT INTO countries VALUES + ( 'DE' + , 'Germany' + , 1 + ); + +INSERT INTO countries VALUES + ( 'ZM' + , 'Zambia' + , 4 + ); + +INSERT INTO countries VALUES + ( 'EG' + , 'Egypt' + , 4 + ); + +INSERT INTO countries VALUES + ( 'BR' + , 'Brazil' + , 2 + ); + +INSERT INTO countries VALUES + ( 'CH' + , 'Switzerland' + , 1 + ); + +INSERT INTO countries VALUES + ( 'NL' + , 'Netherlands' + , 1 + ); + +INSERT INTO countries VALUES + ( 'MX' + , 'Mexico' + , 2 + ); + +INSERT INTO countries VALUES + ( 'KW' + , 'Kuwait' + , 4 + ); + +INSERT INTO countries VALUES + ( 'IL' + , 'Israel' + , 4 + ); + +INSERT INTO countries VALUES + ( 'DK' + , 'Denmark' + , 1 + ); + +INSERT INTO countries VALUES + ( 'ML' + , 'Malaysia' + , 3 + ); + +INSERT INTO countries VALUES + ( 'NG' + , 'Nigeria' + , 4 + ); + +INSERT INTO countries VALUES + ( 'AR' + , 'Argentina' + , 2 + ); + +INSERT INTO countries VALUES + ( 'BE' + , 'Belgium' + , 1 + ); + + +REM ***************************insert data into the LOCATIONS table + +Prompt ****** Populating LOCATIONS table .... + +INSERT INTO locations VALUES + ( 1000 + , '1297 Via Cola di Rie' + , '00989' + , 'Roma' + , NULL + , 'IT' + ); + +INSERT INTO locations VALUES + ( 1100 + , '93091 Calle della Testa' + , '10934' + , 'Venice' + , NULL + , 'IT' + ); + +INSERT INTO locations VALUES + ( 1200 + , '2017 Shinjuku-ku' + , '1689' + , 'Tokyo' + , 'Tokyo Prefecture' + , 'JP' + ); + +INSERT INTO locations VALUES + ( 1300 + , '9450 Kamiya-cho' + , '6823' + , 'Hiroshima' + , NULL + , 'JP' + ); + +INSERT INTO locations VALUES + ( 1400 + , '2014 Jabberwocky Rd' + , '26192' + , 'Southlake' + , 'Texas' + , 'US' + ); + +INSERT INTO locations VALUES + ( 1500 + , '2011 Interiors Blvd' + , '99236' + , 'South San Francisco' + , 'California' + , 'US' + ); + +INSERT INTO locations VALUES + ( 1600 + , '2007 Zagora St' + , '50090' + , 'South Brunswick' + , 'New Jersey' + , 'US' + ); + +INSERT INTO locations VALUES + ( 1700 + , '2004 Charade Rd' + , '98199' + , 'Seattle' + , 'Washington' + , 'US' + ); + +INSERT INTO locations VALUES + ( 1800 + , '147 Spadina Ave' + , 'M5V 2L7' + , 'Toronto' + , 'Ontario' + , 'CA' + ); + +INSERT INTO locations VALUES + ( 1900 + , '6092 Boxwood St' + , 'YSW 9T2' + , 'Whitehorse' + , 'Yukon' + , 'CA' + ); + +INSERT INTO locations VALUES + ( 2000 + , '40-5-12 Laogianggen' + , '190518' + , 'Beijing' + , NULL + , 'CN' + ); + +INSERT INTO locations VALUES + ( 2100 + , '1298 Vileparle (E)' + , '490231' + , 'Bombay' + , 'Maharashtra' + , 'IN' + ); + +INSERT INTO locations VALUES + ( 2200 + , '12-98 Victoria Street' + , '2901' + , 'Sydney' + , 'New South Wales' + , 'AU' + ); + +INSERT INTO locations VALUES + ( 2300 + , '198 Clementi North' + , '540198' + , 'Singapore' + , NULL + , 'SG' + ); + +INSERT INTO locations VALUES + ( 2400 + , '8204 Arthur St' + , NULL + , 'London' + , NULL + , 'UK' + ); + +INSERT INTO locations VALUES + ( 2500 + , 'Magdalen Centre, The Oxford Science Park' + , 'OX9 9ZB' + , 'Oxford' + , 'Oxford' + , 'UK' + ); + +INSERT INTO locations VALUES + ( 2600 + , '9702 Chester Road' + , '09629850293' + , 'Stretford' + , 'Manchester' + , 'UK' + ); + +INSERT INTO locations VALUES + ( 2700 + , 'Schwanthalerstr. 7031' + , '80925' + , 'Munich' + , 'Bavaria' + , 'DE' + ); + +INSERT INTO locations VALUES + ( 2800 + , 'Rua Frei Caneca 1360 ' + , '01307-002' + , 'Sao Paulo' + , 'Sao Paulo' + , 'BR' + ); + +INSERT INTO locations VALUES + ( 2900 + , '20 Rue des Corps-Saints' + , '1730' + , 'Geneva' + , 'Geneve' + , 'CH' + ); + +INSERT INTO locations VALUES + ( 3000 + , 'Murtenstrasse 921' + , '3095' + , 'Bern' + , 'BE' + , 'CH' + ); + +INSERT INTO locations VALUES + ( 3100 + , 'Pieter Breughelstraat 837' + , '3029SK' + , 'Utrecht' + , 'Utrecht' + , 'NL' + ); + +INSERT INTO locations VALUES + ( 3200 + , 'Mariano Escobedo 9991' + , '11932' + , 'Mexico City' + , 'Distrito Federal,' + , 'MX' + ); + + +REM ****************************insert data into the DEPARTMENTS table + +Prompt ****** Populating DEPARTMENTS table .... + +REM disable integrity constraint to EMPLOYEES to load data + +ALTER TABLE departments + DISABLE CONSTRAINT dept_mgr_fk; + +INSERT INTO departments VALUES + ( 10 + , 'Administration' + , 200 + , 1700 + ); + +INSERT INTO departments VALUES + ( 20 + , 'Marketing' + , 201 + , 1800 + ); + +INSERT INTO departments VALUES + ( 30 + , 'Purchasing' + , 114 + , 1700 + ); + +INSERT INTO departments VALUES + ( 40 + , 'Human Resources' + , 203 + , 2400 + ); + +INSERT INTO departments VALUES + ( 50 + , 'Shipping' + , 121 + , 1500 + ); + +INSERT INTO departments VALUES + ( 60 + , 'IT' + , 103 + , 1400 + ); + +INSERT INTO departments VALUES + ( 70 + , 'Public Relations' + , 204 + , 2700 + ); + +INSERT INTO departments VALUES + ( 80 + , 'Sales' + , 145 + , 2500 + ); + +INSERT INTO departments VALUES + ( 90 + , 'Executive' + , 100 + , 1700 + ); + +INSERT INTO departments VALUES + ( 100 + , 'Finance' + , 108 + , 1700 + ); + +INSERT INTO departments VALUES + ( 110 + , 'Accounting' + , 205 + , 1700 + ); + +INSERT INTO departments VALUES + ( 120 + , 'Treasury' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 130 + , 'Corporate Tax' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 140 + , 'Control And Credit' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 150 + , 'Shareholder Services' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 160 + , 'Benefits' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 170 + , 'Manufacturing' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 180 + , 'Construction' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 190 + , 'Contracting' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 200 + , 'Operations' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 210 + , 'IT Support' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 220 + , 'NOC' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 230 + , 'IT Helpdesk' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 240 + , 'Government Sales' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 250 + , 'Retail Sales' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 260 + , 'Recruiting' + , NULL + , 1700 + ); + +INSERT INTO departments VALUES + ( 270 + , 'Payroll' + , NULL + , 1700 + ); + + +REM ***************************insert data into the JOBS table + +Prompt ****** Populating JOBS table .... + +INSERT INTO jobs VALUES + ( 'AD_PRES' + , 'President' + , 20080 + , 40000 + ); +INSERT INTO jobs VALUES + ( 'AD_VP' + , 'Administration Vice President' + , 15000 + , 30000 + ); + +INSERT INTO jobs VALUES + ( 'AD_ASST' + , 'Administration Assistant' + , 3000 + , 6000 + ); + +INSERT INTO jobs VALUES + ( 'FI_MGR' + , 'Finance Manager' + , 8200 + , 16000 + ); + +INSERT INTO jobs VALUES + ( 'FI_ACCOUNT' + , 'Accountant' + , 4200 + , 9000 + ); + +INSERT INTO jobs VALUES + ( 'AC_MGR' + , 'Accounting Manager' + , 8200 + , 16000 + ); + +INSERT INTO jobs VALUES + ( 'AC_ACCOUNT' + , 'Public Accountant' + , 4200 + , 9000 + ); +INSERT INTO jobs VALUES + ( 'SA_MAN' + , 'Sales Manager' + , 10000 + , 20080 + ); + +INSERT INTO jobs VALUES + ( 'SA_REP' + , 'Sales Representative' + , 6000 + , 12008 + ); + +INSERT INTO jobs VALUES + ( 'PU_MAN' + , 'Purchasing Manager' + , 8000 + , 15000 + ); + +INSERT INTO jobs VALUES + ( 'PU_CLERK' + , 'Purchasing Clerk' + , 2500 + , 5500 + ); + +INSERT INTO jobs VALUES + ( 'ST_MAN' + , 'Stock Manager' + , 5500 + , 8500 + ); +INSERT INTO jobs VALUES + ( 'ST_CLERK' + , 'Stock Clerk' + , 2008 + , 5000 + ); + +INSERT INTO jobs VALUES + ( 'SH_CLERK' + , 'Shipping Clerk' + , 2500 + , 5500 + ); + +INSERT INTO jobs VALUES + ( 'IT_PROG' + , 'Programmer' + , 4000 + , 10000 + ); + +INSERT INTO jobs VALUES + ( 'MK_MAN' + , 'Marketing Manager' + , 9000 + , 15000 + ); + +INSERT INTO jobs VALUES + ( 'MK_REP' + , 'Marketing Representative' + , 4000 + , 9000 + ); + +INSERT INTO jobs VALUES + ( 'HR_REP' + , 'Human Resources Representative' + , 4000 + , 9000 + ); + +INSERT INTO jobs VALUES + ( 'PR_REP' + , 'Public Relations Representative' + , 4500 + , 10500 + ); + + +REM ***************************insert data into the EMPLOYEES table + +Prompt ****** Populating EMPLOYEES table .... + +INSERT INTO employees VALUES + ( 100 + , 'Steven' + , 'King' + , 'SKING' + , '515.123.4567' + , TO_DATE('17-06-2003', 'dd-MM-yyyy') + , 'AD_PRES' + , 24000 + , NULL + , NULL + , 90 + ); + +INSERT INTO employees VALUES + ( 101 + , 'Neena' + , 'Kochhar' + , 'NKOCHHAR' + , '515.123.4568' + , TO_DATE('21-09-2005', 'dd-MM-yyyy') + , 'AD_VP' + , 17000 + , NULL + , 100 + , 90 + ); + +INSERT INTO employees VALUES + ( 102 + , 'Lex' + , 'De Haan' + , 'LDEHAAN' + , '515.123.4569' + , TO_DATE('13-01-2001', 'dd-MM-yyyy') + , 'AD_VP' + , 17000 + , NULL + , 100 + , 90 + ); + +INSERT INTO employees VALUES + ( 103 + , 'Alexander' + , 'Hunold' + , 'AHUNOLD' + , '590.423.4567' + , TO_DATE('03-01-2006', 'dd-MM-yyyy') + , 'IT_PROG' + , 9000 + , NULL + , 102 + , 60 + ); + +INSERT INTO employees VALUES + ( 104 + , 'Bruce' + , 'Ernst' + , 'BERNST' + , '590.423.4568' + , TO_DATE('21-05-2007', 'dd-MM-yyyy') + , 'IT_PROG' + , 6000 + , NULL + , 103 + , 60 + ); + +INSERT INTO employees VALUES + ( 105 + , 'David' + , 'Austin' + , 'DAUSTIN' + , '590.423.4569' + , TO_DATE('25-06-2005', 'dd-MM-yyyy') + , 'IT_PROG' + , 4800 + , NULL + , 103 + , 60 + ); + +INSERT INTO employees VALUES + ( 106 + , 'Valli' + , 'Pataballa' + , 'VPATABAL' + , '590.423.4560' + , TO_DATE('05-02-2006', 'dd-MM-yyyy') + , 'IT_PROG' + , 4800 + , NULL + , 103 + , 60 + ); + +INSERT INTO employees VALUES + ( 107 + , 'Diana' + , 'Lorentz' + , 'DLORENTZ' + , '590.423.5567' + , TO_DATE('07-02-2007', 'dd-MM-yyyy') + , 'IT_PROG' + , 4200 + , NULL + , 103 + , 60 + ); + +INSERT INTO employees VALUES + ( 108 + , 'Nancy' + , 'Greenberg' + , 'NGREENBE' + , '515.124.4569' + , TO_DATE('17-08-2002', 'dd-MM-yyyy') + , 'FI_MGR' + , 12008 + , NULL + , 101 + , 100 + ); + +INSERT INTO employees VALUES + ( 109 + , 'Daniel' + , 'Faviet' + , 'DFAVIET' + , '515.124.4169' + , TO_DATE('16-08-2002', 'dd-MM-yyyy') + , 'FI_ACCOUNT' + , 9000 + , NULL + , 108 + , 100 + ); + +INSERT INTO employees VALUES + ( 110 + , 'John' + , 'Chen' + , 'JCHEN' + , '515.124.4269' + , TO_DATE('28-09-2005', 'dd-MM-yyyy') + , 'FI_ACCOUNT' + , 8200 + , NULL + , 108 + , 100 + ); + +INSERT INTO employees VALUES + ( 111 + , 'Ismael' + , 'Sciarra' + , 'ISCIARRA' + , '515.124.4369' + , TO_DATE('30-09-2005', 'dd-MM-yyyy') + , 'FI_ACCOUNT' + , 7700 + , NULL + , 108 + , 100 + ); + +INSERT INTO employees VALUES + ( 112 + , 'Jose Manuel' + , 'Urman' + , 'JMURMAN' + , '515.124.4469' + , TO_DATE('07-03-2006', 'dd-MM-yyyy') + , 'FI_ACCOUNT' + , 7800 + , NULL + , 108 + , 100 + ); + +INSERT INTO employees VALUES + ( 113 + , 'Luis' + , 'Popp' + , 'LPOPP' + , '515.124.4567' + , TO_DATE('07-12-2007', 'dd-MM-yyyy') + , 'FI_ACCOUNT' + , 6900 + , NULL + , 108 + , 100 + ); + +INSERT INTO employees VALUES + ( 114 + , 'Den' + , 'Raphaely' + , 'DRAPHEAL' + , '515.127.4561' + , TO_DATE('07-12-2002', 'dd-MM-yyyy') + , 'PU_MAN' + , 11000 + , NULL + , 100 + , 30 + ); + +INSERT INTO employees VALUES + ( 115 + , 'Alexander' + , 'Khoo' + , 'AKHOO' + , '515.127.4562' + , TO_DATE('18-05-2003', 'dd-MM-yyyy') + , 'PU_CLERK' + , 3100 + , NULL + , 114 + , 30 + ); + +INSERT INTO employees VALUES + ( 116 + , 'Shelli' + , 'Baida' + , 'SBAIDA' + , '515.127.4563' + , TO_DATE('24-12-2005', 'dd-MM-yyyy') + , 'PU_CLERK' + , 2900 + , NULL + , 114 + , 30 + ); + +INSERT INTO employees VALUES + ( 117 + , 'Sigal' + , 'Tobias' + , 'STOBIAS' + , '515.127.4564' + , TO_DATE('24-07-2005', 'dd-MM-yyyy') + , 'PU_CLERK' + , 2800 + , NULL + , 114 + , 30 + ); + +INSERT INTO employees VALUES + ( 118 + , 'Guy' + , 'Himuro' + , 'GHIMURO' + , '515.127.4565' + , TO_DATE('15-11-2006', 'dd-MM-yyyy') + , 'PU_CLERK' + , 2600 + , NULL + , 114 + , 30 + ); + +INSERT INTO employees VALUES + ( 119 + , 'Karen' + , 'Colmenares' + , 'KCOLMENA' + , '515.127.4566' + , TO_DATE('10-08-2007', 'dd-MM-yyyy') + , 'PU_CLERK' + , 2500 + , NULL + , 114 + , 30 + ); + +INSERT INTO employees VALUES + ( 120 + , 'Matthew' + , 'Weiss' + , 'MWEISS' + , '650.123.1234' + , TO_DATE('18-07-2004', 'dd-MM-yyyy') + , 'ST_MAN' + , 8000 + , NULL + , 100 + , 50 + ); + +INSERT INTO employees VALUES + ( 121 + , 'Adam' + , 'Fripp' + , 'AFRIPP' + , '650.123.2234' + , TO_DATE('10-04-2005', 'dd-MM-yyyy') + , 'ST_MAN' + , 8200 + , NULL + , 100 + , 50 + ); + +INSERT INTO employees VALUES + ( 122 + , 'Payam' + , 'Kaufling' + , 'PKAUFLIN' + , '650.123.3234' + , TO_DATE('01-05-2003', 'dd-MM-yyyy') + , 'ST_MAN' + , 7900 + , NULL + , 100 + , 50 + ); + +INSERT INTO employees VALUES + ( 123 + , 'Shanta' + , 'Vollman' + , 'SVOLLMAN' + , '650.123.4234' + , TO_DATE('10-10-2005', 'dd-MM-yyyy') + , 'ST_MAN' + , 6500 + , NULL + , 100 + , 50 + ); + +INSERT INTO employees VALUES + ( 124 + , 'Kevin' + , 'Mourgos' + , 'KMOURGOS' + , '650.123.5234' + , TO_DATE('16-11-2007', 'dd-MM-yyyy') + , 'ST_MAN' + , 5800 + , NULL + , 100 + , 50 + ); + +INSERT INTO employees VALUES + ( 125 + , 'Julia' + , 'Nayer' + , 'JNAYER' + , '650.124.1214' + , TO_DATE('16-07-2005', 'dd-MM-yyyy') + , 'ST_CLERK' + , 3200 + , NULL + , 120 + , 50 + ); + +INSERT INTO employees VALUES + ( 126 + , 'Irene' + , 'Mikkilineni' + , 'IMIKKILI' + , '650.124.1224' + , TO_DATE('28-09-2006', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2700 + , NULL + , 120 + , 50 + ); + +INSERT INTO employees VALUES + ( 127 + , 'James' + , 'Landry' + , 'JLANDRY' + , '650.124.1334' + , TO_DATE('14-01-2007', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2400 + , NULL + , 120 + , 50 + ); + +INSERT INTO employees VALUES + ( 128 + , 'Steven' + , 'Markle' + , 'SMARKLE' + , '650.124.1434' + , TO_DATE('08-03-2008', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2200 + , NULL + , 120 + , 50 + ); + +INSERT INTO employees VALUES + ( 129 + , 'Laura' + , 'Bissot' + , 'LBISSOT' + , '650.124.5234' + , TO_DATE('20-08-2005', 'dd-MM-yyyy') + , 'ST_CLERK' + , 3300 + , NULL + , 121 + , 50 + ); + +INSERT INTO employees VALUES + ( 130 + , 'Mozhe' + , 'Atkinson' + , 'MATKINSO' + , '650.124.6234' + , TO_DATE('30-10-2005', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2800 + , NULL + , 121 + , 50 + ); + +INSERT INTO employees VALUES + ( 131 + , 'James' + , 'Marlow' + , 'JAMRLOW' + , '650.124.7234' + , TO_DATE('16-02-2005', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2500 + , NULL + , 121 + , 50 + ); + +INSERT INTO employees VALUES + ( 132 + , 'TJ' + , 'Olson' + , 'TJOLSON' + , '650.124.8234' + , TO_DATE('10-04-2007', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2100 + , NULL + , 121 + , 50 + ); + +INSERT INTO employees VALUES + ( 133 + , 'Jason' + , 'Mallin' + , 'JMALLIN' + , '650.127.1934' + , TO_DATE('14-06-2004', 'dd-MM-yyyy') + , 'ST_CLERK' + , 3300 + , NULL + , 122 + , 50 + ); + +INSERT INTO employees VALUES + ( 134 + , 'Michael' + , 'Rogers' + , 'MROGERS' + , '650.127.1834' + , TO_DATE('26-08-2006', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2900 + , NULL + , 122 + , 50 + ); + +INSERT INTO employees VALUES + ( 135 + , 'Ki' + , 'Gee' + , 'KGEE' + , '650.127.1734' + , TO_DATE('12-12-2007', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2400 + , NULL + , 122 + , 50 + ); + +INSERT INTO employees VALUES + ( 136 + , 'Hazel' + , 'Philtanker' + , 'HPHILTAN' + , '650.127.1634' + , TO_DATE('06-02-2008', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2200 + , NULL + , 122 + , 50 + ); + +INSERT INTO employees VALUES + ( 137 + , 'Renske' + , 'Ladwig' + , 'RLADWIG' + , '650.121.1234' + , TO_DATE('14-07-2003', 'dd-MM-yyyy') + , 'ST_CLERK' + , 3600 + , NULL + , 123 + , 50 + ); + +INSERT INTO employees VALUES + ( 138 + , 'Stephen' + , 'Stiles' + , 'SSTILES' + , '650.121.2034' + , TO_DATE('26-10-2005', 'dd-MM-yyyy') + , 'ST_CLERK' + , 3200 + , NULL + , 123 + , 50 + ); + +INSERT INTO employees VALUES + ( 139 + , 'John' + , 'Seo' + , 'JSEO' + , '650.121.2019' + , TO_DATE('12-02-2006', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2700 + , NULL + , 123 + , 50 + ); + +INSERT INTO employees VALUES + ( 140 + , 'Joshua' + , 'Patel' + , 'JPATEL' + , '650.121.1834' + , TO_DATE('06-04-2006', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2500 + , NULL + , 123 + , 50 + ); + +INSERT INTO employees VALUES + ( 141 + , 'Trenna' + , 'Rajs' + , 'TRAJS' + , '650.121.8009' + , TO_DATE('17-10-2003', 'dd-MM-yyyy') + , 'ST_CLERK' + , 3500 + , NULL + , 124 + , 50 + ); + +INSERT INTO employees VALUES + ( 142 + , 'Curtis' + , 'Davies' + , 'CDAVIES' + , '650.121.2994' + , TO_DATE('29-01-2005', 'dd-MM-yyyy') + , 'ST_CLERK' + , 3100 + , NULL + , 124 + , 50 + ); + +INSERT INTO employees VALUES + ( 143 + , 'Randall' + , 'Matos' + , 'RMATOS' + , '650.121.2874' + , TO_DATE('15-03-2006', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2600 + , NULL + , 124 + , 50 + ); + +INSERT INTO employees VALUES + ( 144 + , 'Peter' + , 'Vargas' + , 'PVARGAS' + , '650.121.2004' + , TO_DATE('09-07-2006', 'dd-MM-yyyy') + , 'ST_CLERK' + , 2500 + , NULL + , 124 + , 50 + ); + +INSERT INTO employees VALUES + ( 145 + , 'John' + , 'Russell' + , 'JRUSSEL' + , '011.44.1344.429268' + , TO_DATE('01-10-2004', 'dd-MM-yyyy') + , 'SA_MAN' + , 14000 + , .4 + , 100 + , 80 + ); + +INSERT INTO employees VALUES + ( 146 + , 'Karen' + , 'Partners' + , 'KPARTNER' + , '011.44.1344.467268' + , TO_DATE('05-01-2005', 'dd-MM-yyyy') + , 'SA_MAN' + , 13500 + , .3 + , 100 + , 80 + ); + +INSERT INTO employees VALUES + ( 147 + , 'Alberto' + , 'Errazuriz' + , 'AERRAZUR' + , '011.44.1344.429278' + , TO_DATE('10-03-2005', 'dd-MM-yyyy') + , 'SA_MAN' + , 12000 + , .3 + , 100 + , 80 + ); + +INSERT INTO employees VALUES + ( 148 + , 'Gerald' + , 'Cambrault' + , 'GCAMBRAU' + , '011.44.1344.619268' + , TO_DATE('15-10-2007', 'dd-MM-yyyy') + , 'SA_MAN' + , 11000 + , .3 + , 100 + , 80 + ); + +INSERT INTO employees VALUES + ( 149 + , 'Eleni' + , 'Zlotkey' + , 'EZLOTKEY' + , '011.44.1344.429018' + , TO_DATE('29-01-2008', 'dd-MM-yyyy') + , 'SA_MAN' + , 10500 + , .2 + , 100 + , 80 + ); + +INSERT INTO employees VALUES + ( 150 + , 'Peter' + , 'Tucker' + , 'PTUCKER' + , '011.44.1344.129268' + , TO_DATE('30-01-2005', 'dd-MM-yyyy') + , 'SA_REP' + , 10000 + , .3 + , 145 + , 80 + ); + +INSERT INTO employees VALUES + ( 151 + , 'David' + , 'Bernstein' + , 'DBERNSTE' + , '011.44.1344.345268' + , TO_DATE('24-03-2005', 'dd-MM-yyyy') + , 'SA_REP' + , 9500 + , .25 + , 145 + , 80 + ); + +INSERT INTO employees VALUES + ( 152 + , 'Peter' + , 'Hall' + , 'PHALL' + , '011.44.1344.478968' + , TO_DATE('20-08-2005', 'dd-MM-yyyy') + , 'SA_REP' + , 9000 + , .25 + , 145 + , 80 + ); + +INSERT INTO employees VALUES + ( 153 + , 'Christopher' + , 'Olsen' + , 'COLSEN' + , '011.44.1344.498718' + , TO_DATE('30-03-2006', 'dd-MM-yyyy') + , 'SA_REP' + , 8000 + , .2 + , 145 + , 80 + ); + +INSERT INTO employees VALUES + ( 154 + , 'Nanette' + , 'Cambrault' + , 'NCAMBRAU' + , '011.44.1344.987668' + , TO_DATE('09-12-2006', 'dd-MM-yyyy') + , 'SA_REP' + , 7500 + , .2 + , 145 + , 80 + ); + +INSERT INTO employees VALUES + ( 155 + , 'Oliver' + , 'Tuvault' + , 'OTUVAULT' + , '011.44.1344.486508' + , TO_DATE('23-11-2007', 'dd-MM-yyyy') + , 'SA_REP' + , 7000 + , .15 + , 145 + , 80 + ); + +INSERT INTO employees VALUES + ( 156 + , 'Janette' + , 'King' + , 'JKING' + , '011.44.1345.429268' + , TO_DATE('30-01-2004', 'dd-MM-yyyy') + , 'SA_REP' + , 10000 + , .35 + , 146 + , 80 + ); + +INSERT INTO employees VALUES + ( 157 + , 'Patrick' + , 'Sully' + , 'PSULLY' + , '011.44.1345.929268' + , TO_DATE('04-03-2004', 'dd-MM-yyyy') + , 'SA_REP' + , 9500 + , .35 + , 146 + , 80 + ); + +INSERT INTO employees VALUES + ( 158 + , 'Allan' + , 'McEwen' + , 'AMCEWEN' + , '011.44.1345.829268' + , TO_DATE('01-08-2004', 'dd-MM-yyyy') + , 'SA_REP' + , 9000 + , .35 + , 146 + , 80 + ); + +INSERT INTO employees VALUES + ( 159 + , 'Lindsey' + , 'Smith' + , 'LSMITH' + , '011.44.1345.729268' + , TO_DATE('10-03-2005', 'dd-MM-yyyy') + , 'SA_REP' + , 8000 + , .3 + , 146 + , 80 + ); + +INSERT INTO employees VALUES + ( 160 + , 'Louise' + , 'Doran' + , 'LDORAN' + , '011.44.1345.629268' + , TO_DATE('15-12-2005', 'dd-MM-yyyy') + , 'SA_REP' + , 7500 + , .3 + , 146 + , 80 + ); + +INSERT INTO employees VALUES + ( 161 + , 'Sarath' + , 'Sewall' + , 'SSEWALL' + , '011.44.1345.529268' + , TO_DATE('03-11-2006', 'dd-MM-yyyy') + , 'SA_REP' + , 7000 + , .25 + , 146 + , 80 + ); + +INSERT INTO employees VALUES + ( 162 + , 'Clara' + , 'Vishney' + , 'CVISHNEY' + , '011.44.1346.129268' + , TO_DATE('11-11-2005', 'dd-MM-yyyy') + , 'SA_REP' + , 10500 + , .25 + , 147 + , 80 + ); + +INSERT INTO employees VALUES + ( 163 + , 'Danielle' + , 'Greene' + , 'DGREENE' + , '011.44.1346.229268' + , TO_DATE('19-03-2007', 'dd-MM-yyyy') + , 'SA_REP' + , 9500 + , .15 + , 147 + , 80 + ); + +INSERT INTO employees VALUES + ( 164 + , 'Mattea' + , 'Marvins' + , 'MMARVINS' + , '011.44.1346.329268' + , TO_DATE('24-01-2008', 'dd-MM-yyyy') + , 'SA_REP' + , 7200 + , .10 + , 147 + , 80 + ); + +INSERT INTO employees VALUES + ( 165 + , 'David' + , 'Lee' + , 'DLEE' + , '011.44.1346.529268' + , TO_DATE('23-02-2008', 'dd-MM-yyyy') + , 'SA_REP' + , 6800 + , .1 + , 147 + , 80 + ); + +INSERT INTO employees VALUES + ( 166 + , 'Sundar' + , 'Ande' + , 'SANDE' + , '011.44.1346.629268' + , TO_DATE('24-03-2008', 'dd-MM-yyyy') + , 'SA_REP' + , 6400 + , .10 + , 147 + , 80 + ); + +INSERT INTO employees VALUES + ( 167 + , 'Amit' + , 'Banda' + , 'ABANDA' + , '011.44.1346.729268' + , TO_DATE('21-04-2008', 'dd-MM-yyyy') + , 'SA_REP' + , 6200 + , .10 + , 147 + , 80 + ); + +INSERT INTO employees VALUES + ( 168 + , 'Lisa' + , 'Ozer' + , 'LOZER' + , '011.44.1343.929268' + , TO_DATE('11-03-2005', 'dd-MM-yyyy') + , 'SA_REP' + , 11500 + , .25 + , 148 + , 80 + ); + +INSERT INTO employees VALUES + ( 169 + , 'Harrison' + , 'Bloom' + , 'HBLOOM' + , '011.44.1343.829268' + , TO_DATE('23-03-2006', 'dd-MM-yyyy') + , 'SA_REP' + , 10000 + , .20 + , 148 + , 80 + ); + +INSERT INTO employees VALUES + ( 170 + , 'Tayler' + , 'Fox' + , 'TFOX' + , '011.44.1343.729268' + , TO_DATE('24-01-2006', 'dd-MM-yyyy') + , 'SA_REP' + , 9600 + , .20 + , 148 + , 80 + ); + +INSERT INTO employees VALUES + ( 171 + , 'William' + , 'Smith' + , 'WSMITH' + , '011.44.1343.629268' + , TO_DATE('23-02-2007', 'dd-MM-yyyy') + , 'SA_REP' + , 7400 + , .15 + , 148 + , 80 + ); + +INSERT INTO employees VALUES + ( 172 + , 'Elizabeth' + , 'Bates' + , 'EBATES' + , '011.44.1343.529268' + , TO_DATE('24-03-2007', 'dd-MM-yyyy') + , 'SA_REP' + , 7300 + , .15 + , 148 + , 80 + ); + +INSERT INTO employees VALUES + ( 173 + , 'Sundita' + , 'Kumar' + , 'SKUMAR' + , '011.44.1343.329268' + , TO_DATE('21-04-2008', 'dd-MM-yyyy') + , 'SA_REP' + , 6100 + , .10 + , 148 + , 80 + ); + +INSERT INTO employees VALUES + ( 174 + , 'Ellen' + , 'Abel' + , 'EABEL' + , '011.44.1644.429267' + , TO_DATE('11-05-2004', 'dd-MM-yyyy') + , 'SA_REP' + , 11000 + , .30 + , 149 + , 80 + ); + +INSERT INTO employees VALUES + ( 175 + , 'Alyssa' + , 'Hutton' + , 'AHUTTON' + , '011.44.1644.429266' + , TO_DATE('19-03-2005', 'dd-MM-yyyy') + , 'SA_REP' + , 8800 + , .25 + , 149 + , 80 + ); + +INSERT INTO employees VALUES + ( 176 + , 'Jonathon' + , 'Taylor' + , 'JTAYLOR' + , '011.44.1644.429265' + , TO_DATE('24-03-2006', 'dd-MM-yyyy') + , 'SA_REP' + , 8600 + , .20 + , 149 + , 80 + ); + +INSERT INTO employees VALUES + ( 177 + , 'Jack' + , 'Livingston' + , 'JLIVINGS' + , '011.44.1644.429264' + , TO_DATE('23-04-2006', 'dd-MM-yyyy') + , 'SA_REP' + , 8400 + , .20 + , 149 + , 80 + ); + +INSERT INTO employees VALUES + ( 178 + , 'Kimberely' + , 'Grant' + , 'KGRANT' + , '011.44.1644.429263' + , TO_DATE('24-05-2007', 'dd-MM-yyyy') + , 'SA_REP' + , 7000 + , .15 + , 149 + , NULL + ); + +INSERT INTO employees VALUES + ( 179 + , 'Charles' + , 'Johnson' + , 'CJOHNSON' + , '011.44.1644.429262' + , TO_DATE('04-01-2008', 'dd-MM-yyyy') + , 'SA_REP' + , 6200 + , .10 + , 149 + , 80 + ); + +INSERT INTO employees VALUES + ( 180 + , 'Winston' + , 'Taylor' + , 'WTAYLOR' + , '650.507.9876' + , TO_DATE('24-01-2006', 'dd-MM-yyyy') + , 'SH_CLERK' + , 3200 + , NULL + , 120 + , 50 + ); + +INSERT INTO employees VALUES + ( 181 + , 'Jean' + , 'Fleaur' + , 'JFLEAUR' + , '650.507.9877' + , TO_DATE('23-02-2006', 'dd-MM-yyyy') + , 'SH_CLERK' + , 3100 + , NULL + , 120 + , 50 + ); + +INSERT INTO employees VALUES + ( 182 + , 'Martha' + , 'Sullivan' + , 'MSULLIVA' + , '650.507.9878' + , TO_DATE('21-06-2007', 'dd-MM-yyyy') + , 'SH_CLERK' + , 2500 + , NULL + , 120 + , 50 + ); + +INSERT INTO employees VALUES + ( 183 + , 'Girard' + , 'Geoni' + , 'GGEONI' + , '650.507.9879' + , TO_DATE('03-02-2008', 'dd-MM-yyyy') + , 'SH_CLERK' + , 2800 + , NULL + , 120 + , 50 + ); + +INSERT INTO employees VALUES + ( 184 + , 'Nandita' + , 'Sarchand' + , 'NSARCHAN' + , '650.509.1876' + , TO_DATE('27-01-2004', 'dd-MM-yyyy') + , 'SH_CLERK' + , 4200 + , NULL + , 121 + , 50 + ); + +INSERT INTO employees VALUES + ( 185 + , 'Alexis' + , 'Bull' + , 'ABULL' + , '650.509.2876' + , TO_DATE('20-02-2005', 'dd-MM-yyyy') + , 'SH_CLERK' + , 4100 + , NULL + , 121 + , 50 + ); + +INSERT INTO employees VALUES + ( 186 + , 'Julia' + , 'Dellinger' + , 'JDELLING' + , '650.509.3876' + , TO_DATE('24-06-2006', 'dd-MM-yyyy') + , 'SH_CLERK' + , 3400 + , NULL + , 121 + , 50 + ); + +INSERT INTO employees VALUES + ( 187 + , 'Anthony' + , 'Cabrio' + , 'ACABRIO' + , '650.509.4876' + , TO_DATE('07-02-2007', 'dd-MM-yyyy') + , 'SH_CLERK' + , 3000 + , NULL + , 121 + , 50 + ); + +INSERT INTO employees VALUES + ( 188 + , 'Kelly' + , 'Chung' + , 'KCHUNG' + , '650.505.1876' + , TO_DATE('14-06-2005', 'dd-MM-yyyy') + , 'SH_CLERK' + , 3800 + , NULL + , 122 + , 50 + ); + +INSERT INTO employees VALUES + ( 189 + , 'Jennifer' + , 'Dilly' + , 'JDILLY' + , '650.505.2876' + , TO_DATE('13-08-2005', 'dd-MM-yyyy') + , 'SH_CLERK' + , 3600 + , NULL + , 122 + , 50 + ); + +INSERT INTO employees VALUES + ( 190 + , 'Timothy' + , 'Gates' + , 'TGATES' + , '650.505.3876' + , TO_DATE('11-07-2006', 'dd-MM-yyyy') + , 'SH_CLERK' + , 2900 + , NULL + , 122 + , 50 + ); + +INSERT INTO employees VALUES + ( 191 + , 'Randall' + , 'Perkins' + , 'RPERKINS' + , '650.505.4876' + , TO_DATE('19-12-2007', 'dd-MM-yyyy') + , 'SH_CLERK' + , 2500 + , NULL + , 122 + , 50 + ); + +INSERT INTO employees VALUES + ( 192 + , 'Sarah' + , 'Bell' + , 'SBELL' + , '650.501.1876' + , TO_DATE('04-02-2004', 'dd-MM-yyyy') + , 'SH_CLERK' + , 4000 + , NULL + , 123 + , 50 + ); + +INSERT INTO employees VALUES + ( 193 + , 'Britney' + , 'Everett' + , 'BEVERETT' + , '650.501.2876' + , TO_DATE('03-03-2005', 'dd-MM-yyyy') + , 'SH_CLERK' + , 3900 + , NULL + , 123 + , 50 + ); + +INSERT INTO employees VALUES + ( 194 + , 'Samuel' + , 'McCain' + , 'SMCCAIN' + , '650.501.3876' + , TO_DATE('01-07-2006', 'dd-MM-yyyy') + , 'SH_CLERK' + , 3200 + , NULL + , 123 + , 50 + ); + +INSERT INTO employees VALUES + ( 195 + , 'Vance' + , 'Jones' + , 'VJONES' + , '650.501.4876' + , TO_DATE('17-03-2007', 'dd-MM-yyyy') + , 'SH_CLERK' + , 2800 + , NULL + , 123 + , 50 + ); + +INSERT INTO employees VALUES + ( 196 + , 'Alana' + , 'Walsh' + , 'AWALSH' + , '650.507.9811' + , TO_DATE('24-04-2006', 'dd-MM-yyyy') + , 'SH_CLERK' + , 3100 + , NULL + , 124 + , 50 + ); + +INSERT INTO employees VALUES + ( 197 + , 'Kevin' + , 'Feeney' + , 'KFEENEY' + , '650.507.9822' + , TO_DATE('23-05-2006', 'dd-MM-yyyy') + , 'SH_CLERK' + , 3000 + , NULL + , 124 + , 50 + ); + +INSERT INTO employees VALUES + ( 198 + , 'Donald' + , 'OConnell' + , 'DOCONNEL' + , '650.507.9833' + , TO_DATE('21-06-2007', 'dd-MM-yyyy') + , 'SH_CLERK' + , 2600 + , NULL + , 124 + , 50 + ); + +INSERT INTO employees VALUES + ( 199 + , 'Douglas' + , 'Grant' + , 'DGRANT' + , '650.507.9844' + , TO_DATE('13-01-2008', 'dd-MM-yyyy') + , 'SH_CLERK' + , 2600 + , NULL + , 124 + , 50 + ); + +INSERT INTO employees VALUES + ( 200 + , 'Jennifer' + , 'Whalen' + , 'JWHALEN' + , '515.123.4444' + , TO_DATE('17-09-2003', 'dd-MM-yyyy') + , 'AD_ASST' + , 4400 + , NULL + , 101 + , 10 + ); + +INSERT INTO employees VALUES + ( 201 + , 'Michael' + , 'Hartstein' + , 'MHARTSTE' + , '515.123.5555' + , TO_DATE('17-02-2004', 'dd-MM-yyyy') + , 'MK_MAN' + , 13000 + , NULL + , 100 + , 20 + ); + +INSERT INTO employees VALUES + ( 202 + , 'Pat' + , 'Fay' + , 'PFAY' + , '603.123.6666' + , TO_DATE('17-08-2005', 'dd-MM-yyyy') + , 'MK_REP' + , 6000 + , NULL + , 201 + , 20 + ); + +INSERT INTO employees VALUES + ( 203 + , 'Susan' + , 'Mavris' + , 'SMAVRIS' + , '515.123.7777' + , TO_DATE('07-06-2002', 'dd-MM-yyyy') + , 'HR_REP' + , 6500 + , NULL + , 101 + , 40 + ); + +INSERT INTO employees VALUES + ( 204 + , 'Hermann' + , 'Baer' + , 'HBAER' + , '515.123.8888' + , TO_DATE('07-06-2002', 'dd-MM-yyyy') + , 'PR_REP' + , 10000 + , NULL + , 101 + , 70 + ); + +INSERT INTO employees VALUES + ( 205 + , 'Shelley' + , 'Higgins' + , 'SHIGGINS' + , '515.123.8080' + , TO_DATE('07-06-2002', 'dd-MM-yyyy') + , 'AC_MGR' + , 12008 + , NULL + , 101 + , 110 + ); + +INSERT INTO employees VALUES + ( 206 + , 'William' + , 'Gietz' + , 'WGIETZ' + , '515.123.8181' + , TO_DATE('07-06-2002', 'dd-MM-yyyy') + , 'AC_ACCOUNT' + , 8300 + , NULL + , 205 + , 110 + ); + +REM ********* insert data into the JOB_HISTORY table + +Prompt ****** Populating JOB_HISTORY table .... + + +INSERT INTO job_history +VALUES (102 + , TO_DATE('13-01-2001', 'dd-MM-yyyy') + , TO_DATE('24-07-2006', 'dd-MM-yyyy') + , 'IT_PROG' + , 60); + +INSERT INTO job_history +VALUES (101 + , TO_DATE('21-09-1997', 'dd-MM-yyyy') + , TO_DATE('27-10-2001', 'dd-MM-yyyy') + , 'AC_ACCOUNT' + , 110); + +INSERT INTO job_history +VALUES (101 + , TO_DATE('28-10-2001', 'dd-MM-yyyy') + , TO_DATE('15-03-2005', 'dd-MM-yyyy') + , 'AC_MGR' + , 110); + +INSERT INTO job_history +VALUES (201 + , TO_DATE('17-02-2004', 'dd-MM-yyyy') + , TO_DATE('19-12-2007', 'dd-MM-yyyy') + , 'MK_REP' + , 20); + +INSERT INTO job_history +VALUES (114 + , TO_DATE('24-03-2006', 'dd-MM-yyyy') + , TO_DATE('31-12-2007', 'dd-MM-yyyy') + , 'ST_CLERK' + , 50 + ); + +INSERT INTO job_history +VALUES (122 + , TO_DATE('01-01-2007', 'dd-MM-yyyy') + , TO_DATE('31-12-2007', 'dd-MM-yyyy') + , 'ST_CLERK' + , 50 + ); + +INSERT INTO job_history +VALUES (200 + , TO_DATE('17-09-1995', 'dd-MM-yyyy') + , TO_DATE('17-06-2001', 'dd-MM-yyyy') + , 'AD_ASST' + , 90 + ); + +INSERT INTO job_history +VALUES (176 + , TO_DATE('24-03-2006', 'dd-MM-yyyy') + , TO_DATE('31-12-2006', 'dd-MM-yyyy') + , 'SA_REP' + , 80 + ); + +INSERT INTO job_history +VALUES (176 + , TO_DATE('01-01-2007', 'dd-MM-yyyy') + , TO_DATE('31-12-2007', 'dd-MM-yyyy') + , 'SA_MAN' + , 80 + ); + +INSERT INTO job_history +VALUES (200 + , TO_DATE('01-07-2002', 'dd-MM-yyyy') + , TO_DATE('31-12-2006', 'dd-MM-yyyy') + , 'AC_ACCOUNT' + , 90 + ); + +REM enable integrity constraint to DEPARTMENTS + +ALTER TABLE departments + ENABLE CONSTRAINT dept_mgr_fk; + +COMMIT; + +Rem +Rem $Header: hr_idx.sql 29-aug-2002.11:44:09 hyeh Exp $ +Rem +Rem hr_idx.sql +Rem +Rem Copyright (c) 2001, 2015, Oracle Corporation. All rights reserved. +Rem +Rem Permission is hereby granted, free of charge, to any person obtaining +Rem a copy of this software and associated documentation files (the +Rem "Software"), to deal in the Software without restriction, including +Rem without limitation the rights to use, copy, modify, merge, publish, +Rem distribute, sublicense, and/or sell copies of the Software, and to +Rem permit persons to whom the Software is furnished to do so, subject to +Rem the following conditions: +Rem +Rem The above copyright notice and this permission notice shall be +Rem included in all copies or substantial portions of the Software. +Rem +Rem THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +Rem EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +Rem MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +Rem NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +Rem LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +Rem OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +Rem WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Rem +Rem NAME +Rem hr_idx.sql - Create indexes for HR schema +Rem +Rem DESCRIPTION +Rem +Rem +Rem NOTES +Rem +Rem +Rem CREATED by Nancy Greenberg - 06/01/00 +Rem MODIFIED (MM/DD/YY) +Rem hyeh 08/29/02 - hyeh_mv_comschema_to_rdbms +Rem ahunold 02/20/01 - New header +Rem vpatabal 03/02/01 - Removed DROP INDEX statements + +SET FEEDBACK 1 +SET NUMWIDTH 10 +SET LINESIZE 80 +SET TRIMSPOOL ON +SET TAB OFF +SET PAGESIZE 100 +SET ECHO OFF + +CREATE INDEX emp_department_ix + ON employees (department_id); + +CREATE INDEX emp_job_ix + ON employees (job_id); + +CREATE INDEX emp_manager_ix + ON employees (manager_id); + +CREATE INDEX emp_name_ix + ON employees (last_name, first_name); + +CREATE INDEX dept_location_ix + ON departments (location_id); + +CREATE INDEX jhist_job_ix + ON job_history (job_id); + +CREATE INDEX jhist_employee_ix + ON job_history (employee_id); + +CREATE INDEX jhist_department_ix + ON job_history (department_id); + +CREATE INDEX loc_city_ix + ON locations (city); + +CREATE INDEX loc_state_province_ix + ON locations (state_province); + +CREATE INDEX loc_country_ix + ON locations (country_id); + +COMMIT; + +Rem +Rem $Header: hr_code.sql 29-aug-2002.11:44:01 hyeh Exp $ +Rem +Rem hr_code.sql +Rem +Rem Copyright (c) 2001, 2015, Oracle Corporation. All rights reserved. +Rem +Rem Permission is hereby granted, free of charge, to any person obtaining +Rem a copy of this software and associated documentation files (the +Rem "Software"), to deal in the Software without restriction, including +Rem without limitation the rights to use, copy, modify, merge, publish, +Rem distribute, sublicense, and/or sell copies of the Software, and to +Rem permit persons to whom the Software is furnished to do so, subject to +Rem the following conditions: +Rem +Rem The above copyright notice and this permission notice shall be +Rem included in all copies or substantial portions of the Software. +Rem +Rem THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +Rem EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +Rem MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +Rem NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +Rem LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +Rem OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +Rem WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +Rem +Rem NAME +Rem hr_code.sql - Create procedural objects for HR schema +Rem +Rem DESCRIPTION +Rem Create a statement level trigger on EMPLOYEES +Rem to allow DML during business hours. +Rem Create a row level trigger on the EMPLOYEES table, +Rem after UPDATES on the department_id or job_id columns. +Rem Create a stored procedure to insert a row into the +Rem JOB_HISTORY table. Have the above row level trigger +Rem row level trigger call this stored procedure. +Rem +Rem NOTES +Rem +Rem CREATED by Nancy Greenberg - 06/01/00 +Rem +Rem MODIFIED (MM/DD/YY) +Rem hyeh 08/29/02 - hyeh_mv_comschema_to_rdbms +Rem ahunold 05/11/01 - disable +Rem ahunold 03/03/01 - HR simplification, REGIONS table +Rem ahunold 02/20/01 - Created +Rem + +SET FEEDBACK 1 +SET NUMWIDTH 10 +SET LINESIZE 80 +SET TRIMSPOOL ON +SET TAB OFF +SET PAGESIZE 100 +SET ECHO OFF + +REM ************************************************************************** + +REM procedure and statement trigger to allow dmls during business hours: +CREATE OR REPLACE PROCEDURE secure_dml +IS +BEGIN + IF TO_CHAR (SYSDATE, 'HH24:MI') NOT BETWEEN '08:00' AND '18:00' + OR TO_CHAR (SYSDATE, 'DY') IN ('SAT', 'SUN') THEN + RAISE_APPLICATION_ERROR (-20205, + 'You may only make changes during normal office hours'); + END IF; +END secure_dml; +/ + +CREATE OR REPLACE TRIGGER secure_employees + BEFORE INSERT OR UPDATE OR DELETE ON employees +BEGIN + secure_dml; +END secure_employees; +/ + +ALTER TRIGGER secure_employees DISABLE; + +REM ************************************************************************** +REM procedure to add a row to the JOB_HISTORY table and row trigger +REM to call the procedure when data is updated in the job_id or +REM department_id columns in the EMPLOYEES table: + +CREATE OR REPLACE PROCEDURE add_job_history + ( p_emp_id job_history.employee_id%type + , p_start_date job_history.start_date%type + , p_end_date job_history.end_date%type + , p_job_id job_history.job_id%type + , p_department_id job_history.department_id%type + ) +IS +BEGIN + INSERT INTO job_history (employee_id, start_date, end_date, + job_id, department_id) + VALUES(p_emp_id, p_start_date, p_end_date, p_job_id, p_department_id); +END add_job_history; +/ + +CREATE OR REPLACE TRIGGER update_job_history + AFTER UPDATE OF job_id, department_id ON employees + FOR EACH ROW +BEGIN + add_job_history(:old.employee_id, :old.hire_date, sysdate, + :old.job_id, :old.department_id); +END; +/ + +COMMIT; +/ + +