List:Internals« Previous MessageNext Message »
From:reggie Date:January 13 2005 10:44pm
Subject:bk commit - Connector/Net (1.160)
View as plain text  
ChangeSet
  1.160 05/01/13 16:40:59 reggie@monster. +11 -0
  Fixed problem with shared memory
  properly defaulting name of shared memory object to MYSQL
  added some test cases

  mysqlclient/common/Win32.cs
    1.1 05/01/13 16:40:58 reggie@monster. +91 -0

  mysqlclient/common/Win32.cs
    1.0 05/01/13 16:40:58 reggie@monster. +0 -0
    BitKeeper file D:/Work/connector-net/mysqlclient/common/Win32.cs

  mysqlclient/common/NamedPipeStream.cs
    1.10 05/01/13 16:40:58 reggie@monster. +94 -59
    moved the interop stuff to win32.cs

  mysqlclient/SharedMemoryStream.cs
    1.4 05/01/13 16:40:58 reggie@monster. +6 -5
    do not timeout the WaitOne

  mysqlclient/Driver.cs
    1.25 05/01/13 16:40:58 reggie@monster. +2 -0
    forgot and left the braces in

  mysqlclient/ConnectionString.cs
    1.28 05/01/13 16:40:58 reggie@monster. +1 -0
    properly default memory name to MYSQL

  TestSuite/Syntax.cs
    1.27 05/01/13 16:40:58 reggie@monster. +4 -2
    Added MEDIUMTEXT column to test a bug report

  TestSuite/StressTests.cs
    1.12 05/01/13 16:40:57 reggie@monster. +1 -1
    whitespace junk

  TestSuite/DataReaderTests.cs
    1.39 05/01/13 16:40:57 reggie@monster. +0 -27
    removed because this functionality because we now do conversions

  TestSuite/BaseTest.cs
    1.17 05/01/13 16:40:57 reggie@monster. +3 -2
    now supporting the otherkeys element to specify protocol

  MySql.Data.csproj
    1.65 05/01/13 16:40:57 reggie@monster. +5 -0
    Added the Win32 file to house interop definitions

  CHANGES
    1.67 05/01/13 16:40:57 reggie@monster. +2 -0
    updated

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	reggie
# Host:	monster.
# Root:	D:/Work/connector-net

--- 1.64/MySql.Data.csproj	2004-12-10 21:18:12 -06:00
+++ 1.65/MySql.Data.csproj	2005-01-13 16:40:57 -06:00
@@ -283,6 +283,11 @@
                     BuildAction = "Compile"
                 />
                 <File
+                    RelPath = "MySqlClient\common\Win32.cs"
+                    SubType = "Code"
+                    BuildAction = "Compile"
+                />
+                <File
                     RelPath = "MySqlClient\docs\MySqlCommand.xml"
                     BuildAction = "Content"
                 />

--- 1.9/mysqlclient/common/NamedPipeStream.cs	2004-12-13 22:33:44 -06:00
+++ 1.10/mysqlclient/common/NamedPipeStream.cs	2005-01-13 16:40:58 -06:00
@@ -20,7 +20,6 @@
 
 using System;
 using System.IO;
-using System.Runtime.InteropServices;
 
 
 namespace MySql.Data.Common
