本文整理汇总了C#中MySql.Data.MySqlClient.MySqlDataReader.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# MySqlDataReader.GetBytes方法的具体用法?C# MySqlDataReader.GetBytes怎么用?C# MySqlDataReader.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MySql.Data.MySqlClient.MySqlDataReader
的用法示例。
在下文中一共展示了MySqlDataReader.GetBytes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: convertBlobToBufferData
public static byte[] convertBlobToBufferData(String column,MySqlDataReader rdr)
{
int bufferSize = 1024; // Number of bytes to read at a time
byte[] ImageData = new byte[bufferSize];
long nBytesReturned, startIndex = 0;
int ordinal = rdr.GetOrdinal(column);
string image = rdr.IsDBNull(ordinal) ? null : rdr.GetString(column);
if (image != null)
{
startIndex = 0;
nBytesReturned = rdr.GetBytes(
ordinal, // Column index of BLOB column
startIndex, // Start position of the byte to read
ImageData, // Byte array to recieve BLOB data
0, // Start index of the array
bufferSize // Size of buffer
);
while (nBytesReturned == bufferSize)
{
startIndex += bufferSize;
nBytesReturned = rdr.GetBytes(ordinal, startIndex, ImageData, 0, bufferSize); // Number of bytes returned is assigned to nBytesReturned
}
return ImageData;
}
else
{
return null;
}
}
示例2: DownloadSave
/// <summary>
/// Downloads the save.
/// </summary>
/// <param name="lun">Lun. Logged in User</param>
/// <param name="path">Path. path for saving the zip</param>
public void DownloadSave()
{
if (loggedIn) {
string lun = LoggedInUser;
int db_FileSize;
byte[] rawData;
FileStream fs;
//int db_id;
//string db_name;
//string db_password;
openConnection (true);
try {
string sql = "SELECT save, filesize FROM savebase.saves WHERE [email protected]";
cmd = new MySqlCommand (sql, conn);
cmd.CommandText = sql;
cmd.Parameters.AddWithValue ("@username", lun);
myData = cmd.ExecuteReader ();
if (! myData.HasRows){
throw new Exception("There are no rows");
}
myData.Read();
db_FileSize = myData.GetInt32("filesize");
if (db_FileSize <= 0)
{
// Debug.Log("no remote save found");
}
else
{
rawData = new byte[db_FileSize];
myData.GetBytes(myData.GetOrdinal("save"), 0, rawData, 0, db_FileSize);
fs = new FileStream(@path, FileMode.Create, FileAccess.Write);
fs.Write(rawData, 0, db_FileSize);
fs.Close();
myData.Close();
conn.Close();
Decompress();
if (SceneManager.GetActiveScene().buildIndex == 0)
{
feedback.enabled = true;
feedbackText.text = "Savegame succesfully downloaded, press Load Game game now";
}
}
} catch (Exception ex) {
Debug.Log (ex.Message.ToString ());
if (ex is MySqlException) {
MySqlException ex2 = (MySqlException)ex;
Debug.Log (ex2.Number);
}
Debug.Log (ex.ToString ());
throw ex;
} finally {
conn.Close ();
}
}
}
示例3: GetValue
// 取 dr 中某字段的数据并返回
public static object GetValue( DbColumn col, MySqlDataReader r, int idx )
{
switch( col.dataType )
{
case DbDataTypes.Boolean:
return r.GetBoolean( idx );
case DbDataTypes.Int8:
return r.GetSByte( idx );
case DbDataTypes.Int16:
return r.GetInt16( idx );
case DbDataTypes.Int32:
return r.GetInt32( idx );
case DbDataTypes.Int64:
return r.GetInt64( idx );
case DbDataTypes.UInt8:
return r.GetByte( idx );
case DbDataTypes.UInt16:
return r.GetUInt16( idx );
case DbDataTypes.UInt32:
return r.GetUInt32( idx );
case DbDataTypes.UInt64:
return r.GetUInt64( idx );
case DbDataTypes.Float:
return r.GetFloat( idx );
case DbDataTypes.Double:
return r.GetDouble( idx );
case DbDataTypes.DateTime:
return r.GetDateTime( idx );
case DbDataTypes.String:
return r.GetString( idx );
case DbDataTypes.Bytes:
var len = (int)r.GetBytes( idx, 0, null, 0, 0 );
var buf = new byte[ len ];
r.GetBytes( idx, 0, buf, 0, len );
return buf;
default:
throw new Exception( "unsupported DbType" );
}
}
示例4: FillValue
// 往 dr 填充 r 于 i 索引的值
public static void FillValue( DbRow dr, MySqlDataReader r, int i )
{
switch( dr.parent.columns[ i ].dataType )
{
case DbDataTypes.Boolean:
dr[ i ].Assign( r.GetBoolean( i ) ); break;
case DbDataTypes.Int8:
dr[ i ].Assign( r.GetSByte( i ) ); break;
case DbDataTypes.Int16:
dr[ i ].Assign( r.GetInt16( i ) ); break;
case DbDataTypes.Int32:
dr[ i ].Assign( r.GetInt32( i ) ); break;
case DbDataTypes.Int64:
dr[ i ].Assign( r.GetInt64( i ) ); break;
case DbDataTypes.UInt8:
dr[ i ].Assign( r.GetByte( i ) ); break;
case DbDataTypes.UInt16:
dr[ i ].Assign( r.GetUInt16( i ) ); break;
case DbDataTypes.UInt32:
dr[ i ].Assign( r.GetUInt32( i ) ); break;
case DbDataTypes.UInt64:
dr[ i ].Assign( r.GetUInt64( i ) ); break;
case DbDataTypes.Float:
dr[ i ].Assign( r.GetFloat( i ) ); break;
case DbDataTypes.Double:
dr[ i ].Assign( r.GetDouble( i ) ); break;
case DbDataTypes.DateTime:
dr[ i ].Assign( r.GetDateTime( i ) ); break;
case DbDataTypes.String:
dr[ i ].Assign( r.GetString( i ) ); break;
case DbDataTypes.Bytes:
var len = (int)r.GetBytes( i, 0, null, 0, 0 );
var buf = new byte[ len ];
r.GetBytes( i, 0, buf, 0, len );
dr[ i ].Assign( buf );
break;
default:
break;
}
}
示例5: ReadBlobData
public BitmapImage ReadBlobData(int id)
{
cmd.CommandText = "select Picture from Products where ID=" + id;
// Size of the BLOB buffer.
int bufferSize = 1024;
// The BLOB byte[] buffer to be filled by GetBytes.
byte[] outByte = new byte[bufferSize];
byte[] overallOutByte = null;
// The bytes returned from GetBytes.
long retval;
// The starting position in the BLOB output.
long startIndex = 0;
// The publisher id to use in the file name.
// Open the connection and read data into the DataReader.
dataReader = cmd.ExecuteReader(CommandBehavior.SequentialAccess);
while (dataReader.Read())
{
// Reset the starting byte for the new BLOB.
startIndex = 0;
// Read bytes into outByte[] and retain the number of bytes returned.
retval = dataReader.GetBytes(0, startIndex, outByte, 0, bufferSize);
overallOutByte = new byte[bufferSize];
outByte.CopyTo(overallOutByte, 0);
// Continue while there are bytes beyond the size of the buffer.
while (retval == bufferSize)
{
startIndex += bufferSize;
retval = dataReader.GetBytes(0, startIndex, outByte, 0, bufferSize);
byte[] tmpArr = new byte[overallOutByte.Length];
overallOutByte.CopyTo(tmpArr, 0);
overallOutByte = new byte[bufferSize + tmpArr.Length];
tmpArr.CopyTo(overallOutByte, 0);
outByte.CopyTo(overallOutByte, tmpArr.Length);
}
}
dataReader.Close();
return ConvertByteToImg(overallOutByte);
}