2 // Copyright (c) 2006 Mainsoft Co.
4 // Permission is hereby granted, free of charge, to any person obtaining
5 // a copy of this software and associated documentation files (the
6 // "Software"), to deal in the Software without restriction, including
7 // without limitation the rights to use, copy, modify, merge, publish,
8 // distribute, sublicense, and/or sell copies of the Software, and to
9 // permit persons to whom the Software is furnished to do so, subject to
10 // the following conditions:
12 // The above copyright notice and this permission notice shall be
13 // included in all copies or substantial portions of the Software.
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 using System.Data.OracleClient;
28 using MonoTests.System.Data.Utils;
30 using MonoTests.System.Data.Utils.Data;
32 using NUnit.Framework;
34 namespace MonoTests.System.Data.OracleClient
37 public class OracleDataReader_GetValue : ADONetTesterClass
46 base.PrepareDataForTesting(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
48 con = new OracleConnection(MonoTests.System.Data.Utils.ConnectedDataProvider.ConnectionString);
49 Result = new char[100];
54 public void TearDown()
56 if (con.State == ConnectionState.Open) con.Close();
59 public static void Main()
61 OracleDataReader_GetValue tc = new OracleDataReader_GetValue();
65 tc.BeginTest("OracleDataReader_GetValue");
83 TypesTests(ConnectedDataProvider.GetSimpleDbTypesParameters());
84 TypesTests(ConnectedDataProvider.GetExtendedDbTypesParameters());
88 public void SimpleTest()
90 OracleDataReader rdr = null;
94 BeginCase("check value");
96 OracleCommand cmd = new OracleCommand("Select LastName From Employees Where EmployeeID = 100", con);
97 rdr = cmd.ExecuteReader();
100 Object obj = rdr.GetValue(0);
101 Compare(obj.ToString(), "Last100");
117 private void TypesTests(DbTypeParametersCollection typesToTest)
121 DbTypeParametersCollection currentlyTested = new DbTypeParametersCollection(typesToTest.TableName);
122 string rowId = "13289";
124 OracleDataReader rdr = null;
125 OracleConnection selectCon = null;
126 DataBaseServer testedDbServer = ConnectedDataProvider.GetDbType();
128 foreach (DbTypeParameter currentParamType in typesToTest)
130 BeginCase("Test value of db type: " + currentParamType.DbTypeName);
132 rowId = string.Format("13289_{0}", this.TestCaseNumber);
133 currentlyTested.Clear();
134 currentlyTested.Add(currentParamType);
135 currentlyTested.ExecuteInsert(rowId);
139 currentlyTested.ExecuteSelectReader(rowId, out rdr, out selectCon);
141 dbValue = WorkaroundOracleCharsPaddingLimitation(testedDbServer, currentParamType, rdr.GetValue(0));
142 if (currentParamType.Value.GetType().IsArray)
144 Compare(dbValue as Array, currentParamType.Value as Array);
148 Compare(dbValue, currentParamType.Value);
159 if (rdr != null && !rdr.IsClosed)
163 if (selectCon != null && selectCon.State != ConnectionState.Closed)
167 currentlyTested.ExecuteDelete(rowId);
172 /// This is a workaround for the extra white spaces added in oracle to NCHAR & NVARCHAR values.
173 /// The problem is a documented GH limitation, see bug #3417.
174 /// The workaround is to trim the lemgth of the returned string to the specified length of the parameter/column.
176 /// <param name="testedServer">The database server we are currently running on.</param>
177 /// <param name="val">The value returned from the database.</param>
178 /// <returns>The normalized value..</returns>
179 private object WorkaroundOracleCharsPaddingLimitation(DataBaseServer testedServer, DbTypeParameter currentParam, object val)
181 object origVal = val;
182 string dbTypeName = currentParam.DbTypeName.ToUpper();
183 if ( (testedServer == DataBaseServer.Oracle) && (dbTypeName == "CHAR" || dbTypeName == "NCHAR") )
185 val = ((string)val).Substring(0, currentParam.Size);
186 Log(string.Format("Worked around oracle chars padding limitation by triming '{0}' to '{1}'", origVal, val));