You've already forked linux-packaging-mono
acceptance-tests
data
debian
docs
eglib
external
ikvm-native
libgc
llvm
m4
man
mcs
build
class
Accessibility
Commons.Xml.Relaxng
Cscompmgd
CustomMarshalers
Facades
I18N
IBM.Data.DB2
ICSharpCode.SharpZipLib
Microsoft.Build
Microsoft.Build.Engine
Microsoft.Build.Framework
Microsoft.Build.Tasks
Microsoft.Build.Utilities
Microsoft.CSharp
Microsoft.NuGet.Build.Tasks
Microsoft.VisualC
Microsoft.Web.Infrastructure
MicrosoftAjaxLibrary
Mono.Btls.Interface
Mono.C5
Mono.CSharp
Mono.Cairo
Mono.Cecil
Mono.Cecil.Mdb
Mono.CodeContracts
Mono.CompilerServices.SymbolWriter
Mono.Data.Sqlite
Mono.Data.Tds
Mono.Debugger.Soft
Mono.Http
Mono.Management
Mono.Messaging
Mono.Messaging.RabbitMQ
Mono.Options
Mono.Parallel
Mono.Posix
Mono.Security
Mono.Security.Win32
Mono.Simd
Mono.Tasklets
Mono.WebBrowser
Mono.XBuild.Tasks
Novell.Directory.Ldap
PEAPI
RabbitMQ.Client
SMDiagnostics
System
System.ComponentModel.Composition.4.5
System.ComponentModel.DataAnnotations
System.Configuration
System.Configuration.Install
System.Core
System.Data
System.Data.DataSetExtensions
System.Data.Entity
System.Data.Linq
System.Data.OracleClient
Assembly
System.Data.OracleClient
System.Data.OracleClient.Oci
Test
System.Data.OracleClient
System.Data.OracleClient.Oci
System.Data.OracleClient.jvm
MonoTests.System.Data.Utils
OracleCommand
OracleCommand_CommandText.cs
OracleCommand_CommandTimeout.cs
OracleCommand_CommandType.cs
OracleCommand_Connection.cs
OracleCommand_Dispose.cs
OracleCommand_ExecuteNonQuery.cs
OracleCommand_ExecuteReader.cs
OracleCommand_ExecuteScalar.cs
OracleCommand_New.cs
OracleCommand_Parameters.cs
OracleCommand_Prepare.cs
OracleCommand_Transaction.cs
OracleCommandBuilder
OracleConnection
OracleDataAdapter
OracleDataReader
OracleParameter
OracleParameterCollection
OracleTransaction
OracleType
TestOracleClient.cs.REMOVED.git-id
refcursortest.cs
testblob.cs
testclob.cs
Makefile
System.Data.OracleClient.dll.sources
System.Data.OracleClient_test.dll.sources
System.Data.Services
System.Data.Services.Client
System.Deployment
System.Design
System.DirectoryServices
System.DirectoryServices.Protocols
System.Drawing
System.Drawing.Design
System.Dynamic
System.EnterpriseServices
System.IO.Compression
System.IO.Compression.FileSystem
System.IdentityModel
System.IdentityModel.Selectors
System.Json
System.Json.Microsoft
System.Management
System.Messaging
System.Net
System.Net.Http
System.Net.Http.Formatting
System.Net.Http.WebRequest
System.Net.Http.WinHttpHandler
System.Numerics
System.Numerics.Vectors
System.Reactive.Core
System.Reactive.Debugger
System.Reactive.Experimental
System.Reactive.Interfaces
System.Reactive.Linq
System.Reactive.Observable.Aliases
System.Reactive.PlatformServices
System.Reactive.Providers
System.Reactive.Runtime.Remoting
System.Reactive.Windows.Forms
System.Reactive.Windows.Threading
System.Reflection.Context
System.Reflection.DispatchProxy
System.Runtime.Caching
System.Runtime.DurableInstancing
System.Runtime.InteropServices.RuntimeInformation
System.Runtime.Remoting
System.Runtime.Serialization
System.Runtime.Serialization.Formatters.Soap
System.Security
System.ServiceModel
System.ServiceModel.Activation
System.ServiceModel.Discovery
System.ServiceModel.Internals
System.ServiceModel.Routing
System.ServiceModel.Web
System.ServiceProcess
System.Threading.Tasks.Dataflow
System.Transactions
System.Web
System.Web.Abstractions
System.Web.ApplicationServices
System.Web.DynamicData
System.Web.Extensions
System.Web.Extensions.Design
System.Web.Http
System.Web.Http.SelfHost
System.Web.Http.WebHost
System.Web.Mobile
System.Web.Mvc3
System.Web.Razor
System.Web.RegularExpressions
System.Web.Routing
System.Web.Services
System.Web.WebPages
System.Web.WebPages.Deployment
System.Web.WebPages.Razor
System.Windows
System.Windows.Forms
System.Windows.Forms.DataVisualization
System.Workflow.Activities
System.Workflow.ComponentModel
System.Workflow.Runtime
System.XML
System.Xaml
System.Xml.Linq
System.Xml.Serialization
System.Xml.XPath.XmlDocument
SystemWebTestShim
WebMatrix.Data
WindowsBase
aot-compiler
corlib
dlr
doc
legacy
lib
monodoc
notes
reference-assemblies
referencesource
test-helpers
LICENSE
Makefile
Open.snk
README
ecma.pub
mono.pub
mono.snk
msfinal.pub
reactive.pub
silverlight.pub
winfx.pub
winfx3.pub
docs
errors
ilasm
jay
mcs
nunit24
packages
tests
tools
AUTHORS
COPYING
INSTALL.txt
Makefile
MonoIcon.png
README
ScalableMonoIcon.svg
mkinstalldirs
winexe.in
mono
msvc
po
runtime
samples
scripts
support
tools
COPYING.LIB
LICENSE
Makefile.am
Makefile.in
NEWS
README.md
acinclude.m4
aclocal.m4
autogen.sh
code_of_conduct.md
compile
config.guess
config.h.in
config.rpath
config.sub
configure.REMOVED.git-id
configure.ac.REMOVED.git-id
depcomp
install-sh
ltmain.sh.REMOVED.git-id
missing
mkinstalldirs
mono-uninstalled.pc.in
test-driver
winconfig.h
423 lines
11 KiB
C#
423 lines
11 KiB
C#
![]() |
//
|
||
|
// Copyright (c) 2006 Mainsoft Co.
|
||
|
//
|
||
|
// Permission is hereby granted, free of charge, to any person obtaining
|
||
|
// a copy of this software and associated documentation files (the
|
||
|
// "Software"), to deal in the Software without restriction, including
|
||
|
// without limitation the rights to use, copy, modify, merge, publish,
|
||
|
// distribute, sublicense, and/or sell copies of the Software, and to
|
||
|
// permit persons to whom the Software is furnished to do so, subject to
|
||
|
// the following conditions:
|
||
|
//
|
||
|
// The above copyright notice and this permission notice shall be
|
||
|
// included in all copies or substantial portions of the Software.
|
||
|
//
|
||
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||
|
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||
|
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||
|
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||
|
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||
|
//
|
||
|
|
||
|
using System;
|
||
|
using System.Text;
|
||
|
using System.Data;
|
||
|
using System.Data.OracleClient ;
|
||
|
|
||
|
using MonoTests.System.Data.Utils;
|
||
|
|
||
|
|
||
|
using NUnit.Framework;
|
||
|
#if DAAB
|
||
|
using Microsoft.ApplicationBlocks;
|
||
|
#endif
|
||
|
|
||
|
namespace MonoTests.System.Data.OracleClient
|
||
|
{
|
||
|
[TestFixture]
|
||
|
public class OracleCommand_ExecuteReader : ADONetTesterClass
|
||
|
{
|
||
|
OracleConnection con;
|
||
|
OracleCommand cmd;
|
||
|
|
||
|
[SetUp]
|
||
|
public void SetUp()
|
||
|
{
|
||
|
Exception exp = null;
|
||
|
BeginCase("Setup");
|
||
|
try
|
||
|
{
|
||
|
con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
|
||
|
cmd = new OracleCommand("", con);
|
||
|
con.Open();
|
||
|
this.Pass("Setup.");
|
||
|
}
|
||
|
catch(Exception ex) {exp = ex;}
|
||
|
finally {EndCase(exp); exp = null;}
|
||
|
}
|
||
|
|
||
|
[TearDown]
|
||
|
public void TearDown()
|
||
|
{
|
||
|
if (con != null)
|
||
|
{
|
||
|
if (con.State == ConnectionState.Open) con.Close();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void Main()
|
||
|
{
|
||
|
OracleCommand_ExecuteReader tc = new OracleCommand_ExecuteReader();
|
||
|
Exception exp = null;
|
||
|
try
|
||
|
{
|
||
|
tc.BeginTest("OracleCommand_ExecuteReader");
|
||
|
tc.SetUp();
|
||
|
tc.run();
|
||
|
tc.TearDown();
|
||
|
}
|
||
|
catch(Exception ex){exp = ex;}
|
||
|
finally {tc.EndTest(exp);}
|
||
|
}
|
||
|
|
||
|
[Test]
|
||
|
public void run()
|
||
|
{
|
||
|
Exception exp = null;
|
||
|
bool RecordsExists = false;
|
||
|
OracleDataReader rdr =null;
|
||
|
|
||
|
// testBug3965();
|
||
|
// TestMultipleResultsets();
|
||
|
// TestCompoundVariable();
|
||
|
|
||
|
cmd.CommandText = "Select FirstName,City From Employees";
|
||
|
if (con.State != ConnectionState.Open)
|
||
|
{
|
||
|
con.Open();
|
||
|
}
|
||
|
|
||
|
try
|
||
|
{
|
||
|
BeginCase("check reader is null");
|
||
|
rdr = cmd.ExecuteReader();
|
||
|
Compare(rdr==null, false);
|
||
|
}
|
||
|
catch(Exception ex){exp = ex;}
|
||
|
finally
|
||
|
{
|
||
|
if (rdr != null) rdr.Close();
|
||
|
EndCase(exp);
|
||
|
exp = null;
|
||
|
}
|
||
|
|
||
|
try
|
||
|
{
|
||
|
BeginCase("check reader.read");
|
||
|
rdr = cmd.ExecuteReader();
|
||
|
RecordsExists = rdr.Read();
|
||
|
Compare(RecordsExists ,true);
|
||
|
}
|
||
|
catch(Exception ex){exp = ex;}
|
||
|
finally
|
||
|
{
|
||
|
if (rdr != null) rdr.Close();
|
||
|
EndCase(exp);
|
||
|
exp = null;
|
||
|
}
|
||
|
|
||
|
try
|
||
|
{
|
||
|
BeginCase("execute reader again ");
|
||
|
rdr = cmd.ExecuteReader();
|
||
|
Compare(rdr==null, false);
|
||
|
}
|
||
|
catch(Exception ex){exp = ex;}
|
||
|
finally
|
||
|
{
|
||
|
if (rdr != null) rdr.Close();
|
||
|
EndCase(exp);
|
||
|
exp = null;
|
||
|
}
|
||
|
|
||
|
try
|
||
|
{
|
||
|
BeginCase("Test compound SQL statement");
|
||
|
//Build a compund SQL command.
|
||
|
string[] sqlStatements = new string[] {
|
||
|
"INSERT INTO Categories (CategoryName, Description) VALUES('__TEST_RECORD__', 'Inserted')",
|
||
|
"UPDATE Categories SET Description='Updated' WHERE CategoryName='__TEST_RECORD__'",
|
||
|
"DELETE FROM Categories WHERE CategoryName='__TEST_RECORD__'" ,
|
||
|
};
|
||
|
cmd.CommandText = CreateCompundSqlStatement(sqlStatements, ConnectedDataProvider.GetDbType());
|
||
|
rdr = cmd.ExecuteReader();
|
||
|
Compare(rdr.Read(), false);
|
||
|
}
|
||
|
catch(Exception ex){exp = ex;}
|
||
|
finally
|
||
|
{
|
||
|
if (rdr != null) rdr.Close();
|
||
|
EndCase(exp);
|
||
|
exp = null;
|
||
|
}
|
||
|
|
||
|
|
||
|
if (ConnectedDataProvider.GetDbType() != DataBaseServer.Oracle)
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
BeginCase("Check that in a compound SQL statement, resultsets are returned only for SELECT statements. (bug #3358)");
|
||
|
//prepare db:
|
||
|
OracleCommand prepare = new OracleCommand("DELETE FROM Categories WHERE CategoryName='__TEST_RECORD__'", con);
|
||
|
prepare.ExecuteNonQuery();
|
||
|
|
||
|
|
||
|
//Test body
|
||
|
int resultSetCount ;
|
||
|
|
||
|
//Build a compund SQL command that contains only one select statement.
|
||
|
string[] sqlStatements = new string[] {
|
||
|
"INSERT INTO Categories (CategoryName, Description) VALUES('__TEST_RECORD__', 'Inserted')",
|
||
|
"UPDATE Categories SET Description='Updated' WHERE CategoryName='__TEST_RECORD__'",
|
||
|
"DELETE FROM Categories WHERE CategoryName='__TEST_RECORD__'" ,
|
||
|
"SELECT * FROM Categories "
|
||
|
};
|
||
|
string insertCmdTxt = CreateCompundSqlStatement(sqlStatements, ConnectedDataProvider.GetDbType());
|
||
|
//this.Log(insertCmdTxt);
|
||
|
OracleCommand InsertCmd = new OracleCommand(insertCmdTxt, con);
|
||
|
rdr = InsertCmd.ExecuteReader();
|
||
|
|
||
|
//Count the number of result sets.
|
||
|
resultSetCount = 0;
|
||
|
do
|
||
|
{
|
||
|
resultSetCount++;
|
||
|
}while (rdr.NextResult());
|
||
|
|
||
|
//Test that there is only one result set.
|
||
|
Compare(resultSetCount, 1);
|
||
|
}
|
||
|
catch(Exception ex){exp = ex;}
|
||
|
finally
|
||
|
{
|
||
|
if (rdr != null) rdr.Close();
|
||
|
EndCase(exp);
|
||
|
exp = null;
|
||
|
//cleanup db:
|
||
|
OracleCommand cleanup = new OracleCommand("DELETE FROM Categories WHERE CategoryName='__TEST_RECORD__'", con);
|
||
|
cleanup.ExecuteNonQuery();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
//Create the compund sql statement according to the dbserver.
|
||
|
private string CreateCompundSqlStatement(string[] sqlStatements, DataBaseServer dbServer)
|
||
|
{
|
||
|
string beginStatement;
|
||
|
string endStatement;
|
||
|
string commandDelimiter;
|
||
|
|
||
|
GetDBSpecificSyntax(dbServer, out beginStatement, out endStatement, out commandDelimiter);
|
||
|
|
||
|
StringBuilder cmdBuilder = new StringBuilder();
|
||
|
cmdBuilder.Append(beginStatement);
|
||
|
cmdBuilder.Append(" ");
|
||
|
foreach (string statement in sqlStatements)
|
||
|
{
|
||
|
cmdBuilder.Append(statement);
|
||
|
cmdBuilder.Append(commandDelimiter);
|
||
|
cmdBuilder.Append(" ");
|
||
|
}
|
||
|
cmdBuilder.Append(endStatement);
|
||
|
|
||
|
return cmdBuilder.ToString();
|
||
|
}
|
||
|
|
||
|
private void GetDBSpecificSyntax(DataBaseServer dbServer, out string beginStatement, out string endStatement, out string commandDelimiter)
|
||
|
{
|
||
|
switch (dbServer)
|
||
|
{
|
||
|
case DataBaseServer.SQLServer:
|
||
|
case DataBaseServer.PostgreSQL:
|
||
|
beginStatement = "";
|
||
|
endStatement = "";
|
||
|
commandDelimiter = ";";
|
||
|
break;
|
||
|
|
||
|
case DataBaseServer.Sybase:
|
||
|
beginStatement = "BEGIN";
|
||
|
endStatement = "END";
|
||
|
commandDelimiter = "";
|
||
|
break;
|
||
|
case DataBaseServer.Oracle:
|
||
|
beginStatement = "BEGIN";
|
||
|
endStatement = "END;";
|
||
|
commandDelimiter = ";";
|
||
|
break;
|
||
|
|
||
|
case DataBaseServer.DB2:
|
||
|
beginStatement = "BEGIN ATOMIC";
|
||
|
endStatement = "END";
|
||
|
commandDelimiter = ";";
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
this.Fail("Unknown DataBaseServer type");
|
||
|
throw new ApplicationException("Unknown DataBaseServer type");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
[Test]
|
||
|
public void TestMultipleResultsets()
|
||
|
{
|
||
|
#if !JAVA
|
||
|
if (ConnectedDataProvider.GetDbType(con) == DataBaseServer.Oracle)
|
||
|
{
|
||
|
//In .NET there is a bug when calling a SP with multiple REFCURSORS, the workaround is to use OracleClient and not Oracle.
|
||
|
//In GH we are not bug complient in this issue, because there is no workaround (We do not support the OracleClient namespace.
|
||
|
this.Log("Not testing multi result set Oracle on .NET");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
if (ConnectedDataProvider.GetDbType(con) == DataBaseServer.PostgreSQL)
|
||
|
{
|
||
|
// fail to work on .NET OLEDB
|
||
|
//reader = Microsoft.ApplicationBlocks.Data.PostgresOracleHelper.ADOExecuteReader(cmd1);
|
||
|
this.Log("Not testing PostgreSQL CommandType.StoredProcedure which return SETOF");
|
||
|
return;
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
Exception exp = null;
|
||
|
BeginCase("Test multi result set from stored procedure");
|
||
|
|
||
|
|
||
|
OracleDataReader reader = null;
|
||
|
OracleTransaction tr = null;
|
||
|
|
||
|
try
|
||
|
{
|
||
|
//Check SP with the structre : insert Select + update Select + delete Select
|
||
|
if (con.State != ConnectionState.Open)
|
||
|
{
|
||
|
con.Open();
|
||
|
}
|
||
|
|
||
|
// transaction use was add for PostgreSQL
|
||
|
tr = con.BeginTransaction();
|
||
|
OracleCommand cmd1 = new OracleCommand("GHSP_TYPES_SIMPLE_4", con, tr);
|
||
|
cmd1.CommandType = CommandType.StoredProcedure;
|
||
|
|
||
|
OracleParameter param = new OracleParameter();
|
||
|
param.ParameterName = "ID1";
|
||
|
param.Value = string.Format("13268_{0}", this.TestCaseNumber);
|
||
|
param.OracleType = OracleType.VarChar;
|
||
|
cmd1.Parameters.Add(param);
|
||
|
cmd1.Parameters.Add(new OracleParameter("RESULT", OracleType.Cursor)).Direction = ParameterDirection.Output;
|
||
|
cmd1.Parameters.Add(new OracleParameter("RESULT1", OracleType.Cursor)).Direction = ParameterDirection.Output;
|
||
|
cmd1.Parameters.Add(new OracleParameter("RESULT2", OracleType.Cursor)).Direction = ParameterDirection.Output;
|
||
|
|
||
|
|
||
|
reader = cmd1.ExecuteReader();
|
||
|
|
||
|
//Count the number of result sets.
|
||
|
int resultSetCount = 0;
|
||
|
//Count the number of the records
|
||
|
int recordCounter=0;
|
||
|
|
||
|
do
|
||
|
{
|
||
|
//this.Log(string.Format("resultSetCount:{0}",resultSetCount));
|
||
|
while (reader.Read())
|
||
|
{
|
||
|
recordCounter++;
|
||
|
}
|
||
|
//this.Log(string.Format("recordCounter:{0}",recordCounter));
|
||
|
if (resultSetCount != 2)
|
||
|
{
|
||
|
Compare(recordCounter,1); //Insert + update
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Compare(recordCounter,0); //Delete
|
||
|
}
|
||
|
|
||
|
recordCounter=0;
|
||
|
resultSetCount++;
|
||
|
}while (reader.NextResult());
|
||
|
|
||
|
Compare(resultSetCount,3);
|
||
|
}
|
||
|
catch (Exception ex)
|
||
|
{
|
||
|
exp=ex;
|
||
|
}
|
||
|
finally
|
||
|
{
|
||
|
EndCase(exp);
|
||
|
if (reader != null) reader.Close();
|
||
|
tr.Commit();
|
||
|
con.Close();
|
||
|
}
|
||
|
}
|
||
|
[Test]
|
||
|
public void TestCompoundVariable()
|
||
|
{
|
||
|
OracleDataReader rdr = null;
|
||
|
if (ConnectedDataProvider.GetDbType(con) == DataBaseServer.PostgreSQL)
|
||
|
{
|
||
|
this.Log("not testing PostgreSQL");
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
Exception exp = null;
|
||
|
try
|
||
|
{
|
||
|
BeginCase("Check sql statement that declares a local variable and uses it.");
|
||
|
|
||
|
if (con.State != ConnectionState.Open)
|
||
|
{
|
||
|
con.Open();
|
||
|
}
|
||
|
|
||
|
string sqlTxt = "";
|
||
|
switch (ConnectedDataProvider.GetDbType(cmd.Connection))
|
||
|
{
|
||
|
case DataBaseServer.SQLServer:
|
||
|
sqlTxt = "declare @var int; select @var=1;";
|
||
|
break;
|
||
|
case DataBaseServer.Sybase:
|
||
|
sqlTxt = "declare @var int select @var=1";
|
||
|
break;
|
||
|
case DataBaseServer.Oracle:
|
||
|
sqlTxt = "declare var int;begin var:=1;end;";
|
||
|
break;
|
||
|
case DataBaseServer.DB2:
|
||
|
sqlTxt = "begin atomic declare var integer; set var = 1; end";
|
||
|
break;
|
||
|
case DataBaseServer.PostgreSQL:
|
||
|
// we don't know how the heck to do this in PostgreSQL
|
||
|
sqlTxt = "";
|
||
|
break;
|
||
|
default:
|
||
|
throw new ApplicationException(string.Format("GHT: Unknown DataBaseServer '{0}'", ConnectedDataProvider.GetDbType(cmd.Connection)));
|
||
|
}
|
||
|
cmd.CommandText = sqlTxt;
|
||
|
rdr = cmd.ExecuteReader();
|
||
|
Compare(rdr.Read(), false);
|
||
|
}
|
||
|
catch(Exception ex){exp = ex;}
|
||
|
finally
|
||
|
{
|
||
|
if (rdr != null) rdr.Close();
|
||
|
EndCase(exp);
|
||
|
exp = null;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|