Connector/Net Programming
1926
Treating Binary Blobs As UTF8
MySQL doesn't currently support 4-byte UTF8 sequences. This makes it difficult to represent some
multi-byte languages such as Japanese. To try and alleviate this, Connector/Net now supports a mode
where binary blobs can be treated as strings.
To do this, you set the
'Treat Blobs As UTF8'
connection string keyword to
yes
. This is
all that needs to be done to enable conversion of all binary blobs to UTF8 strings. To convert
only some of your BLOB columns, you can make use of the
'BlobAsUTF8IncludePattern'
and
'BlobAsUTF8ExcludePattern'
keywords. Set these to a regular expression pattern that
matches the column names to include or exclude respectively.
When the regular expression patterns both match a single column, the include pattern is applied before
the exclude pattern. The result, in this case, would be that the column would be excluded. Also, be
aware that this mode does not apply to columns of type
BINARY
or
VARBINARY
and also do not apply
to nonbinary
BLOB
columns.
Currently, this mode only applies to reading strings out of MySQL. To insert 4-byte UTF8 strings into
blob columns, use the .NET
Encoding.GetBytes
function to convert your string to a series of bytes.
You can then set this byte array as a parameter for a
BLOB
column.
20.2.5.17. Using Connector/Net with Crystal Reports
Crystal Reports is a common tool used by Windows application developers to perform reporting and
document generation. In this section we will show how to use Crystal Reports XI with MySQL and
Connector/Net.
20.2.5.17.1. Creating a Data Source
When creating a report in Crystal Reports there are two options for accessing the MySQL data while
designing your report.
The first option is to use Connector/ODBC as an ADO data source when designing your report. You will
be able to browse your database and choose tables and fields using drag and drop to build your report.
The disadvantage of this approach is that additional work must be performed within your application to
produce a data set that matches the one expected by your report.
The second option is to create a data set in VB.NET and save it as XML. This XML file can then be
used to design a report. This works quite well when displaying the report in your application, but is less
versatile at design time because you must choose all relevant columns when creating the data set. If
you forget a column you must re-create the data set before the column can be added to the report.
The following code can be used to create a data set from a query and write it to disk:
Visual Basic Example
Dim myData As New DataSet
Dim conn As New MySqlConnection
Dim cmd As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
conn.ConnectionString = "server=127.0.0.1;" _
& "uid=root;" _
& "pwd=12345;" _
& "database=world"
Try
conn.Open()
cmd.CommandText = "SELECT city.name AS cityName, city.population AS CityPopulation, " _
& "country.name, country.population, country.continent " _
& "FROM country, city ORDER BY country.continent, country.name"
cmd.Connection = conn
Summary of Contents for 5.0
Page 1: ...MySQL 5 0 Reference Manual ...
Page 18: ...xviii ...
Page 60: ...40 ...
Page 396: ...376 ...
Page 578: ...558 ...
Page 636: ...616 ...
Page 844: ...824 ...
Page 1234: ...1214 ...
Page 1427: ...MySQL Proxy Scripting 1407 ...
Page 1734: ...1714 ...
Page 1752: ...1732 ...
Page 1783: ...Configuring Connector ODBC 1763 ...
Page 1793: ...Connector ODBC Examples 1773 ...
Page 1839: ...Connector Net Installation 1819 2 You must choose the type of installation to perform ...
Page 2850: ...2830 ...
Page 2854: ...2834 ...
Page 2928: ...2908 ...
Page 3000: ...2980 ...
Page 3122: ...3102 ...
Page 3126: ...3106 ...
Page 3174: ...3154 ...
Page 3232: ...3212 ...