GetBytes() public method

Reads a stream of bytes from the specified column offset into the buffer an array starting at the given buffer offset.
public GetBytes ( int i, long fieldOffset, byte buffer, int bufferoffset, int length ) : long
i int The zero-based column ordinal.
fieldOffset long The index within the field from which to begin the read operation.
buffer byte The buffer into which to read the stream of bytes.
bufferoffset int The index for buffer to begin the read operation.
length int The maximum length to copy into the buffer.
return long
        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
0
    /// <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 username=@username";
                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
0
文件: MyUtils.cs 项目: whuthj/69net
 // 取 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
0
文件: MyUtils.cs 项目: whuthj/69net
 // 往 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
-1
        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);
        }