Modified:
trunk/CHANGES
trunk/Driver/Source/Field.cs
trunk/Driver/Source/MySqlConnectionStringBuilder.cs
trunk/Driver/Source/NativeDriver.cs
trunk/Driver/Source/docs/MySqlConnection.xml
trunk/TestSuite/Source/CharacterSetTests.cs
Log:
Implemented TreatBlobsAsUTF8 mode.
Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES 2007-07-13 17:43:42 UTC (rev 783)
+++ trunk/CHANGES 2007-07-14 16:27:02 UTC (rev 784)
@@ -12,6 +12,7 @@
overrides for Membership.CreateUser to work.
- Added 'Respect Binary Flags' connection string option to allow existing applications
to select the old behavior of not always respecting the binary flags of a columns.
+ - Added ability to use blobs to store true UTF-8 data (see help)
Version 5.1.2 - 6/12/2007
- Fixed integration with the Website Administration Tool. Before this fix, the test
link
Modified: trunk/Driver/Source/Field.cs
===================================================================
--- trunk/Driver/Source/Field.cs 2007-07-13 17:43:42 UTC (rev 783)
+++ trunk/Driver/Source/Field.cs 2007-07-14 16:27:02 UTC (rev 784)
@@ -22,6 +22,7 @@
using MySql.Data.Common;
using MySql.Data.Types;
using System.Globalization;
+using System.Text.RegularExpressions;
namespace MySql.Data.MySqlClient
{
@@ -193,32 +194,55 @@
{
case MySqlDbType.Byte:
mySqlDbType = MySqlDbType.UByte;
- break;
+ return;
case MySqlDbType.Int16:
mySqlDbType = MySqlDbType.UInt16;
- break;
+ return;
case MySqlDbType.Int24:
mySqlDbType = MySqlDbType.UInt24;
- break;
+ return;
case MySqlDbType.Int32:
mySqlDbType = MySqlDbType.UInt32;
- break;
+ return;
case MySqlDbType.Int64:
mySqlDbType = MySqlDbType.UInt64;
- break;
+ return;
}
}
- if (IsBlob && !IsBinary)
+ if (IsBlob)
{
- if (type == MySqlDbType.TinyBlob)
- mySqlDbType = MySqlDbType.TinyText;
- else if (type == MySqlDbType.MediumBlob)
- mySqlDbType = MySqlDbType.MediumText;
- else if (type == MySqlDbType.Blob)
- mySqlDbType = MySqlDbType.Text;
- else if (type == MySqlDbType.LongBlob)
- mySqlDbType = MySqlDbType.LongText;
+ // handle blob to UTF8 conversion if requested. This is only activated
+ // on binary blobs
+ if (IsBinary && connection.Settings.TreatBlobsAsUTF8)
+ {
+ bool convertBlob = true;
+ Regex includeRegex = connection.Settings.BlobAsUTF8IncludeRegex;
+ Regex excludeRegex = connection.Settings.BlobAsUTF8ExcludeRegex;
+ convertBlob &= (includeRegex != null &&
includeRegex.IsMatch(ColumnName));
+ if (excludeRegex != null && excludeRegex.IsMatch(ColumnName))
+ convertBlob = false;
+
+ if (convertBlob)
+ {
+ binaryOk = false;
+ Encoding = System.Text.Encoding.GetEncoding("UTF-8");
+ charSetIndex = -1; // lets driver know we are in charge of
encoding
+ maxLength = 4;
+ }
+ }
+
+ if (!IsBinary)
+ {
+ if (type == MySqlDbType.TinyBlob)
+ mySqlDbType = MySqlDbType.TinyText;
+ else if (type == MySqlDbType.MediumBlob)
+ mySqlDbType = MySqlDbType.MediumText;
+ else if (type == MySqlDbType.Blob)
+ mySqlDbType = MySqlDbType.Text;
+ else if (type == MySqlDbType.LongBlob)
+ mySqlDbType = MySqlDbType.LongText;
+ }
}
// now determine if we really should be binary
Modified: trunk/Driver/Source/MySqlConnectionStringBuilder.cs
===================================================================
--- trunk/Driver/Source/MySqlConnectionStringBuilder.cs 2007-07-13 17:43:42 UTC (rev 783)
+++ trunk/Driver/Source/MySqlConnectionStringBuilder.cs 2007-07-14 16:27:02 UTC (rev 784)
@@ -24,6 +24,7 @@
using System.Data.Common;
using System.Globalization;
using System.Text;
+using System.Text.RegularExpressions;
namespace MySql.Data.MySqlClient
{
@@ -44,10 +45,10 @@
bool oldSyntax, persistSI, usePerfMon, pooling;
bool allowZeroDatetime, convertZeroDatetime;
bool useUsageAdvisor, useSSL;
- bool ignorePrepare;
- bool useProcedureBodies;
- bool autoEnlist;
- bool respectBinaryFlags;
+ bool ignorePrepare, useProcedureBodies;
+ bool autoEnlist, respectBinaryFlags, treatBlobsAsUTF8;
+ string blobAsUtf8IncludePattern, blobAsUtf8ExcludePattern;
+ Regex blobAsUtf8ExcludeRegex, blobAsUtf8IncludeRegex;
static MySqlConnectionStringBuilder()
{
@@ -82,6 +83,9 @@
defaultValues.Add(Keyword.UseProcedureBodies, true);
defaultValues.Add(Keyword.AutoEnlist, true);
defaultValues.Add(Keyword.RespectBinaryFlags, true);
+ defaultValues.Add(Keyword.BlobAsUTF8ExcludePattern, null);
+ defaultValues.Add(Keyword.BlobAsUTF8IncludePattern, null);
+ defaultValues.Add(Keyword.TreatBlobsAsUTF8, false);
}
/// <summary>
@@ -486,25 +490,6 @@
}
/// <summary>
- /// Gets or sets the character set that should be used for sending queries to the
server.
- /// </summary>
-#if !CF && !MONO
- [DisplayName("Character Set")]
- [Category("Advanced")]
- [Description("Character set this connection should use")]
- [RefreshProperties(RefreshProperties.All)]
-#endif
- public string CharacterSet
- {
- get { return charSet; }
- set
- {
- SetValue("Character Set", value);
- charSet = value;
- }
- }
-
- /// <summary>
/// Gets or sets a boolean value indicating if the Usage Advisor should be
enabled.
/// </summary>
#if !CF && !MONO
@@ -745,6 +730,88 @@
#endregion
+ #region Language and Character Set Properties
+
+ /// <summary>
+ /// Gets or sets the character set that should be used for sending queries to the
server.
+ /// </summary>
+#if !CF && !MONO
+ [DisplayName("Character Set")]
+ [Category("Advanced")]
+ [Description("Character set this connection should use")]
+ [RefreshProperties(RefreshProperties.All)]
+#endif
+ public string CharacterSet
+ {
+ get { return charSet; }
+ set
+ {
+ SetValue("Character Set", value);
+ charSet = value;
+ }
+ }
+
+ /// <summary>
+ /// Indicates whether the driver should treat binary blobs as UTF8
+ /// </summary>
+#if !CF && !MONO
+ [DisplayName("Treat Blobs As UTF8")]
+ [Category("Advanced")]
+ [Description("Should binary blobs be treated as UTF8")]
+ [RefreshProperties(RefreshProperties.All)]
+#endif
+ public bool TreatBlobsAsUTF8
+ {
+ get { return treatBlobsAsUTF8; }
+ set
+ {
+ SetValue("TreatBlobsAsUTF8", value);
+ treatBlobsAsUTF8 = value;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the pattern that matches the columns that should be treated as
UTF8
+ /// </summary>
+#if !CF && !MONO
+ [DisplayName("BlobAsUTF8IncludePattern")]
+ [Category("Advanced")]
+ [Description("Pattern that matches columns that should be treated as UTF8")]
+ [RefreshProperties(RefreshProperties.All)]
+#endif
+ public string BlobAsUTF8IncludePattern
+ {
+ get { return blobAsUtf8IncludePattern; }
+ set
+ {
+ SetValue("BlobAsUTF8IncludePattern", value);
+ blobAsUtf8IncludePattern = value;
+ blobAsUtf8IncludeRegex = null;
+ }
+ }
+
+ /// <summary>
+ /// Gets or sets the pattern that matches the columns that should not be treated
as UTF8
+ /// </summary>
+#if !CF && !MONO
+ [DisplayName("BlobAsUTF8ExcludePattern")]
+ [Category("Advanced")]
+ [Description("Pattern that matches columns that should not be treated as UTF8")]
+ [RefreshProperties(RefreshProperties.All)]
+#endif
+ public string BlobAsUTF8ExcludePattern
+ {
+ get { return blobAsUtf8ExcludePattern; }
+ set
+ {
+ SetValue("BlobAsUTF8ExcludePattern", value);
+ blobAsUtf8ExcludePattern = value;
+ blobAsUtf8ExcludeRegex = null;
+ }
+ }
+
+ #endregion
+
#region Conversion Routines
private static uint ConvertToUInt(object value)
@@ -818,6 +885,32 @@
#endregion
+ #region Internal Properties
+
+ internal Regex BlobAsUTF8IncludeRegex
+ {
+ get
+ {
+ if (blobAsUtf8IncludePattern == null) return null;
+ if (blobAsUtf8IncludeRegex == null)
+ blobAsUtf8IncludeRegex = new Regex(blobAsUtf8IncludePattern);
+ return blobAsUtf8IncludeRegex;
+ }
+ }
+
+ internal Regex BlobAsUTF8ExcludeRegex
+ {
+ get
+ {
+ if (blobAsUtf8ExcludePattern == null) return null;
+ if (blobAsUtf8ExcludeRegex == null)
+ blobAsUtf8ExcludeRegex = new Regex(blobAsUtf8ExcludePattern);
+ return blobAsUtf8ExcludeRegex;
+ }
+ }
+
+ #endregion
+
/// <summary>
/// Takes a given connection string and returns it, possible
/// stripping out the password info
@@ -942,6 +1035,13 @@
return Keyword.AutoEnlist;
case "respect binary flags":
return Keyword.RespectBinaryFlags;
+ case "blobasutf8excludepattern":
+ return Keyword.BlobAsUTF8ExcludePattern;
+ case "blobasutf8includepattern":
+ return Keyword.BlobAsUTF8IncludePattern;
+ case "treatblobsasutf8":
+ case "treat blobs as utf8":
+ return Keyword.TreatBlobsAsUTF8;
}
throw new ArgumentException(Resources.KeywordNotSupported, key);
}
@@ -1012,6 +1112,12 @@
return AutoEnlist;
case Keyword.RespectBinaryFlags:
return RespectBinaryFlags;
+ case Keyword.TreatBlobsAsUTF8:
+ return TreatBlobsAsUTF8;
+ case Keyword.BlobAsUTF8ExcludePattern:
+ return blobAsUtf8ExcludePattern;
+ case Keyword.BlobAsUTF8IncludePattern:
+ return blobAsUtf8IncludePattern;
default:
return null; /* this will never happen */
}
@@ -1094,6 +1200,12 @@
autoEnlist = ConvertToBool(value); break;
case Keyword.RespectBinaryFlags:
respectBinaryFlags = ConvertToBool(value); break;
+ case Keyword.TreatBlobsAsUTF8:
+ treatBlobsAsUTF8 = ConvertToBool(value); break;
+ case Keyword.BlobAsUTF8ExcludePattern:
+ blobAsUtf8ExcludePattern = (string)value; break;
+ case Keyword.BlobAsUTF8IncludePattern:
+ blobAsUtf8IncludePattern = (string)value; break;
}
}
@@ -1267,6 +1379,9 @@
UseSSL,
UseProcedureBodies,
AutoEnlist,
- RespectBinaryFlags
+ RespectBinaryFlags,
+ TreatBlobsAsUTF8,
+ BlobAsUTF8IncludePattern,
+ BlobAsUTF8ExcludePattern
}
}
Modified: trunk/Driver/Source/NativeDriver.cs
===================================================================
--- trunk/Driver/Source/NativeDriver.cs 2007-07-13 17:43:42 UTC (rev 783)
+++ trunk/Driver/Source/NativeDriver.cs 2007-07-14 16:27:02 UTC (rev 784)
@@ -713,7 +713,7 @@
stream.ReadInteger(2); // reserved
}
- if (charSets != null)
+ if (charSets != null && field.CharacterSetIndex != -1)
{
CharacterSet cs = CharSetMap.GetChararcterSet(Version, (string)
charSets[field.CharacterSetIndex]);
field.MaxLength = cs.byteCount;
Modified: trunk/Driver/Source/docs/MySqlConnection.xml
===================================================================
--- trunk/Driver/Source/docs/MySqlConnection.xml 2007-07-13 17:43:42 UTC (rev 783)
+++ trunk/Driver/Source/docs/MySqlConnection.xml 2007-07-14 16:27:02 UTC (rev 784)
@@ -900,9 +900,23 @@
Connector/Net 5.0 and earlier.
</td>
</tr>
+ <tr>
+ <td>BlobAsUTF8IncludePattern</td>
+ <td>null</td>
+ <td>
+ Pattern that should be used to indicate which blob columns should be treated as
UTF-8.
+ </td>
+ </tr>
+ <tr>
+ <td>BlobAsUTF8ExcludePattern</td>
+ <td>null</td>
+ <td>
+ Pattern that should be used to indicate which blob columns should not be treated
as UTF-8.
+ </td>
+ </tr>
</table>
- </div>
- <para>
+</div>
+<para>
The following table lists the valid names for connection pooling values within
the <B>ConnectionString</B>. For more information about connection pooling,
see
Connection Pooling for the MySql Data Provider.</para>
Modified: trunk/TestSuite/Source/CharacterSetTests.cs
===================================================================
--- trunk/TestSuite/Source/CharacterSetTests.cs 2007-07-13 17:43:42 UTC (rev 783)
+++ trunk/TestSuite/Source/CharacterSetTests.cs 2007-07-14 16:27:02 UTC (rev 784)
@@ -24,6 +24,7 @@
+
@@ -189,6 +190,84 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
| Thread |
|---|
| • Connector/NET commit: r784 - in trunk: . Driver/Source Driver/Source/docs TestSuite/Source | rburnett | 14 Jul |