diff options
author | Sureshkumar T <suresh@mono-cvs.ximian.com> | 2004-08-02 07:50:05 +0400 |
---|---|---|
committer | Sureshkumar T <suresh@mono-cvs.ximian.com> | 2004-08-02 07:50:05 +0400 |
commit | 348b79c29a09a9938d742aea62a2798b7f4b1bb4 (patch) | |
tree | 02166495e4c480b922f00c23cac9844664889ace | |
parent | a993a4d53b7a32a44a277df0b7f4a0263f5f3482 (diff) |
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.
svn path=/branches/mono-1-0/mcs/; revision=31725
-rw-r--r-- | mcs/class/System.Data/System.Data.Odbc/ChangeLog | 5 | ||||
-rw-r--r-- | mcs/class/System.Data/System.Data.Odbc/OdbcCommand.cs | 56 | ||||
-rw-r--r-- | mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs | 31 |
3 files changed, 47 insertions, 45 deletions
diff --git a/mcs/class/System.Data/System.Data.Odbc/ChangeLog b/mcs/class/System.Data/System.Data.Odbc/ChangeLog index cafe4abf744..148d4fcba01 100644 --- a/mcs/class/System.Data/System.Data.Odbc/ChangeLog +++ b/mcs/class/System.Data/System.Data.Odbc/ChangeLog @@ -1,3 +1,8 @@ +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 diff --git a/mcs/class/System.Data/System.Data.Odbc/OdbcCommand.cs b/mcs/class/System.Data/System.Data.Odbc/OdbcCommand.cs index 3a8252809d1..64c4fcfe661 100644 --- a/mcs/class/System.Data/System.Data.Odbc/OdbcCommand.cs +++ b/mcs/class/System.Data/System.Data.Odbc/OdbcCommand.cs @@ -223,14 +223,14 @@ namespace System.Data.Odbc return (IDbTransaction) Transaction;
}
set {
- if (value is OdbcTransaction) - { - Transaction = (OdbcTransaction)value; - } - else - { - throw new ArgumentException (); - } + if (value is OdbcTransaction) + { + Transaction = (OdbcTransaction)value; + } + else + { + throw new ArgumentException (); + } }
}
@@ -292,6 +292,12 @@ 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)
@@ -299,25 +305,29 @@ namespace System.Data.Odbc // FIXME: a third check is mentioned in .NET docs
ExecSQL(CommandText);
-
-// if (!prepared)
-// libodbc.SQLFreeHandle( (ushort) OdbcHandleType.Stmt, hstmt);
- // .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) || + // .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; + + int numrows = 0; OdbcReturn ret = libodbc.SQLRowCount(hstmt,ref numrows); - return numrows; - } - else - return -1; - }
+ 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;
+ } + public void Prepare()
{
OdbcReturn ret=libodbc.SQLAllocHandle(OdbcHandleType.Stmt, Connection.hDbc, ref hstmt);
@@ -350,7 +360,7 @@ namespace System.Data.Odbc public OdbcDataReader ExecuteReader (CommandBehavior behavior)
{
- ExecuteNonQuery();
+ ExecuteNonQuery(false);
dataReader=new OdbcDataReader(this,behavior);
return dataReader;
}
diff --git a/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs b/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs index 394963734f0..70112bec219 100644 --- a/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs +++ b/mcs/class/System.Data/System.Data.Odbc/OdbcDataReader.cs @@ -167,25 +167,8 @@ 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)) @@ -196,6 +179,9 @@ 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 () @@ -231,6 +217,10 @@ 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 @@ -241,11 +231,10 @@ namespace System.Data.Odbc copyBuffer = false; returnVal = -1; } else { - string sqlstate = GetSQLState (hstmt, 1); + string sqlstate = odbcErr.SQLState; //SQLState: String Data, Right truncated if (sqlstate != libodbc.SQLSTATE_RIGHT_TRUNC) - throw new OdbcException (new OdbcError ("SQLGetData", - OdbcHandleType.Stmt, hstmt)); + throw new OdbcException ( odbcErr); copyBuffer = true; } } else { @@ -400,7 +389,6 @@ 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); @@ -539,7 +527,6 @@ namespace System.Data.Odbc 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); |