@@ -30,50 +29,14 @@
 	/// </summary>
 	internal class NamedPipeStream : Stream
 	{
-		[DllImport("kernel32.dll")]
-		private static extern uint GetLastError();
 
-		[DllImport("kernel32.dll", EntryPoint="CreateFile", SetLastError=true)]
-		private static extern IntPtr CreateFile(String lpFileName, 
-			UInt32 dwDesiredAccess, UInt32 dwShareMode,
-			IntPtr lpSecurityAttributes, UInt32 dwCreationDisposition, 
-			UInt32 dwFlagsAndAttributes,
-			IntPtr hTemplateFile);
-		[DllImport("kernel32.dll", EntryPoint="PeekNamedPipe", SetLastError=true)]
-		private static extern bool PeekNamedPipe( IntPtr handle,
-			byte[] buffer, uint nBufferSize, ref uint bytesRead,
-			ref uint bytesAvail, ref uint BytesLeftThisMessage);
-		[DllImport("kernel32.dll", SetLastError=true)]
-		private static extern bool ReadFile( IntPtr handle,
-			byte[] buffer, uint toRead, ref uint read, IntPtr lpOverLapped);
-		[DllImport("kernel32.dll", SetLastError=true)]
-		private static extern bool WriteFile( IntPtr handle,
-			IntPtr buffer, uint count, ref uint written, IntPtr lpOverlapped );
-		[DllImport("kernel32.dll", SetLastError=true)]
-		private static extern bool CloseHandle( IntPtr handle );
-		[DllImport("kernel32.dll", SetLastError=true)]
-		private static extern bool FlushFileBuffers( IntPtr handle );
-
-		//Constants for dwDesiredAccess:
-		private const UInt32 GENERIC_READ = 0x80000000;
-		private const UInt32 GENERIC_WRITE = 0x40000000;
-
-		//Constants for return value:
-		private const Int32 INVALID_HANDLE_VALUE = -1;
-
-		//Constants for dwFlagsAndAttributes:
-		private const UInt32 FILE_FLAG_OVERLAPPED = 0x40000000;
-		private const UInt32 FILE_FLAG_NO_BUFFERING = 0x20000000;
-
-		//Constants for dwCreationDisposition:
-		private const UInt32 OPEN_EXISTING = 3;
-
-		IntPtr		_handle;
+		int			pipeHandle;
+		FileStream	stream;
 		FileAccess	_mode;
 
 		public NamedPipeStream(string host, FileAccess mode)
 		{
-			_handle = IntPtr.Zero;
+			pipeHandle = 0;
 			Open(host, mode);
 		}
 
@@ -83,11 +46,21 @@
 			uint pipemode = 0;
 
 			if ((mode & FileAccess.Read) > 0)
-				pipemode |= GENERIC_READ;
+				pipemode |= Win32.GENERIC_READ;
 			if ((mode & FileAccess.Write) > 0)
-				pipemode |= GENERIC_WRITE;
-			_handle = CreateFile( host, pipemode,
-				0, IntPtr.Zero, OPEN_EXISTING, 0, IntPtr.Zero );
+				pipemode |= Win32.GENERIC_WRITE;
+
+			pipeHandle = Win32.CreateFile( host, pipemode,
+						0, null, Win32.OPEN_EXISTING, 0, 0 );
+//			try 
+//			{
+//				stream = new FileStream( (IntPtr)pipeHandle, FileAccess.ReadWrite );
+//			}
+//			catch (Exception ex) 
+//			{
+//				Console.WriteLine( ex.Message );
+//			}
+
 		}
 
 		public bool DataAvailable
