示例#1
0
        /// <summary>
        /// Loads a value from the specified buffer and seek real memo content from separated memo stream.
        /// </summary>
        /// <param name="buffer">The byte array from which a value should be loaded. The buffer length is always at least equal to the column size.</param>
        /// <param name="encoding">The encoding that should be used when loading a value. The encoding is never <c>null</c>.</param>
        /// <returns>A column text value, but null value signal if don't read from memo stream.</returns>
        protected override string ValueFromRowBuffer(byte[] rowBuffer, ref byte[] cachedColumnData)
        {
            if (cachedColumnData == null)
            { // cachedColumnData for decrease stream read
                if (IsNull(rowBuffer))
                {
                    return(String.Empty);
                }


                if (memoFile == null)
                {
                    if (exceptionIfNoMemoStream)
                    {
                        throw ExceptionFactory.CreateNotSupportedException("memoFile", "Stream of memo text is not defined!");
                    }
                    else
                    {
                        return(null);
                    }
                }
                else if (memoFile.disposed)
                {
                    if (exceptionIfNoMemoStream)
                    {
                        throw ExceptionFactory.CreateNotSupportedException("memoFile", "Stream of memo text is disposed!");
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    string temp = Encoding.ASCII.GetString(rowBuffer, offset_ + 1, size_);

                    int endPos = temp.IndexOf('\0');
                    if (endPos >= 0)
                    {
                        temp = temp.Substring(0, endPos);
                    }

                    int memoIndex;

                    if (!int.TryParse(temp, out memoIndex))
                    {
                        throw ExceptionFactory.CreateNotSupportedException("memoIndex", "Content of memo field '{0}' invalid (It isn't a block number)!", temp);
                    }

                    cachedColumnData = memoFile.ReadMemoBytes(memoIndex);
                }
            }

            return(encoding_.GetString(cachedColumnData));
        }
示例#2
0
        public static NdxHeader GetHeader(Stream stream)
        {
            if (stream.Length < (pageSize * 2))
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "NDX index stream length '{0}' < '{1}'!", stream.Length, (pageSize * 2));
            }

            if ((stream.Length % pageSize) != 0)
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "NDX index stream length ({0}) isn't a multiple of '{1}'!", stream.Length, pageSize);
            }

            //

            NdxHeader header = new NdxHeader();

            stream.Position = 0;

            BinaryReader reader = new BinaryReader(stream);                     // don't use 'using (BinaryReader reader...' because 'using' dispose 'stream' too!

            header.rootPage   = reader.ReadInt32();
            header.totalPages = reader.ReadInt32();

            reader.ReadInt32();                                                 // reserved space

            header.keyLen     = reader.ReadUInt16();
            header.keyPages   = reader.ReadUInt16();
            header.keyType    = reader.ReadUInt16();
            header.keyRecSize = reader.ReadInt32();                             // Size of key record is a multiplum of 4. Record size is 4 (Pointer to next page) + 4 (record number i dbf) + key size ( as a multiplum of 4 ). i.e. if the key size is 10, the record size is 20 (4+4+12)

            {
                int extraSpace = header.keyLen % 4;

                if (extraSpace != 0)
                {
                    extraSpace += (4 - extraSpace);
                }

                header.keyRecSize = 4 + 4 + header.keyLen + extraSpace;         // rewrite readed value because it was a not valid value
            }

            reader.ReadByte();                                                  // reserved space

            header.unique = reader.ReadBoolean();

            header.keyExpr = reader.ReadBytes(maxKeyLen);

            if (ProcessKeyExpressionBuffer(header.keyExpr) == null)
            {
                throw ExceptionFactory.CreateNotSupportedException("Content of NDX key expression bytes is envalid!");
            }

            return(header);
        }
示例#3
0
        public static NtxHeader GetHeader(Stream stream)
        {
            if (stream.Length < (pageSize * 2))
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "NTX index stream length '{0}' < '{1}'!", stream.Length, (pageSize * 2));
            }

            if ((stream.Length % pageSize) != 0)
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "NTX index stream length ({0}) isn't a multiple of '{1}'!", stream.Length, pageSize);
            }

            //

            NtxHeader header = new NtxHeader();

            stream.Position = 0;

            BinaryReader reader = new BinaryReader(stream);                     // don't use 'using (BinaryReader reader...' because 'using' dispose 'stream' too!

            header.signature = reader.ReadUInt16();
            header.version   = reader.ReadUInt16();
            header.root      = reader.ReadInt32();
            header.unused    = reader.ReadInt32();
            header.itemSize  = reader.ReadUInt16();
            header.keySize   = reader.ReadUInt16();
            header.keyDec    = reader.ReadUInt16();
            header.maxItem   = reader.ReadUInt16();
            header.halfPage  = reader.ReadUInt16();
            header.keyExpr   = reader.ReadBytes(maxKeyLen);

            byte uniqueFlag = reader.ReadByte();

            header.unique = (uniqueFlag != 0);

            Debug.Assert(reader.BaseStream.Position == 279);

            //

            byte sign1Byte = (byte)(header.signature >> 8);                       // get first byte

            if (!Array.Exists(validSignatures, s => (s == sign1Byte)))
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "Signature byte of NTX index stream is invalid! '{0}'", sign1Byte);
            }

            byte sign2Byte = (byte)(header.signature);                            // cut off first byte

            if (sign2Byte != 0)
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "Second signature byte in NTX index stream header is invalid!'{0}'", sign2Byte);
            }

            if ((header.keySize < 1) || (header.keySize > 250))
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "Key size in NTX index stream header is invalid!");
            }

            if ((header.keySize + 8) != header.itemSize)
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "Key size (+8) in NTX index stream header is invalid!");
            }

            if (ProcessKeyExpressionBuffer(header.keyExpr) == null)
            {
                throw ExceptionFactory.CreateNotSupportedException("Content of key expression bytes is envalid!");
            }

            if (!((uniqueFlag == 0) || (uniqueFlag == 1)))
            {
                throw ExceptionFactory.CreateArgumentOutOfRangeException("stream", "Unique flag in NTX index stream header is invalid!");
            }

            //

            return(header);
        }