-
-//
-// 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.Collections;
-using System.Data;
-using System.Runtime.InteropServices;
-using System.Globalization;
-using System.Text;
-
-namespace IBM.Data.DB2
-{
- /// <summary>
- /// Summary description for DB2ClientDataReader.
- /// DB2ClientDataReader.
- /// </summary>
- public sealed class DB2DataReader : MarshalByRefObject, IDataReader
- {
+\r
+//\r
+// Permission is hereby granted, free of charge, to any person obtaining\r
+// a copy of this software and associated documentation files (the\r
+// "Software"), to deal in the Software without restriction, including\r
+// without limitation the rights to use, copy, modify, merge, publish,\r
+// distribute, sublicense, and/or sell copies of the Software, and to\r
+// permit persons to whom the Software is furnished to do so, subject to\r
+// the following conditions:\r
+// \r
+// The above copyright notice and this permission notice shall be\r
+// included in all copies or substantial portions of the Software.\r
+// \r
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+//\r
+using System;\r
+using System.Collections;\r
+using System.Data;\r
+using System.Runtime.InteropServices;\r
+using System.Globalization;\r
+using System.Text;\r
+\r
+namespace IBM.Data.DB2\r
+{\r
+ /// <summary>\r
+ /// Summary description for DB2ClientDataReader.\r
+ /// DB2ClientDataReader. \r
+ /// </summary>\r
+ public sealed class DB2DataReader : MarshalByRefObject, IDataReader\r
+ {\r
private struct ColumnInfo\r
{\r
public string Colname;\r
public int Sqltype;\r
- }
-
+ }\r
+\r
private object[] _resultSet;\r
private ColumnInfo[] columnInfo;\r
private Hashtable columnsNames;\r
private CommandBehavior behavior;\r
private bool hasRows;\r
private bool skipReadOnce;\r
-
-
+ \r
+ \r
#region Constructors and destructors\r
/// <summary>\r
/// \r
}\r
\r
#endregion\r
-
+\r
private void GetFieldCountAndAffectedRows()\r
{\r
short sqlRet;\r
sqlRet = DB2CLIWrapper.SQLNumResultCols(hwndStmt, out colCount);\r
DB2ClientUtils.DB2CheckReturn(sqlRet, DB2Constants.SQL_HANDLE_STMT, hwndStmt, "DB2ClientDataReader - SQLNumResultCols", db2Conn);\r
fieldCount = colCount;\r
- }
-
- #region Properties
-
- #region Depth property
- ///
- ///Depth of nesting for the current row, need to figure out what this translates into
- ///with DB2.
- ///
- private int depth = 0;
- public int Depth
- {
- get
- {
+ }\r
+\r
+ #region Properties\r
+\r
+ #region Depth property \r
+ ///\r
+ ///Depth of nesting for the current row, need to figure out what this translates into \r
+ ///with DB2.\r
+ ///\r
+ private int depth = 0;\r
+ public int Depth\r
+ {\r
+ get\r
+ {\r
if(isClosed)\r
{\r
throw new InvalidOperationException("Reader is closed");\r
- }
- return depth;
- }
- }
- #endregion
-
- #region IsClosed property
- /// <summary>
- /// True if the reader is closed.
- /// </summary>
- private bool isClosed = true;
- public bool IsClosed
- {
- get
- {
- return isClosed;
- }
- }
- #endregion
-
- #region RecordsAffected property
- ///
- /// Number of records affected by this operation. Will be zero until we close the
- /// reader
- ///
-
- public int RecordsAffected
- {
- get
- {
- return recordsAffected;
- }
- }
- #endregion
-
- #endregion
-
- #region Methods
-
-
-
+ }\r
+ return depth;\r
+ }\r
+ }\r
+ #endregion\r
+\r
+ #region IsClosed property\r
+ /// <summary>\r
+ /// True if the reader is closed.\r
+ /// </summary>\r
+ private bool isClosed = true;\r
+ public bool IsClosed\r
+ {\r
+ get\r
+ {\r
+ return isClosed;\r
+ }\r
+ }\r
+ #endregion\r
+\r
+ #region RecordsAffected property\r
+ ///\r
+ /// Number of records affected by this operation. Will be zero until we close the \r
+ /// reader\r
+ /// \r
+ \r
+ public int RecordsAffected\r
+ {\r
+ get\r
+ {\r
+ return recordsAffected;\r
+ }\r
+ }\r
+ #endregion\r
+\r
+ #endregion\r
+\r
+ #region Methods\r
+\r
+\r
+\r
#region Close method\r
\r
public void Close()\r
Dispose(false);\r
}\r
\r
- #endregion
-
- #region GetSchemaTable
-
+ #endregion\r
+\r
+ #region GetSchemaTable \r
+\r
public DataTable GetSchemaTable()\r
{\r
if(isClosed)\r
}\r
}\r
return _schemaTable;\r
- }
- #endregion
-
- #region NextResult
-
+ }\r
+ #endregion\r
+\r
+ #region NextResult \r
+\r
public bool NextResult()\r
{\r
hasRows = false;\r
return false;\r
DB2ClientUtils.DB2CheckReturn(sqlRet, DB2Constants.SQL_HANDLE_STMT, hwndStmt, "Db2ClientDataReader - SQLMoreResults", db2Conn);\r
return true;\r
- }
- #endregion
-
- #region Read
-
-#if !NET_1_0\r
+ }\r
+ #endregion\r
+\r
+ #region Read\r
+\r
public bool HasRows\r
{\r
get\r
return hasRows;\r
}\r
}\r
-#endif
-
+\r
public bool Read()\r
{\r
if (isClosed)\r
\r
hasData = true;\r
return true;\r
- }
- #endregion
-
- #region GetColumnInfo
+ }\r
+ #endregion\r
+\r
+ #region GetColumnInfo\r
private void GetColumnInfo()\r
{\r
if(isClosed)\r
\r
\r
}\r
- }
- #endregion
-
- #region Describe/Bind/Fetch functions
- ///
- ///Broke these out so that we can use different paths for Immediate executions and Prepared executions
- /// <summary>
- /// Does the describe and bind steps for the query result set. Called for both immediate and prepared queries.
- /// </summary>
-
-/// <summary>
-/// FetchResults does what it says.
-/// </summary>
-/// <param name="dbVals"></param>
-/// <param name="sqlLen_or_IndPtr"></param>
-/// <param name="_resultSet"></param>
+ }\r
+ #endregion\r
+\r
+ #region Describe/Bind/Fetch functions\r
+ ///\r
+ ///Broke these out so that we can use different paths for Immediate executions and Prepared executions\r
+ /// <summary>\r
+ /// Does the describe and bind steps for the query result set. Called for both immediate and prepared queries. \r
+ /// </summary>\r
+ \r
+/// <summary>\r
+/// FetchResults does what it says.\r
+/// </summary>\r
+/// <param name="dbVals"></param>\r
+/// <param name="sqlLen_or_IndPtr"></param>\r
+/// <param name="_resultSet"></param>\r
private int FieldNameLookup(DataTable _schemaTable, string name)\r
{\r
for(int i = 0; i < _schemaTable.Rows.Count; i++)\r
}\r
}\r
return -1;\r
- }
-
- #endregion
-
- #region IDataRecord Interface
- ///Code for the IDataRecord interface
- ///
- #region FieldCount
- ///
- ///
+ }\r
+ \r
+ #endregion\r
+\r
+ #region IDataRecord Interface\r
+ ///Code for the IDataRecord interface\r
+ ///\r
+ #region FieldCount\r
+ ///\r
+ ///\r
public int FieldCount\r
{\r
get\r
\r
return fieldCount;\r
}\r
- }
- #endregion
-
- #region Item accessors
+ }\r
+ #endregion\r
+\r
+ #region Item accessors\r
public object this[string name]\r
{\r
get\r
}\r
throw new NotImplementedException("Unknown SQL type " + columnInfo[col].Sqltype);\r
}\r
- }
- #endregion
-
+ }\r
+ #endregion\r
+\r
#region GetBytes\r
///\r
/// GetBytes, return a stream of bytes\r
// TODO: need better implementation for big BLOBs\r
\r
byte[] sourceArray = (byte[])this[col];\r
-#if NET_1_0\r
- if(buffer == null)\r
- {\r
- Array.Copy(sourceArray, (int)fieldOffset, buffer, bufferOffset, length);\r
- }\r
- return sourceArray.Length;\r
-#else\r
if(buffer == null)\r
{\r
Array.Copy(sourceArray, fieldOffset, buffer, bufferOffset, length);\r
}\r
return sourceArray.LongLength;\r
-#endif\r
}\r
- #endregion
-
+ #endregion\r
+\r
#region GetChars\r
///\r
///GetChars, returns char array\r
}\r
return (long)sourceString.Length;\r
}\r
- #endregion
-
- #region GetBoolean method
-
+ #endregion\r
+\r
+ #region GetBoolean method\r
+\r
public Boolean GetBoolean(int col)\r
{\r
return (Boolean)GetBooleanInternal(col);\r
}\r
} \r
return _resultSet[col];\r
- }
- #endregion
-
+ }\r
+ #endregion\r
+\r
#region GetGuid\r
///\r
/// GetDateTime method\r
return _resultSet[col];\r
}\r
\r
- #endregion
-
- #region GetByte
- ///
- ///GetByte
- ///
+ #endregion\r
+\r
+ #region GetByte\r
+ ///\r
+ ///GetByte\r
+ ///\r
public Byte GetByte(int col)\r
{\r
return (Byte)GetByteInternal(col);\r
}\r
} \r
return _resultSet[col];\r
- }
- #endregion
-
- #region GetChar
- ///
- ///GetChar, return column as a char
- ///
+ }\r
+ #endregion\r
+\r
+ #region GetChar\r
+ ///\r
+ ///GetChar, return column as a char\r
+ ///\r
public Char GetChar(int col)\r
{\r
return (Char)GetCharInternal(col);\r
}\r
} \r
return _resultSet[col];\r
- }
- #endregion
-
- #region GetData
- ///
- /// GetData method
- ///
- public IDataReader GetData(int col)
- {
- //Have to research this one, not quite sure what the docs mean
- //DB2 does have some structured data types, is that what this is for?
- throw new NotSupportedException();
- }
- #endregion
-
- #region GetDataTypeName
- ///
- ///GetDataTypeName return the type of data
- ///
+ }\r
+ #endregion\r
+\r
+ #region GetData\r
+ ///\r
+ /// GetData method\r
+ /// \r
+ public IDataReader GetData(int col)\r
+ {\r
+ //Have to research this one, not quite sure what the docs mean\r
+ //DB2 does have some structured data types, is that what this is for?\r
+ throw new NotSupportedException();\r
+ }\r
+ #endregion\r
+\r
+ #region GetDataTypeName\r
+ ///\r
+ ///GetDataTypeName return the type of data\r
+ ///\r
public string GetDataTypeName(int col)\r
{\r
if(columnInfo == null)\r
return "VARBINARY";\r
}\r
throw new NotImplementedException("Unknown SQL type " + columnInfo[col].Sqltype);\r
- }
- #endregion
-
- #region GetDateTime
- ///
- /// GetDateTime method
- ///
-
+ }\r
+ #endregion\r
+\r
+ #region GetDateTime\r
+ ///\r
+ /// GetDateTime method\r
+ /// \r
+\r
public DateTime GetDateTime(int col)\r
{\r
return (DateTime)GetDateTimeInternal(col);\r
}\r
} \r
return _resultSet[col];\r
- }
- #endregion
-
+ }\r
+ #endregion\r
+\r
#region GetDate\r
///\r
/// GetDate method\r
return _resultSet[col];\r
}\r
\r
- #endregion
-
+ #endregion\r
+\r
#region GetTime\r
///\r
/// GetTime method\r
return _resultSet[col];\r
}\r
\r
- #endregion
-
-
- #region GetDecimal
- ///
- ///GetDecimal method
- ///
+ #endregion\r
+\r
+\r
+ #region GetDecimal\r
+ ///\r
+ ///GetDecimal method\r
+ ///\r
\r
public Decimal GetDecimal(int col)\r
{\r
// }\r
// } \r
return _resultSet[col];\r
- }
- #endregion
-
- #region GetDouble
- ///
- /// GetDouble
- ///
+ }\r
+ #endregion\r
+\r
+ #region GetDouble \r
+ ///\r
+ /// GetDouble \r
+ /// \r
public Double GetDouble(int col)\r
{\r
return (Double)GetDoubleInternal(col);\r
}\r
} \r
return _resultSet[col];\r
- }
- #endregion
-
- #region GetFieldType
- ///
- /// Type GetFieldType
- ///
+ }\r
+ #endregion\r
+\r
+ #region GetFieldType\r
+ ///\r
+ /// Type GetFieldType\r
+ ///\r
public Type GetFieldType(int col)\r
{\r
if(columnInfo == null)\r
GetColumnInfo();\r
}\r
return GetManagedType(columnInfo[col].Sqltype);\r
- }
- #endregion
-
- #region GetFloat
- ///
- /// GetFloat
- ///
+ }\r
+ #endregion\r
+\r
+ #region GetFloat\r
+ ///\r
+ /// GetFloat\r
+ /// \r
public float GetFloat(int col)\r
{\r
return (float)GetFloatInternal(col);\r
}\r
} \r
return _resultSet[col];\r
- }
- #endregion
-
- #region The GetInt?? series
- ///
- ///GetInt16
- ///
+ }\r
+ #endregion\r
+\r
+ #region The GetInt?? series\r
+ ///\r
+ ///GetInt16\r
+ ///\r
public short GetInt16(int col)\r
{\r
return (short)GetInt16Internal(col);\r
} \r
return _resultSet[col];\r
}\r
-
- #endregion
-
- #region GetName
- ///
- ///GetName, returns the name of the field
- ///
+\r
+ #endregion\r
+\r
+ #region GetName\r
+ ///\r
+ ///GetName, returns the name of the field\r
+ ///\r
public string GetName(int col)\r
{\r
if(columnInfo == null)\r
GetColumnInfo();\r
}\r
return columnInfo[col].Colname;\r
- }
- #endregion
-
- #region GetOrdinal
- ///
- /// GetOrdinal, return the index of the named column
- ///
+ }\r
+ #endregion\r
+\r
+ #region GetOrdinal\r
+ ///\r
+ /// GetOrdinal, return the index of the named column\r
+ /// \r
public int GetOrdinal(string name)\r
{\r
if(columnInfo == null)\r
throw new IndexOutOfRangeException("name");\r
}\r
return (int)ordinal;\r
- }
- #endregion
-
- #region GetString
- ///
- /// GetString returns a string
- ///
+ }\r
+ #endregion\r
+\r
+ #region GetString\r
+ ///\r
+ /// GetString returns a string\r
+ /// \r
public string GetString(int col)\r
{\r
return (string)GetStringInternal(col);\r
}\r
} \r
return _resultSet[col];\r
- }
- #endregion
-
- #region GetValue
- ///
- /// GetVCalue, returns an object
- ///
- public object GetValue(int col)
- {
- return this[col];
- }
- #endregion
-
- #region GetValues
- ///
- /// GetValues returns all columns in the row through the argument, and the number of columns in the return value
- ///
+ }\r
+ #endregion\r
+\r
+ #region GetValue\r
+ ///\r
+ /// GetVCalue, returns an object\r
+ /// \r
+ public object GetValue(int col)\r
+ {\r
+ return this[col];\r
+ }\r
+ #endregion\r
+\r
+ #region GetValues\r
+ ///\r
+ /// GetValues returns all columns in the row through the argument, and the number of columns in the return value\r
+ /// \r
public int GetValues(object[] values)\r
{\r
int count = Math.Min(fieldCount, values.Length);\r
}\r
\r
return count;\r
- }
- #endregion
-
- #region IsDBNull
- ///
- /// IsDBNull Is the column null
- ///
+ }\r
+ #endregion\r
+\r
+ #region IsDBNull\r
+ ///\r
+ /// IsDBNull Is the column null\r
+ /// \r
public bool IsDBNull(int col)\r
{\r
//Proper implementation once I get the SQLDescribe/SQLBind/SQLFetch stuff in place\r
return Convert.IsDBNull(this[col]);\r
- }
- #endregion
-
- #endregion ///For IDataRecord
-
- #region private methods
-
+ }\r
+ #endregion\r
+\r
+ #endregion ///For IDataRecord\r
+\r
+ #region private methods\r
+ \r
private DataTable BuildNewSchemaTable()\r
{\r
DataTable schemaTable = new DataTable("SchemaTable");\r
schemaTable.Columns.Add(new DataColumn("BaseColumnName", typeof(string)));\r
\r
return schemaTable;\r
- }
- #endregion
-
- private void InitMem(int memSize, ref IntPtr ptr){
- if (ptr.ToInt32() == 0){
- unsafe{
- fixed(byte* arr = new byte[memSize]){
- ptr = new IntPtr(arr);
- }
- }
- }
- }
-
+ }\r
+ #endregion\r
+ \r
+ private void InitMem(int memSize, ref IntPtr ptr){\r
+ if (ptr.ToInt32() == 0){\r
+ unsafe{\r
+ fixed(byte* arr = new byte[memSize]){\r
+ ptr = new IntPtr(arr); \r
+ }\r
+ }\r
+ } \r
+ }\r
+ \r
private Type GetManagedType(int sql_type)\r
{\r
switch(sql_type)\r
return typeof(byte[]);\r
}\r
throw new NotImplementedException("Unknown SQL type " + sql_type);\r
- }
-
+ }\r
+ \r
private bool IsLong(short sql_type)\r
{\r
switch(sql_type)\r
return true;\r
}\r
return false;\r
- }
+ }\r
private object GetBlobDataInternal(int col)\r
{\r
if((col < 0) || (col >= fieldCount))\r
}\r
} \r
return _resultSet[col];\r
- }
- }
-
-}
-#endregion
+ }\r
+ }\r
+\r
+}\r
+#endregion\r