@@ -96,7 +69,7 @@
 			{
 				uint bytesRead=0, avail=0, thismsg=0;
 
-				bool result = PeekNamedPipe( _handle, 
+				bool result = Win32.PeekNamedPipe( pipeHandle, 
 					null, 0, ref bytesRead, ref avail, ref thismsg );
 				return (result == true && avail > 0);
 			}
@@ -130,13 +103,31 @@
 
 		public override void Flush() 
 		{
-			if (_handle == IntPtr.Zero)
+//			if (stream != null)
+//				stream.Flush();
+			if ( pipeHandle == 0 )
 				throw new ObjectDisposedException("NamedPipeStream", "The stream has already been closed");
-			FlushFileBuffers(_handle);
+			Win32.FlushFileBuffers(pipeHandle);
 		}
 
 		public override int Read(byte[] buffer, int offset, int count)
 		{
+/*			try 
+			{
+				uint bytesRead=0, avail=0, thismsg=0;
+
+				bool result = Win32.PeekNamedPipe( pipeHandle, 
+					null, 0, ref bytesRead, ref avail, ref thismsg );
+				if (result)
+					return stream.Read( buffer, offset, (int)avail );
+				else
+					return -1;
+			}
+			catch (Exception ex) 
+			{
+				Console.WriteLine(ex.Message);
+			}
+			return -1;*/
 			if (buffer == null) 
 				throw new ArgumentNullException("buffer", "The buffer to read into cannot be null");
 			if (buffer.Length < (offset + count))
@@ -147,14 +138,14 @@
 				throw new ArgumentOutOfRangeException("count", count, "Count cannot be negative");
 			if (! CanRead)
 				throw new NotSupportedException("The stream does not support reading");
-			if (_handle == IntPtr.Zero)
+			if (pipeHandle == 0)
 				throw new ObjectDisposedException("NamedPipeStream", "The stream has already been closed");
 
 			// first read the data into an internal buffer since ReadFile cannot read into a buf at
 			// a specified offset
 			uint read=0;
 			byte[] buf = new Byte[count];
-			ReadFile( _handle, buf, (uint)count, ref read, IntPtr.Zero );
+			Win32.ReadFile( pipeHandle, buf, (uint)count, out read, null );
 			
 			for (int x=0; x < read; x++) 
 			{
@@ -165,8 +156,10 @@
 
 		public override void Close()
 		{
-			CloseHandle(_handle);
-			_handle = IntPtr.Zero;
+//			stream.Close();
+			//stream = null;
+			Win32.CloseHandle(pipeHandle);
+			pipeHandle = 0;
 		}
 
 		public override void SetLength(long length)
@@ -176,6 +169,14 @@
 
 		public override void Write(byte[] buffer, int offset, int count)
 		{
+//			try 
+//			{
+//				stream.Write( buffer, offset, count );
+//			}
+//			catch (Exception ex) 
+//			{
+//				Console.WriteLine( ex.Message );
+//			}
 			if (buffer == null) 
 				throw new ArgumentNullException("buffer", "The buffer to write into cannot be null");
 			if (buffer.Length < (offset + count))
@@ -186,27 +187,61 @@
 				throw new ArgumentOutOfRangeException("count", count, "Count cannot be negative");
 			if (! CanWrite)
 				throw new NotSupportedException("The stream does not support writing");
-			if (_handle == IntPtr.Zero)
+			if (pipeHandle == 0)
 				throw new ObjectDisposedException("NamedPipeStream", "The stream has already been closed");
 			
 			// copy data to internal buffer to allow writing from a specified offset
+			uint bytesWritten = 0;
+			bool result;
+
+			if (offset == 0  && count <= 65535)
+				result = Win32.WriteFile( pipeHandle, buffer, (uint)count, out bytesWritten, null );
+			else
+			{
+				byte[] localBuf = new byte[65535];
+
+				result = true;
+				uint thisWritten;
+				while (count != 0 && result)
+				{
+					int cnt = Math.Min( count, 65535 );
+					Array.Copy( buffer, offset, localBuf, 0, cnt );
+					result = Win32.WriteFile( pipeHandle, localBuf, (uint)cnt, out thisWritten, null );
+					bytesWritten += thisWritten;
+					count -= cnt;
+					offset += cnt;
+				}
+
+//				byte[] tempBuf = new byte[count];
+//				try 
+//				{
+//					Array.Copy( buffer, offset, tempBuf, 0, count );
+//				}
+//				catch (Exception ex) 
+//				{
+//					Console.Write(ex.Message);
+//				}
+//				localBuf = tempBuf;
+			}
+
+//			bool result = Win32.WriteFile( pipeHandle, localBuf, (uint)count, out bytesWritten, null );
 //			byte[] buf = new Byte[count];
 //			for (int x=0; x < count; x++) 
 //			{
 //				buf[x] = buffer[offset+x];
 //			}
-			uint written=0;
-			GCHandle h = GCHandle.Alloc( buffer, GCHandleType.Pinned );
-			IntPtr addr = Marshal.UnsafeAddrOfPinnedArrayElement( buffer, offset );
-			bool result = WriteFile( _handle, addr, (uint)count, ref written, IntPtr.Zero );
-			h.Free();
+//			uint written=0;
+//			GCHandle h = GCHandle.Alloc( buffer, GCHandleType.Pinned );
+//			IntPtr addr = Marshal.UnsafeAddrOfPinnedArrayElement( buffer, offset );
+//			bool result = WriteFile( pipeHandle, addr, (uint)count, ref written, IntPtr.Zero );
+//			h.Free();
 
 			if (! result)
 			{
-				uint err = GetLastError();
+				uint err = Win32.GetLastError();
 				throw new IOException("Writing to the stream failed");
 			}
-			if (written < count)
+			if (bytesWritten < count)
 				throw new IOException("Unable to write entire buffer to stream");
 		}
 

--- 1.27/mysqlclient/ConnectionString.cs	2004-12-09 14:29:03 -06:00
+++ 1.28/mysqlclient/ConnectionString.cs	2005-01-13 16:40:58 -06:00
@@ -329,6 +329,7 @@
 				defaults["logging"] = false;
 				defaults["oldsyntax"] = false;
 				defaults["pipeName"] = "MySQL";
+				defaults["memname"] = "MYSQL";
 				defaults["allowzerodatetime"] = false;
 			}
 			return (Hashtable)defaults.Clone();

--- 1.38/TestSuite/DataReaderTests.cs	2005-01-12 12:37:19 -06:00
+++ 1.39/TestSuite/DataReaderTests.cs	2005-01-13 16:40:57 -06:00
@@ -446,33 +446,6 @@
 			}
 		}
 
