sqlite3_column_bytes() private method

private sqlite3_column_bytes ( IntPtr stmt, int index ) : int
stmt System.IntPtr
index int
return int
Example #1
0
        internal override long GetBytes(SqliteStatement stmt, int index, int nDataOffset, byte[] bDest, int nStart,
                                        int nLength)
        {
            int nCopied = nLength;
            int nlen    = UnsafeNativeMethods.sqlite3_column_bytes(stmt._sqlite_stmt, index);
            var ptr     = UnsafeNativeMethods.sqlite3_column_blob(stmt._sqlite_stmt, index);

            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);
        }
Example #2
0
        internal override long GetBytes(SqliteStatement stmt, int index, int nDataOffset, byte[] bDest, int nStart, int nLength)
        {
            IntPtr ptr;
            int    nlen;
            int    nCopied = nLength;

            nlen = UnsafeNativeMethods.sqlite3_column_bytes(stmt._sqlite_stmt, index);
            ptr  = UnsafeNativeMethods.sqlite3_column_blob(stmt._sqlite_stmt, index);

            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);
        }