Oracle 5.0 Reference Manual page 1935

Table of Contents

Advertisement

byte[] rawData;
FileStream fs;
conn.ConnectionString = "server=127.0.0.1;uid=root;" +
"pwd=12345;database=test;";
SQL = "SELECT file_name, file_size, file FROM file";
try
{
conn.Open();
cmd.Connection = conn;
cmd.CommandText = SQL;
myData = cmd.ExecuteReader();
if (! myData.HasRows)
throw new Exception("There are no BLOBs to save");
myData.Read();
FileSize = myData.GetUInt32(myData.GetOrdinal("file_size"));
rawData = new byte[FileSize];
myData.GetBytes(myData.GetOrdinal("file"), 0, rawData, 0, (int)FileSize);
fs = new FileStream(@"C:\newfile.png", FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(rawData, 0, (int)FileSize);
fs.Close();
MessageBox.Show("File successfully written to disk!",
"Success!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
myData.Close();
conn.Close();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show("Error " + ex.Number + " has occurred: " + ex.Message,
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
After connecting, the contents of the
method of the
GetBytes
written to disk using a
The
GetOrdinal
named column. Use of the GetOrdinal method prevents errors if the column order of the
is changed.
20.2.5.11. Using the Connector/Net Interceptor Classes
An interceptor is a software design pattern that provides a transparent way to extend or modify
some aspect of a program, similar to a user exit. No recompiling is required. With Connector/Net, the
interceptors are enabled and disabled by updating the connection string to refer to different sets of
interceptor classes that you instantiate.
Connector/Net includes the following interceptor classes:
• The
BaseCommandInterceptor
a SQL command. For example, you can examine the SQL statement for logging or debugging
purposes, substitute your own result set to implement a caching mechanism, and so on. Depending
on the use case, your code can supplement the SQL command or replace it entirely.
The
BaseCommandInterceptor
public virtual bool ExecuteScalar(string sql, ref object returnValue);
Connector/Net Programming
file
MySqlDataReader
object.
FileStream
method of the MySqlDataReader can be used to determine the integer index of a
lets you perform additional operations when a program issues
class has these methods that you can override:
table are loaded into a
is used to load the
1915
object. The
MySqlDataReader
into a byte array, which is then
BLOB
SELECT
query

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents