sqlite3_value_bytes() private method

private sqlite3_value_bytes ( IntPtr p ) : int
p IntPtr
return int
        internal override long GetParamValueBytes(SqliteValueHandle p, int nDataOffset, byte[] bDest, int nStart,
                                                  int nLength)
        {
            int nCopied = nLength;

            int nlen = UnsafeNativeMethods.sqlite3_value_bytes(p);
            var ptr  = UnsafeNativeMethods.sqlite3_value_blob(p);

            if (bDest == null)
            {
                return(nlen);
            }

            if (nCopied + nStart > bDest.Length)
            {
                nCopied = bDest.Length - nStart;
            }
            if (nCopied + nDataOffset > nlen)
            {
                nCopied = nlen - nDataOffset;
            }

            if (nCopied > 0)
            {
                Array.Copy(ptr, nStart + nDataOffset, bDest, 0, nCopied);
            }
            else
            {
                nCopied = 0;
            }

            return(nCopied);
        }
Beispiel #2
0
        internal override long GetParamValueBytes(IntPtr p, int nDataOffset, byte[] bDest, int nStart, int nLength)
        {
            IntPtr ptr;
            int    nlen;
            int    nCopied = nLength;

            nlen = UnsafeNativeMethods.sqlite3_value_bytes(p);
            ptr  = UnsafeNativeMethods.sqlite3_value_blob(p);

            if (bDest == null)
            {
                return(nlen);
            }

            if (nCopied + nStart > bDest.Length)
            {
                nCopied = bDest.Length - nStart;
            }
            if (nCopied + nDataOffset > nlen)
            {
                nCopied = nlen - nDataOffset;
            }

            unsafe
            {
                if (nCopied > 0)
                {
                    Marshal.Copy((IntPtr)((byte *)ptr + nDataOffset), bDest, nStart, nCopied);
                }
                else
                {
                    nCopied = 0;
                }
            }

            return(nCopied);
        }