本文整理汇总了C#中IDataReader.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# IDataReader.GetBytes方法的具体用法?C# IDataReader.GetBytes怎么用?C# IDataReader.GetBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDataReader
的用法示例。
在下文中一共展示了IDataReader.GetBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public override object Get(IDataReader rs, int index)
{
int length = (int)rs.GetBytes(index, 0, null, 0, 0);
byte[] buffer = new byte[length];
rs.GetBytes(index, 0, buffer, 0, length);
return ToExternalFormat(buffer);
}
示例2: ReadBytesFromBlob
//---------------------------------------------------------------------------
// protected methods that can be overridden by subclasses
//---------------------------------------------------------------------------
protected override byte[] ReadBytesFromBlob(IDataReader dr, int colIndex)
{
if (dr.IsDBNull(colIndex))
{
return null;
}
// PostgreSQL reads all data at once
long dataLength = dr.GetBytes(colIndex, 0, null, 0, 0);
byte[] data = new byte[dataLength];
dr.GetBytes(colIndex, 0, data, 0, 0);
return data;
}
示例3: GetValueByIndex
/// <summary>
/// Gets a column value by the index
/// </summary>
/// <param name="mapping"></param>
/// <param name="dataReader"></param>
/// <returns></returns>
public override object GetValueByIndex(ResultProperty mapping, IDataReader dataReader)
{
if (dataReader.IsDBNull(mapping.ColumnIndex) || dataReader.GetBytes(mapping.ColumnIndex, 0, null, 0, 0) == 0)
{
return DBNull.Value;
}
return GetValueByIndex(mapping.ColumnIndex, dataReader);
}
示例4: GetValueByName
/// <summary>
/// Gets a column value by the name
/// </summary>
/// <param name="mapping"></param>
/// <param name="dataReader"></param>
/// <returns></returns>
public override object GetValueByName(ResultProperty mapping, IDataReader dataReader)
{
int index = dataReader.GetOrdinal(mapping.ColumnName);
if (dataReader.IsDBNull(index) || dataReader.GetBytes(index, 0, null, 0, 0) == 0)
{
return DBNull.Value;
}
return GetValueByIndex(index, dataReader);
}
示例5: Get
public override object Get(IDataReader rs, int index)
{
int length = (int) rs.GetBytes(index, 0, null, 0, 0);
byte[] bytes = new byte[length];
int offset = 0;
while (offset < length)
{
int count = (int) rs.GetBytes(index, offset, bytes, offset, length - offset);
offset += count;
if (count == 0)
{
throw new AssertionFailure("IDataRecord.GetBytes returned 0");
}
}
return new SqlBinary(bytes);
}
示例6: Get
public override object Get(IDataReader rs, int index)
{
int length = (int)rs.GetBytes(index, 0, null, 0, 0);
byte[] buffer = new byte[length];
if (length > 0)
{
// The "if" is to make happy MySQL NH-2096
rs.GetBytes(index, 0, buffer, 0, length);
}
return ToExternalFormat(buffer);
}
示例7: Get
/// <summary>
///
/// </summary>
/// <param name="rs"></param>
/// <param name="index"></param>
/// <returns></returns>
public override object Get( IDataReader rs, int index )
{
int length = ( int ) rs.GetBytes( index, 0, null, 0, 0 );
byte[ ] buffer = new byte[ length ];
int offset = 0;
while( length - offset > 0 )
{
int countRead = ( int ) rs.GetBytes( index, offset, buffer, offset, length - offset );
offset += countRead;
if( countRead == 0 )
{
// Should never happen
throw new AssertionFailure( "Error in BinaryType.Get, IDataRecord.GetBytes read zero bytes" );
}
}
return buffer;
}
示例8: GetByte
public static byte[] GetByte(IDataReader dr, string columnName, int length)
{
int ordinal = dr.GetOrdinal(columnName);
bool isDbNull = dr.IsDBNull(ordinal);
byte[] buffer = null;
if (!isDbNull)
{
buffer = new byte[length];
dr.GetBytes(ordinal, 0, buffer, 0, length);
}
return buffer;
}
示例9: Get
protected virtual object Get(IDataReader rs, int ordinal)
{
int bufferSize = 0x1000;
byte[] buffer = new byte[bufferSize];
int readBytes = (int)rs.GetBytes(ordinal, 0L, buffer, 0, bufferSize);
long position = readBytes;
using (MemoryStream data = new MemoryStream(readBytes))
{
if (readBytes >= bufferSize)
while (readBytes > 0)
{
data.Write(buffer, 0, readBytes);
position += (readBytes = (int)rs.GetBytes(ordinal, position, buffer, 0, bufferSize));
}
data.Write(buffer, 0, readBytes);
data.Flush();
if (data.Length == 0)
return GetValue(new byte[0]);
return GetValue(data.ToArray());
}
}
示例10: NullSafeGet
public override object NullSafeGet(IDataReader rs, string name, ISessionImplementor session, object owner)
{
int index = rs.GetOrdinal(name);
if (rs.IsDBNull(index)) return null;
IExternalBlobConnection conn = GetExternalBlobConnection(session);
byte[] identifier = new byte[conn.BlobIdentifierLength];
int i = (int)rs.GetBytes(index, 0, identifier, 0, identifier.Length);
if (i != identifier.Length) throw new Exception("Unknown identifier length. Recieved " + i.ToString() + " but expected " + identifier.Length.ToString() + " bytes");
return CreateLobInstance(conn, identifier);
}
示例11: fetchWordList
public bool fetchWordList(ref WorldList wl)
{
// Doesnt exist by default
wl.setExistance(false);
string sqlQuery = "select * from users where username='"+wl.getUsername()+"' and passwordmd5='"+wl.getPassword()+"';";
queryExecuter= conn.CreateCommand();
queryExecuter.CommandText = sqlQuery;
dr= queryExecuter.ExecuteReader();
while(dr.Read()){
// Player is on the DB
wl.setExistance(true);
wl.setUserID((int) dr.GetDecimal(0));
dr.GetBytes(6,0,wl.getPrivateExponent(),0,96);
dr.GetBytes(5,0,wl.getPublicModulus(),0,96);
wl.setTimeCreated((int)dr.GetDecimal(7));
}
dr.Close();
// If doesnt exist... should not do more things
if (!wl.getExistance()){
Output.writeToLogForConsole("[WORLD DB ACCESS] fetchWordList : Player not found on DB with #" + wl.getUsername() + "# and #" + wl.getPassword() + "#");
conn.Close();
return false;
}
return true;
}
示例12: GenParameterText
//将 DataReader 中的数据打包为报表需要的参数数据包形式
public static string GenParameterText(IDataReader drParamer)
{
StringBuilder sbJSONText = new StringBuilder();
if (drParamer.Read())
{
for (int i = 0; i < drParamer.FieldCount; ++i)
{
if (drParamer.IsDBNull(i))
continue;
string Value;
if (drParamer.GetFieldType(i).IsArray)
{
long DataSize = drParamer.GetBytes(i, 0, null, 0, int.MaxValue);
byte[] buffer = new byte[DataSize];
drParamer.GetBytes(i, 0, buffer, 0, (int)DataSize);
Value = Convert.ToBase64String(buffer);
}
else
{
Value = drParamer.GetValue(i).ToString();
PrepareValueText(ref Value);
}
sbJSONText.AppendFormat("\"{0}\":\"{1}\",", drParamer.GetName(i), Value);
}
}
sbJSONText.Remove(sbJSONText.Length - 1, 1); //去掉最后一个字段后面的","
return sbJSONText.ToString();
}
示例13: ReadBytesFromBlob
protected virtual byte[] ReadBytesFromBlob(IDataReader dr, int colIndex)
{
if (dr.IsDBNull(colIndex))
{
return null;
}
int bufferSize = 1024;
MemoryStream stream = new MemoryStream();
// can read the data
byte[] outbyte = new byte[bufferSize];
// Reset the starting byte for the new BLOB.
int startIndex;
startIndex = 0;
// Read the bytes into outbyte[] and retain the number of bytes returned.
int retval; // The bytes returned from GetBytes.
retval = (int)dr.GetBytes(colIndex, startIndex, outbyte, 0, bufferSize);
// Continue reading and writing while there are bytes beyond the size of the buffer.
while (retval == bufferSize)
{
stream.Write(outbyte, 0, retval);
// Reposition the start index to the end of the last buffer and fill the buffer.
startIndex += bufferSize;
retval = (int)dr.GetBytes(colIndex, startIndex, outbyte, 0, bufferSize);
}
// Write the remaining buffer.
stream.Write(outbyte, 0, retval);
return stream.GetBuffer();
}
示例14: GetBytes
public int GetBytes(IDataReader reader, long dataOffset, byte[] buffer, int bufferIndex, int length)
{
InitColumn(reader);
return (int)reader.GetBytes(Ordinal, dataOffset, buffer, bufferIndex, length);
}
示例15: NullSafeGet
public override object NullSafeGet(IDataReader rs, string name, ISessionImplementor session, object owner)
{
int index = rs.GetOrdinal(name);
if (rs.IsDBNull(index)) return null;
IExternalBlobConnection conn = GetExternalBlobConnection(session);
byte[] payload;
if (conn.BlobIdentifierLength == Int32.MaxValue)
{
var length = (int) rs.GetBytes(index, 0L, null, 0, 0);
payload = new byte[length];
// The if here makes MySql happy (See https://nhibernate.jira.com/browse/NH-2096 for details)
if (length > 0)
{
rs.GetBytes(index, 0L, payload, 0, length);
}
}
else
{
payload = new byte[conn.BlobIdentifierLength];
// The if here makes MySql happy (See https://nhibernate.jira.com/browse/NH-2096 for details)
if (payload.Length > 0)
{
var i = (int) rs.GetBytes(index, 0, payload, 0, payload.Length);
if (i != payload.Length)
{
if (Logger.IsErrorEnabled) Logger.ErrorFormat("Unknown payload (identifier) length. Recieved {0} but expected {1} bytes for owner: {2}", i, payload.Length, owner);
return null;
}
}
else
{
if (Logger.IsErrorEnabled) Logger.ErrorFormat("Unknown payload (identifier) length. Recieved 0 but expected {0} bytes for owner: {1}", payload.Length, owner);
return null;
}
}
return CreateLobInstance(conn, payload);
}