-		[Test()]
-		public void InvalidCasts() 
-		{
-			execSQL( "INSERT INTO Test (id) VALUES(1)" );
-
-			MySqlCommand cmd = new MySqlCommand("SELECT id FROM test", conn);
-			MySqlDataReader reader = null;
-			try 
-			{
-				reader = cmd.ExecuteReader();
-				try 
-				{
-					reader.Read();
-					short s = reader.GetInt16(0);
-					Assert.Fail(" This should not execute" );
-				}
-				catch (InvalidCastException) { }
-			}
-			catch (Exception ex) 
-			{
-				Assert.Fail( ex.Message );
-			}
-			finally 
-			{
-				if (reader != null) reader.Close();
-			}
-		}
 
 		[Test]
 		public void ReadingTextFields() 
--- New file ---
+++ mysqlclient/common/Win32.cs	05/01/13 16:40:58
using System;
using System.Runtime.InteropServices;

namespace MySql.Data.Common
{
	/// <summary>
	/// Summary description for Win32.
	/// </summary>
	internal class Win32
	{
		[StructLayout(LayoutKind.Sequential)]
		public class SecurityAttributes 
		{
			public SecurityAttributes() 
			{
				Length = Marshal.SizeOf(typeof(SecurityAttributes));
			}
			public int Length;
			public IntPtr securityDescriptor = IntPtr.Zero;
			public bool inheritHandle = false;
		}

		[StructLayout(LayoutKind.Sequential)]
		public class Overlapped 
		{
			public IntPtr Internal;
			public IntPtr InternalHigh;
			public uint Offset;
			public uint OffsetHigh;
			public IntPtr Event;
		}

		[DllImport("kernel32.dll")]
		public static extern uint GetLastError();

		[DllImport("Kernel32")]
		static extern public int CreateFile(String fileName,
			uint desiredAccess,
			uint shareMode, 
			SecurityAttributes securityAttributes,
			uint creationDisposition,
			uint flagsAndAttributes,
			uint templateFile);

		[DllImport("kernel32.dll", EntryPoint="PeekNamedPipe", SetLastError=true)]
		static extern public bool PeekNamedPipe( int handle,
			byte[] buffer, 
			uint nBufferSize, 
			ref uint bytesRead,
			ref uint bytesAvail, 
			ref uint BytesLeftThisMessage);

		[DllImport("Kernel32")]
		static extern public bool ReadFile(
			int fileHandle,            // handle to file
			byte[] buffer,				// data buffer
			uint numberOfBytesToRead,	// number of bytes to read
			out uint numberOfBytesRead,	// number of bytes read
			Overlapped overlapped		// overlapped buffer
			);

		[DllImport("Kernel32")]
		static extern public bool WriteFile(
			int fileHandle,				// handle to file
			byte[] buffer,					// data buffer
			uint numberOfBytesToWrite,		// number of bytes to write
			out uint numberOfBytesWritten,	// number of bytes written
			Overlapped overlapped			// overlapped buffer
			);

		[DllImport("kernel32.dll", SetLastError=true)]
		public static extern bool CloseHandle( int handle );

		[DllImport("kernel32.dll", SetLastError=true)]
		public static extern bool FlushFileBuffers( int handle );

		//Constants for dwDesiredAccess:
		public const UInt32 GENERIC_READ = 0x80000000;
		public const UInt32 GENERIC_WRITE = 0x40000000;

		//Constants for return value:
		public const Int32 INVALIDpipeHandle_VALUE = -1;

		//Constants for dwFlagsAndAttributes:
		public const UInt32 FILE_FLAG_OVERLAPPED = 0x40000000;
		public const UInt32 FILE_FLAG_NO_BUFFERING = 0x20000000;

		//Constants for dwCreationDisposition:
		public const UInt32 OPEN_EXISTING = 3;
	}
}


--- 1.66/CHANGES	2005-01-12 13:25:08 -06:00
+++ 1.67/CHANGES	2005-01-13 16:40:57 -06:00
@@ -7,6 +7,8 @@
 	Bug #7755	MySqlReader.GetInt32 throws exception if column is unsigned [fixed]
 	Bug #7704	GetBytes is working no more [fixed]
 	Bug #7724	Quote character \222 not quoted in EscapeString [fixed]
+	Fixed problem that causes named pipes to not work with some blob functionality
+	Fixed problem with shared memory connections
 	
 12-10-04 - Version 1.0.3-gamma
 

--- 1.16/TestSuite/BaseTest.cs	2004-12-13 22:36:53 -06:00
+++ 1.17/TestSuite/BaseTest.cs	2005-01-13 16:40:57 -06:00
@@ -52,8 +52,9 @@
 				user = ConfigurationSettings.AppSettings["user"];
 				password = ConfigurationSettings.AppSettings["password"];
 				nopassuser = ConfigurationSettings.AppSettings["nopassuser"];
