public MySqlField(Driver driver) { this.driver = driver; connVersion = driver.Version; maxLength = 1; binaryOk = true; }
public static CharacterSet GetCharacterSet(DBVersion version, string CharSetName) { CharacterSet cs = (CharacterSet) mapping[CharSetName]; if (cs == null) throw new MySqlException("Character set '" + CharSetName + "' is not supported"); return cs; }
public MySqlField(MySqlConnection connection) { this.connection = connection; connVersion = connection.driver.Version; maxLength = 1; binaryOk = true; }
public static CharacterSet GetCharacterSet(DBVersion version, string CharSetName) { CharacterSet cs = null; if(mapping.ContainsKey(CharSetName)) cs = (CharacterSet)mapping[CharSetName]; if (cs == null) throw new MySqlException("Character set '" + CharSetName + "' is not supported by .Net Framework."); return cs; }
public static Stream GetStream(string server, uint port, string pipename, uint keepalive, DBVersion v, uint timeout) { MySqlConnectionStringBuilder settings = new MySqlConnectionStringBuilder(); settings.Server = server; settings.Port = port; settings.PipeName = pipename; settings.Keepalive = keepalive; settings.ConnectionTimeout = timeout; return GetStream(settings); }
public StreamCreator(string hosts, uint port, string pipeName, uint keepalive, DBVersion driverVersion) { hostList = hosts; if (hostList == null || hostList.Length == 0) hostList = "localhost"; this.port = port; this.pipeName = pipeName; this.keepalive = keepalive; this.driverVersion = driverVersion; }
public StreamCreator(string hosts, uint port, string pipeName, uint keepalive, DBVersion driverVersion) { _hostList = hosts; if (string.IsNullOrEmpty(_hostList)) { _hostList = "localhost"; } this._port = port; this.pipeName = pipeName; this.keepalive = keepalive; this.driverVersion = driverVersion; }
public StreamCreator(string hosts, uint port, string pipeName, uint keepalive, DBVersion driverVersion) { hostList = hosts; if (hostList == null || hostList.Length == 0) { hostList = "localhost"; } this.port = port; this.pipeName = pipeName; this.keepalive = keepalive; this.driverVersion = driverVersion; }
/// <summary> /// Returns the text encoding for a given MySQL character set name /// </summary> /// <param name="version">Version of the connection requesting the encoding</param> /// <param name="CharSetName">Name of the character set to get the encoding for</param> /// <returns>Encoding object for the given character set name</returns> public static Encoding GetEncoding(DBVersion version, string CharSetName) { try { CharacterSet cs = GetCharacterSet(version, CharSetName); return Encoding.GetEncoding(cs.name); } catch (NotSupportedException) { return Encoding.GetEncoding("utf-8"); } }
static internal MySqlDateTime Parse(string s, DBVersion version) { var dt = new MySqlDateTime(); return dt.ParseMySql(s); }
public static Stream GetStream(string server, uint port, string pipename, uint keepalive, DBVersion v, uint timeout) { MySqlConnectionStringBuilder settings = new MySqlConnectionStringBuilder { Server = server, Port = port, PipeName = pipename, Keepalive = keepalive, ConnectionTimeout = timeout }; return(GetStream(settings)); }
public SSPI(string targetName, MySqlStream stream, int seqNo, DBVersion version) { this.targetName = null; this.stream = stream; packetHeader = new byte[4]; seq = seqNo; this.version = version; }
public void Open() { // connect to one of our specified hosts try { #if !CF if (Settings.ConnectionProtocol == MySqlConnectionProtocol.SharedMemory) { SharedMemoryStream str = new SharedMemoryStream(Settings.SharedMemoryName); str.Open(Settings.ConnectionTimeout); baseStream = str; } else { #endif string pipeName = Settings.PipeName; if (Settings.ConnectionProtocol != MySqlConnectionProtocol.NamedPipe) pipeName = null; StreamCreator sc = new StreamCreator(Settings.Server, Settings.Port, pipeName, Settings.Keepalive, this.Version); #if !CF if (Settings.IncludeSecurityAsserts) MySqlSecurityPermission.CreatePermissionSet(false).Assert(); #endif baseStream = sc.GetStream(Settings.ConnectionTimeout); #if !CF } #endif } catch (System.Security.SecurityException) { throw; } catch (Exception ex) { throw new MySqlException(Resources.UnableToConnectToHost, (int)MySqlErrorCode.UnableToConnectToHost, ex); } if (baseStream == null) throw new MySqlException(Resources.UnableToConnectToHost, (int)MySqlErrorCode.UnableToConnectToHost); int maxSinglePacket = 255 * 255 * 255; stream = new MySqlStream(baseStream, Encoding, false); stream.ResetTimeout((int)Settings.ConnectionTimeout * 1000); // read off the welcome packet and parse out it's values packet = stream.ReadPacket(); int protocol = packet.ReadByte(); string versionString = packet.ReadString(); version = DBVersion.Parse(versionString); if (!version.isAtLeast(5, 0, 0)) throw new NotSupportedException(Resources.ServerTooOld); threadId = packet.ReadInteger(4); encryptionSeed = packet.ReadString(); maxSinglePacket = (256 * 256 * 256) - 1; // read in Server capabilities if they are provided ClientFlags serverCaps = 0; if (packet.HasMoreData) serverCaps = (ClientFlags)packet.ReadInteger(2); /* New protocol with 16 bytes to describe server characteristics */ owner.ConnectionCharSetIndex = (int)packet.ReadByte(); serverStatus = (ServerStatusFlags)packet.ReadInteger(2); // Since 5.5, high bits of server caps are stored after status. // Previously, it was part of reserved always 0x00 13-byte filler. uint serverCapsHigh = (uint)packet.ReadInteger(2); serverCaps |= (ClientFlags)(serverCapsHigh << 16); packet.Position += 11; string seedPart2 = packet.ReadString(); encryptionSeed += seedPart2; string authenticationMethod = ""; if ((serverCaps & ClientFlags.PLUGIN_AUTH) != 0) { authenticationMethod = packet.ReadString(); } else { // Some MySql versions like 5.1, don't give name of plugin, default to native password. authenticationMethod = "mysql_native_password"; } // based on our settings, set our connection flags SetConnectionFlags(serverCaps); packet.Clear(); packet.WriteInteger((int)connectionFlags, 4); #if !CF if ((serverCaps & ClientFlags.SSL) == 0) { if ((Settings.SslMode != MySqlSslMode.None) && (Settings.SslMode != MySqlSslMode.Preferred)) { // Client requires SSL connections. string message = String.Format(Resources.NoServerSSLSupport, Settings.Server); throw new MySqlException(message); } } else if (Settings.SslMode != MySqlSslMode.None) { stream.SendPacket(packet); StartSSL(); packet.Clear(); packet.WriteInteger((int)connectionFlags, 4); } #endif packet.WriteInteger(maxSinglePacket, 4); packet.WriteByte(8); packet.Write(new byte[23]); Authenticate(authenticationMethod, false); // if we are using compression, then we use our CompressedStream class // to hide the ugliness of managing the compression if ((connectionFlags & ClientFlags.COMPRESS) != 0) stream = new MySqlStream(baseStream, Encoding, true); // give our stream the server version we are connected to. // We may have some fields that are read differently based // on the version of the server we are connected to. packet.Version = version; stream.MaxBlockSize = maxSinglePacket; }
public static Task <Stream> GetStream(string server, uint port, string pipename, uint keepalive, DBVersion v, uint timeout) { MySqlConnectionStringBuilder settings = new MySqlConnectionStringBuilder(); settings.Server = server; settings.Port = port; settings.PipeName = pipename; settings.Keepalive = keepalive; settings.ConnectionTimeout = timeout; return(GetStream(settings)); }
public void Open() { // connect to one of our specified hosts try { baseStream = StreamCreator.GetStream(Settings); //#if !CF && !RT // if (Settings.IncludeSecurityAsserts) // MySqlSecurityPermission.CreatePermissionSet(false).Assert(); //#endif } catch (System.Security.SecurityException) { throw; } catch (Exception ex) { throw new MySqlException("Resources.UnableToConnectToHost", (int)MySqlErrorCode.UnableToConnectToHost, ex); } if (baseStream == null) throw new MySqlException("Resources.UnableToConnectToHost", (int)MySqlErrorCode.UnableToConnectToHost); int maxSinglePacket = 255 * 255 * 255; stream = new MySqlStream(baseStream, Encoding, false); stream.ResetTimeout((int)Settings.ConnectionTimeout * 1000); // read off the welcome packet and parse out it's values packet = stream.ReadPacket(); int protocol = packet.ReadByte(); string versionString = packet.ReadString(); owner.isFabric = versionString.EndsWith("fabric", StringComparison.OrdinalIgnoreCase); version = DBVersion.Parse(versionString); if (!owner.isFabric && !version.isAtLeast(5, 0, 0)) throw new NotSupportedException("Resources.ServerTooOld"); threadId = packet.ReadInteger(4); byte[] seedPart1 = packet.ReadStringAsBytes(); maxSinglePacket = (256 * 256 * 256) - 1; // read in Server capabilities if they are provided ClientFlags serverCaps = 0; if (packet.HasMoreData) serverCaps = (ClientFlags)packet.ReadInteger(2); /* New protocol with 16 bytes to describe server characteristics */ owner.ConnectionCharSetIndex = (int)packet.ReadByte(); serverStatus = (ServerStatusFlags)packet.ReadInteger(2); // Since 5.5, high bits of server caps are stored after status. // Previously, it was part of reserved always 0x00 13-byte filler. uint serverCapsHigh = (uint)packet.ReadInteger(2); serverCaps |= (ClientFlags)(serverCapsHigh << 16); packet.Position += 11; byte[] seedPart2 = packet.ReadStringAsBytes(); encryptionSeed = new byte[seedPart1.Length + seedPart2.Length]; seedPart1.CopyTo(encryptionSeed, 0); seedPart2.CopyTo(encryptionSeed, seedPart1.Length); string authenticationMethod = ""; if ((serverCaps & ClientFlags.PLUGIN_AUTH) != 0) { authenticationMethod = packet.ReadString(); } else { // Some MySql versions like 5.1, don't give name of plugin, default to native password. authenticationMethod = "mysql_native_password"; } // based on our settings, set our connection flags SetConnectionFlags(serverCaps); packet.Clear(); packet.WriteInteger((int)connectionFlags, 4); packet.WriteInteger(maxSinglePacket, 4); packet.WriteByte(33); //character set utf-8 packet.Write(new byte[23]); #if !CF && !RT if ((serverCaps & ClientFlags.SSL) == 0) { if ((Settings.SslMode != MySqlSslMode.None) && (Settings.SslMode != MySqlSslMode.Preferred)) { // Client requires SSL connections. string message = String.Format("Resources.NoServerSSLSupport", Settings.Server); throw new MySqlException(message); } } else if (Settings.SslMode != MySqlSslMode.None) { stream.SendPacket(packet); StartSSL(); packet.Clear(); packet.WriteInteger((int)connectionFlags, 4); packet.WriteInteger(maxSinglePacket, 4); packet.WriteByte(33); //character set utf-8 packet.Write(new byte[23]); } #endif #if RT if (Settings.SslMode != MySqlSslMode.None) { throw new NotImplementedException("SSL not supported in this WinRT release."); } #endif Authenticate(authenticationMethod, false); // if we are using compression, then we use our CompressedStream class // to hide the ugliness of managing the compression if ((connectionFlags & ClientFlags.COMPRESS) != 0) stream = new MySqlStream(baseStream, Encoding, true); // give our stream the server version we are connected to. // We may have some fields that are read differently based // on the version of the server we are connected to. packet.Version = version; stream.MaxBlockSize = maxSinglePacket; }
public void Open() { // connect to one of our specified hosts try { #if !CF if (Settings.ConnectionProtocol == MySqlConnectionProtocol.SharedMemory) { SharedMemoryStream str = new SharedMemoryStream(Settings.SharedMemoryName); str.Open(Settings.ConnectionTimeout); baseStream = str; } else { #endif string pipeName = Settings.PipeName; if (Settings.ConnectionProtocol != MySqlConnectionProtocol.NamedPipe) pipeName = null; StreamCreator sc = new StreamCreator(Settings.Server, Settings.Port, pipeName, Settings.Keepalive); baseStream = sc.GetStream(Settings.ConnectionTimeout); #if !CF } #endif } catch (Exception ex) { throw new MySqlException(MySqlResources.UnableToConnectToHost, (int) MySqlErrorCode.UnableToConnectToHost, ex); } if (baseStream == null) throw new MySqlException(MySqlResources.UnableToConnectToHost, (int)MySqlErrorCode.UnableToConnectToHost); int maxSinglePacket = 255*255*255; stream = new MySqlStream(baseStream, Encoding, false); stream.ResetTimeout((int)Settings.ConnectionTimeout*1000); // read off the welcome packet and parse out it's values packet = stream.ReadPacket(); int protocol = packet.ReadByte(); string versionString = packet.ReadString(); version = DBVersion.Parse(versionString); if (!version.isAtLeast(4, 1, 1)) throw new NotSupportedException(MySqlResources.ServerTooOld); threadId = packet.ReadInteger(4); encryptionSeed = packet.ReadString(); maxSinglePacket = (256*256*256) - 1; // read in Server capabilities if they are provided ClientFlags serverCaps = 0; if (packet.HasMoreData) serverCaps = (ClientFlags) packet.ReadInteger(2); /* New protocol with 16 bytes to describe server characteristics */ owner.ConnectionCharSetIndex = (int)packet.ReadByte(); serverStatus = (ServerStatusFlags) packet.ReadInteger(2); packet.Position += 13; string seedPart2 = packet.ReadString(); encryptionSeed += seedPart2; // based on our settings, set our connection flags SetConnectionFlags(serverCaps); packet.Clear(); packet.WriteInteger((int) connectionFlags, 4); #if !CF if ((serverCaps & ClientFlags.SSL) ==0) { if ((Settings.SslMode != MySqlSslMode.None) && (Settings.SslMode != MySqlSslMode.Preferred)) { // Client requires SSL connections. string message = String.Format(MySqlResources.NoServerSSLSupport, Settings.Server); throw new MySqlException(message); } } else if (Settings.SslMode != MySqlSslMode.None) { stream.SendPacket(packet); StartSSL(); packet.Clear(); packet.WriteInteger((int) connectionFlags, 4); } #endif packet.WriteInteger(maxSinglePacket, 4); packet.WriteByte(8); packet.Write(new byte[23]); Authenticate(); // if we are using compression, then we use our CompressedStream class // to hide the ugliness of managing the compression if ((connectionFlags & ClientFlags.COMPRESS) != 0) stream = new MySqlStream(baseStream, Encoding, true); // give our stream the server version we are connected to. // We may have some fields that are read differently based // on the version of the server we are connected to. packet.Version = version; stream.MaxBlockSize = maxSinglePacket; }