dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlText Class
Members Example

In This Topic
    MySqlText Class
    In This Topic
    Represents a variable-length stream of characters to be stored in or retrieved from the database.
    Syntax
    Remarks

    Use this class to retrieve text blocks stored in BLOB files. MySqlText suits best for TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT column types.

    Typically you use ToString method and Value property to retrieve strings from MySqlText. However, you can treat MySqlText as stream of bytes and decode it yourself.

    When creating a MySqlText instance, default client charset is used unless you explicitly force it to be UTF8 by setting unicode parameter to true in constructor MySqlText.New(string,bool)

    When obtaining a MySqlText object from server, its encoding depends on Unicode property of MySqlConnection opened. If this property is true, UTF8 client charset is used, otherwise MySqlText uses encoding default for your system.

    When sending data to server, MySqlText encoding must be synchronised with MySqlConnection encoding. If they differ, data sent to the server will be incorrect.

    Example
    This sample code consists of two routines. The first uploads a string to the server, while the second retrieves all strings contained in "BlockContent" column of the table.
    public void UploadSqlText(MySqlConnection myConnection)
    {
      myConnection.Unicode = true;
      MySqlText myTextSql = new MySqlText("This is a test text block");
      MySqlCommand myCommand = new MySqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(1,'First',:BlockText)", myConnection);
      myCommand.Parameters.Add("BlockText",myTextSql);
      myConnection.Open();
      try
      {
        Console.WriteLine(myCommand.ExecuteNonQuery()+" rows affected.");
      }
      finally
      {
        myConnection.Close();
      }
    }                                                                                                                   
    
    public void DownloadSqlText(MySqlConnection myConnection)
    {
      myConnection.Unicode = true;
      MySqlCommand myCommand = new MySqlCommand("SELECT * FROM Test.TextBlocks", myConnection);
      myConnection.Open();
      MySqlDataReader myReader = myCommand.ExecuteReader(CommandBehavior.Default);
      try
      {
        while (myReader.Read())
        {
          MySqlText myTextSql = myReader.GetMySqlText(myReader.GetOrdinal("BlockContent"));
          if(!myTextSql.IsNull)
          {
            Console.WriteLine(myTextSql.Value);
          }
        }
      }
      finally
      {
        myReader.Close();
        myConnection.Close();
      }
    }
    Public Sub UploadSqlText(ByVal myConnection As MySqlConnection)
      myConnection.Unicode = True
      Dim myTextSql As MySqlText = New MySqlText("This is a test text block")
      Dim myCommand As MySqlCommand = New MySqlCommand("INSERT INTO Test.TextBlocks (BlockID, BlockName, BlockContent) VALUES(3,'First',:BlockText)", myConnection)
      myCommand.Parameters.Add("BlockText", myTextSql)
      myConnection.Open()
      Try
        Console.WriteLine(String.Concat(myCommand.ExecuteNonQuery(), " rows affected."))
      Finally
        myConnection.Close()
      End Try
    End Sub
    
    Public Sub DownloadSqlText(ByVal myConnection As MySqlConnection)
      myConnection.Unicode = True
      Dim myCommand As New MySqlCommand("SELECT * FROM Test.TextBlocks", myConnection)
      myConnection.Open()
      Dim myReader As MySqlDataReader = myCommand.ExecuteReader(CommandBehavior.Default)
      Try
        While myReader.Read()
          Dim myTextSql As MySqlText = myReader.GetMySqlText(myReader.GetOrdinal("BlockContent"))
          If Not myTextSql.IsNull Then
            Console.WriteLine(myTextSql.Value)
          End If
        End While
      Finally
        myReader.Close()
        myConnection.Close()
      End Try
    End Sub
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.IO.Stream
             Devart.Data.MySql.MySqlBlob
                Devart.Data.MySql.MySqlText

    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also