-				string connString = String.Format("server={0};user id={1};password={2};database=test;persist security info=true",
-					host, user, password );
+				string other = ConfigurationSettings.AppSettings["otherkeys"];
+				string connString = String.Format("server={0};user id={1};password={2};database=test;persist security info=true;{3}",
+					host, user, password, other );
 				connString += csAdditions;
 				conn = new MySqlConnection( connString );
 				conn.Open();

--- 1.26/TestSuite/Syntax.cs	2005-01-12 13:25:08 -06:00
+++ 1.27/TestSuite/Syntax.cs	2005-01-13 16:40:58 -06:00
@@ -64,11 +64,12 @@
 		public void ProblemCharsInSQL()
 		{
 			execSQL("DROP TABLE IF EXISTS Test");
-			execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), PRIMARY KEY(id))");
+			execSQL("CREATE TABLE Test (id INT NOT NULL, name VARCHAR(250), mt MEDIUMTEXT, PRIMARY KEY(id)) CHAR SET utf8");
 
-			MySqlCommand cmd = new MySqlCommand( "INSERT INTO Test VALUES (?id, ?text)", conn);
+			MySqlCommand cmd = new MySqlCommand( "INSERT INTO Test VALUES (?id, ?text, ?mt)", conn);
 			cmd.Parameters.Add( "?id", 1 );
 			cmd.Parameters.Add( "?text", "This is my;test ? string???????" );
+			cmd.Parameters.Add( "?mt", "My MT string: ?" );
 			cmd.ExecuteNonQuery();
 
 			cmd.CommandText = "SELECT * FROM Test";
@@ -82,6 +83,7 @@
 					Assert.AreEqual( "This is my;test ? string-'''\"\".", reader.GetString(1));
 				else
 					Assert.AreEqual( "This is my;test ? string???????", reader.GetString(1));
+				Assert.AreEqual( "My MT string: ?", reader.GetString(2) );
 			}
 			catch (Exception ex) 
 			{

--- 1.3/mysqlclient/SharedMemoryStream.cs	2004-08-05 13:09:23 -05:00
+++ 1.4/mysqlclient/SharedMemoryStream.cs	2005-01-13 16:40:58 -06:00
@@ -121,7 +121,7 @@
 
 		public override bool CanSeek
 		{
-			get { throw new NotSupportedException("SharedMemoryStream does not support seeking"); }
+			get { return false; }
 		}
 
 		public override bool CanWrite
@@ -131,12 +131,12 @@
 
 		public override long Length
 		{
-			get { throw new NotSupportedException("SharedMemoryStream does not support seeking"); }
+			get { throw new NotSupportedException("SharedMemoryStream does not support seeking - length"); }
 		}
 
 		public override long Position
 		{
-			get { throw new NotSupportedException("SharedMemoryStream does not support seeking"); }
+			get { throw new NotSupportedException("SharedMemoryStream does not support seeking - postition"); }
 			set	{}
 		}
 
@@ -148,9 +148,10 @@
 
 		public override int Read(byte[] buffer, int offset, int count)
 		{
-			if (bytesLeft == 0)
+			while (bytesLeft == 0)
 			{
-				if (! serverWrote.WaitOne(100, false )) return 0;
+				if (! serverWrote.WaitOne()) 
+					return 0;
 
 				bytesLeft = Marshal.ReadInt32( dataView );
 				position = 4;

--- 1.11/TestSuite/StressTests.cs	2004-12-10 10:09:43 -06:00
+++ 1.12/TestSuite/StressTests.cs	2005-01-13 16:40:57 -06:00
@@ -136,7 +136,7 @@
 				reader.Close();
 
 				Assert.AreEqual( 8000, i2 );
-				cmd = new MySqlCommand("delete from test where id >= 100", conn);
+				cmd = new MySqlCommand("delete from Test where id >= 100", conn);
 				cmd.ExecuteNonQuery();
 			}
 			catch (Exception ex) 

--- 1.24/mysqlclient/Driver.cs	2004-12-10 15:00:44 -06:00
+++ 1.25/mysqlclient/Driver.cs	2005-01-13 16:40:58 -06:00
@@ -199,7 +199,9 @@
 				reader = cmd.ExecuteReader();
 				charSets = new Hashtable();
 				while (reader.Read()) 
+				{
 					charSets[ Convert.ToInt32(reader["id"]) ] = reader["charset"];
+				}
 			}
 			catch (Exception ex) 
 			{

Thread
bk commit - Connector/Net (1.160)reggie13 Jan