diff options
Diffstat (limited to 'mcs/class/System.Data/System.Data.Odbc')
6 files changed, 45 insertions, 142 deletions
diff --git a/mcs/class/System.Data/System.Data.Odbc/ChangeLog b/mcs/class/System.Data/System.Data.Odbc/ChangeLog index e633dabdd9d..d8581c1975b 100644 --- a/mcs/class/System.Data/System.Data.Odbc/ChangeLog +++ b/mcs/class/System.Data/System.Data.Odbc/ChangeLog @@ -1,47 +1,3 @@ -2004-08-31 Umadevi S (sumadevi@novell.com) - * OdbcDataReader.cs - Fixed Decimal parsing - - -2004-08-30 Umadevi S (sumadevi@novell.com) - * OdbcType.cs - removed inheritance from short. - -2004-08-27 Sureshkumar T (tsureshkumar@novell.com) - * OdbcDataReader.cs - fixed bug #63539 - TINYINT ODBC datatype is converted into System.Byte - -2004-08-26 Sureshkumar T (tsureshkumar@novell.com) - * OdbcDataReader.cs - Date & DateTime GetValue fixed. - GetBytes ordinal parameter passing fixed for BINARY in GetValue. - -2004-08-20 Sureshkumar T (tsureshkumar@novell.com) - * OdbcConnection.cs - correct handles are passed to OdbcError exception to trap the correct error - -2004-08-04 Umadevi S (sumadevi@novell.com) - * OdbcDataReader.cs - Fixed bug 61832 - Column names were not filled, due to which name based lookup of columns failed. - -2004-08-04 Umadevi S (sumadevi@novell.com) - * OdbcDataReader.cs - Fixed bug 61405 - Handling smallint column type. - -2004-07-30 Sureshkumar T (tsureshkumar@novell.com) - * OdbcCommand.cs: ExecuteNonQuery Closed statement handle to fix memory leak - * OdbcDataReader.cs: Closed statement handle to fix memory leak - Removed SQLState login in GetBytes coz OdbcError provides the same. - -2004-07-29 Umadevi S (sumadevi@novell.com) - * OdbcCommand.cs - Fixed bug 62046. ExecuteNonQuery implemented correctly - -2004-07-28 Umadevi S (sumadevi@novell.com) - * OdbcParameter.cs - fixed bug 61968. String values passed with quotes - -2004-07-07 Umadevi S (sumadevi@novell.com) - * OdbcConnection.cs - Allowed Close to be called multiple times - - Implementation of Dispose method - -2004-07-07 Umadevi S (sumadevi@novell.com) - * OdbcCommand.cs : fixed set method for Transaction - -2004-07-01 Sureshkumar T (tsureshkumar@novell.com) - * OdbcCommand.cs : fixed reader problem with ExecuteScalar - 2004-06-23 Sureshkumar T (tsureshkumar@novell.com) * OdbcConnection.cs: Fix: Moved env allocation to Open method. Disconnection & freeing handles are done in Close diff --git a/mcs/class/System.Data/System.Data.Odbc/OdbcCommand.cs b/mcs/class/System.Data/System.Data.Odbc/OdbcCommand.cs index 64c4fcfe661..fe242f3bf8f 100644 --- a/mcs/class/System.Data/System.Data.Odbc/OdbcCommand.cs +++ b/mcs/class/System.Data/System.Data.Odbc/OdbcCommand.cs @@ -223,14 +223,7 @@ namespace System.Data.Odbc return (IDbTransaction) Transaction;
}
set {
- if (value is OdbcTransaction) - { - Transaction = (OdbcTransaction)value; - } - else - { - throw new ArgumentException (); - } + throw new NotImplementedException ();
}
}
@@ -292,12 +285,6 @@ namespace System.Data.Odbc public int ExecuteNonQuery ()
{
- return ExecuteNonQuery (true); - }
-
- private int ExecuteNonQuery (bool freeHandle) - { - int records = 0; if (connection == null)
throw new InvalidOperationException ();
if (connection.State == ConnectionState.Closed)
@@ -305,29 +292,12 @@ namespace System.Data.Odbc // FIXME: a third check is mentioned in .NET docs
ExecSQL(CommandText);
- - // .NET documentation says that except for INSERT, UPDATE and - // DELETE where the return value is the number of rows affected - // for the rest of the commands the return value is -1. - if ((CommandText.ToUpper().IndexOf("UPDATE")!=-1) || - (CommandText.ToUpper().IndexOf("INSERT")!=-1) || - (CommandText.ToUpper().IndexOf("DELETE")!=-1)) { - - int numrows = 0; - OdbcReturn ret = libodbc.SQLRowCount(hstmt,ref numrows); - records = numrows; - } - else - records = -1; -
- if (freeHandle && !prepared) {
- OdbcReturn ret = libodbc.SQLFreeHandle( (ushort) OdbcHandleType.Stmt, hstmt);
- if ((ret!=OdbcReturn.Success) && (ret!=OdbcReturn.SuccessWithInfo))
- throw new OdbcException(new OdbcError("SQLFreeHandle",OdbcHandleType.Stmt,hstmt));
- } - return records;
- } - +
+// if (!prepared)
+// libodbc.SQLFreeHandle( (ushort) OdbcHandleType.Stmt, hstmt);
+ return 0;
+ }
+
public void Prepare()
{
OdbcReturn ret=libodbc.SQLAllocHandle(OdbcHandleType.Stmt, Connection.hDbc, ref hstmt);
@@ -360,7 +330,7 @@ namespace System.Data.Odbc public OdbcDataReader ExecuteReader (CommandBehavior behavior)
{
- ExecuteNonQuery(false);
+ ExecuteNonQuery();
dataReader=new OdbcDataReader(this,behavior);
return dataReader;
}
@@ -372,12 +342,11 @@ namespace System.Data.Odbc public object ExecuteScalar ()
{
- object val = null;
+ object val;
OdbcDataReader reader=ExecuteReader();
try
{
- if (reader.Read ())
- val=reader[0];
+ val=reader[0];
}
finally
{
diff --git a/mcs/class/System.Data/System.Data.Odbc/OdbcConnection.cs b/mcs/class/System.Data/System.Data.Odbc/OdbcConnection.cs index b40eb86c8d2..e6bd6ff0441 100644 --- a/mcs/class/System.Data/System.Data.Odbc/OdbcConnection.cs +++ b/mcs/class/System.Data/System.Data.Odbc/OdbcConnection.cs @@ -46,7 +46,6 @@ namespace System.Data.Odbc int connectionTimeout; internal OdbcTransaction transaction; IntPtr henv=IntPtr.Zero, hdbc=IntPtr.Zero; - bool disposed = false; #endregion @@ -198,25 +197,27 @@ namespace System.Data.Odbc // disconnect ret = libodbc.SQLDisconnect (hdbc); if ( (ret!=OdbcReturn.Success) && (ret!=OdbcReturn.SuccessWithInfo)) - throw new OdbcException (new OdbcError ("SQLDisconnect", OdbcHandleType.Dbc,hdbc)); + throw new OdbcException (new OdbcError ("SQLConnect", OdbcHandleType.Dbc,hdbc)); // free handles if (hdbc != IntPtr.Zero) { ret = libodbc.SQLFreeHandle ( (ushort) OdbcHandleType.Dbc, hdbc); if ( (ret!=OdbcReturn.Success) && (ret!=OdbcReturn.SuccessWithInfo)) - throw new OdbcException (new OdbcError ("SQLFreeHandle", OdbcHandleType.Dbc,hdbc)); + throw new OdbcException (new OdbcError ("SQLConnect", OdbcHandleType.Dbc,hdbc)); } hdbc = IntPtr.Zero; if (henv != IntPtr.Zero) { ret = libodbc.SQLFreeHandle ( (ushort) OdbcHandleType.Env, henv); if ( (ret!=OdbcReturn.Success) && (ret!=OdbcReturn.SuccessWithInfo)) - throw new OdbcException (new OdbcError ("SQLFreeHandle", OdbcHandleType.Env,henv)); + throw new OdbcException (new OdbcError ("SQLConnect", OdbcHandleType.Dbc,hdbc)); } henv = IntPtr.Zero; transaction = null; } + else + throw new InvalidOperationException (); } public OdbcCommand CreateCommand () @@ -230,23 +231,10 @@ namespace System.Data.Odbc throw new NotImplementedException (); } + [MonoTODO] protected override void Dispose (bool disposing) - { - if (!this.disposed) { - try - { - // release the native unmananged resources - this.Close(); - this.disposed = true; - } - finally - { - // call Dispose on the base class - base.Dispose(disposing); - } - } - } - + { + } [MonoTODO] object ICloneable.Clone () diff --git a/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs b/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs index 61b49d55481..394963734f0 100644 --- a/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs +++ b/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs @@ -167,8 +167,25 @@ namespace System.Data.Odbc return cols[ordinal]; } + private string GetSQLState (IntPtr hstmt, ushort recNo) + { + OdbcReturn ret = OdbcReturn.Error; + short bufLength=256, txtLength=0; + int nativeError = 1; + string sqlState = "", sqlMsg = ""; + byte [] msgtxtBuffer = new byte [bufLength]; + byte [] sqlStateBuffer = new byte [bufLength]; + ret = libodbc.SQLGetDiagRec (OdbcHandleType.Stmt, hstmt, recNo, + sqlStateBuffer, ref nativeError, msgtxtBuffer, + bufLength, ref txtLength); + sqlState = Encoding.Default.GetString (sqlStateBuffer).Replace ( + (char) 0, ' ').Trim (); + return sqlState; + } + public void Close () { + // libodbc.SQLFreeHandle((ushort) OdbcHandleType.Stmt, hstmt); OdbcReturn ret=libodbc.SQLCloseCursor(hstmt); if ((ret!=OdbcReturn.Success) && (ret!=OdbcReturn.SuccessWithInfo)) @@ -179,9 +196,6 @@ namespace System.Data.Odbc if ((behavior & CommandBehavior.CloseConnection)==CommandBehavior.CloseConnection) this.command.Connection.Close(); - ret = libodbc.SQLFreeHandle( (ushort) OdbcHandleType.Stmt, hstmt);
- if ((ret!=OdbcReturn.Success) && (ret!=OdbcReturn.SuccessWithInfo)) - throw new OdbcException(new OdbcError("SQLFreeHandle",OdbcHandleType.Stmt,hstmt)); } ~OdbcDataReader () @@ -217,10 +231,6 @@ namespace System.Data.Odbc if ( (ret != OdbcReturn.Success) && (ret != OdbcReturn.SuccessWithInfo)) throw new OdbcException (new OdbcError ("SQLGetData", OdbcHandleType.Stmt, hstmt)); - OdbcError odbcErr = null; - if ( (ret == OdbcReturn.SuccessWithInfo)) - odbcErr = new OdbcError ("SQLGetData", OdbcHandleType.Stmt, hstmt); - if (buffer == null) return outsize; //if buffer is null,return length of the field @@ -231,10 +241,11 @@ namespace System.Data.Odbc copyBuffer = false; returnVal = -1; } else { - string sqlstate = odbcErr.SQLState; + string sqlstate = GetSQLState (hstmt, 1); //SQLState: String Data, Right truncated if (sqlstate != libodbc.SQLSTATE_RIGHT_TRUNC) - throw new OdbcException ( odbcErr); + throw new OdbcException (new OdbcError ("SQLGetData", + OdbcHandleType.Stmt, hstmt)); copyBuffer = true; } } else { @@ -389,6 +400,7 @@ namespace System.Data.Odbc for (int i = 0; i < cols.Length; i += 1 ) { OdbcColumn col=GetColumn(i); + //Console.WriteLine("{0}:{1}:{2}",col.ColumnName,col.DataType,col.OdbcType); schemaRow = dataTableSchema.NewRow (); dataTableSchema.Rows.Add (schemaRow); @@ -473,23 +485,14 @@ namespace System.Data.Odbc bufsize=50; buffer=new byte[bufsize]; // According to sqlext.h, use SQL_CHAR for decimal ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Char, buffer, bufsize, ref outsize); - byte[] temp = new byte[outsize]; - for (int i=0;i<outsize;i++) - temp[i]=buffer[i]; - if (outsize!=-1) - DataValue=Decimal.Parse(System.Text.Encoding.Default.GetString(temp)); + DataValue=Decimal.Parse(System.Text.Encoding.Default.GetString(buffer)); break; case OdbcType.TinyInt: short short_data=0; ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.TinyInt, ref short_data, 0, ref outsize); - DataValue = System.Convert.ToByte (short_data); + DataValue=short_data; break; - case OdbcType.SmallInt: - short sint_data=0; - ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.SmallInt, ref sint_data, 0, ref outsize); - DataValue=sint_data; - break; case OdbcType.Int: int int_data=0; ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Int, ref int_data, 0, ref outsize); @@ -521,17 +524,8 @@ namespace System.Data.Odbc break; case OdbcType.Timestamp: case OdbcType.DateTime: - case OdbcType.Date: - case OdbcType.Time: OdbcTimestamp ts_data=new OdbcTimestamp(); - if (col.OdbcType == OdbcType.Timestamp) - ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Timestamp, ref ts_data, 0, ref outsize); - else if (col.OdbcType == OdbcType.DateTime) - ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.DateTime, ref ts_data, 0, ref outsize); - else if (col.OdbcType == OdbcType.Date) - ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Date, ref ts_data, 0, ref outsize); - else // FIXME: how to get TIME datatype ?? - ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.DateTime, ref ts_data, 0, ref outsize); + ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.DateTime, ref ts_data, 0, ref outsize); if (outsize!=-1) // This means SQL_NULL_DATA DataValue=new DateTime(ts_data.year,ts_data.month,ts_data.day,ts_data.hour, ts_data.minute,ts_data.second,Convert.ToInt32(ts_data.fraction)); @@ -540,11 +534,12 @@ namespace System.Data.Odbc case OdbcType.Image : bufsize = col.MaxLength + 1; buffer = new byte [bufsize]; - long read = GetBytes (ordinal, 0, buffer, 0, bufsize); + long read = GetBytes (ColIndex, 0, buffer, 0, bufsize); ret = OdbcReturn.Success; DataValue = buffer; break; default: + //Console.WriteLine("Fetching unsupported data type as string: "+col.OdbcType.ToString()); bufsize=255; buffer=new byte[bufsize]; ret=libodbc.SQLGetData(hstmt, ColIndex, OdbcType.Char, buffer, bufsize, ref outsize); @@ -617,8 +612,6 @@ namespace System.Data.Odbc currentRow=-1; else currentRow++; - GetSchemaTable(); - // Clear cached values from last record foreach (OdbcColumn col in cols) { diff --git a/mcs/class/System.Data/System.Data.Odbc/OdbcParameter.cs b/mcs/class/System.Data/System.Data.Odbc/OdbcParameter.cs index 11153197ca7..51df821d86f 100644 --- a/mcs/class/System.Data/System.Data.Odbc/OdbcParameter.cs +++ b/mcs/class/System.Data/System.Data.Odbc/OdbcParameter.cs @@ -261,9 +261,6 @@ namespace System.Data.Odbc string paramValueString = ParamValue.ToString();
// Treat everything else as a string
// Init string buffer
- if (ParamValue is String) - paramValueString = "\'"+paramValueString+"\'"; - if (buffer == null || buffer.Length < ((size > 20) ? size : 20))
buffer = new byte[(size > 20) ? size : 20];
else
diff --git a/mcs/class/System.Data/System.Data.Odbc/OdbcType.cs b/mcs/class/System.Data/System.Data.Odbc/OdbcType.cs index 6e7c3169bee..fed8035a7e6 100644 --- a/mcs/class/System.Data/System.Data.Odbc/OdbcType.cs +++ b/mcs/class/System.Data/System.Data.Odbc/OdbcType.cs @@ -51,7 +51,7 @@ namespace System.Data.Odbc //#define SQL_INTERVAL 10
// could map to SmallDateTime?
- public enum OdbcType + public enum OdbcType : short
{
BigInt=-5, // SQL_BIGINT
Binary=-2, // SQL_BINARY
|