Strange results from OdbcDataReader reading Sqlite DB

Posted by stout on Stack Overflow See other posts from Stack Overflow or by stout
Published on 2009-01-04T18:53:32Z Indexed on 2010/06/02 9:03 UTC
Read the original article Hit count: 263

Filed under:
|
|
|

This method returns some strange results, and was wondering if someone could explain why this is happening, and possibly a solution to get my desired results.

Results:

FileName = what I'd expect

FileSize = what I'd expect

Buffer = all bytes = 0

BytesRead = 0

BlobString = string of binary data

FieldType = BLOB (what I'd expect)

ColumnType = System.String

Furthermore, if the file is greater than a few KB, the reader throws an exception stating the StringBuilder capacity argument must be greater than zero (presummably because the size is greater than Int32.MaxValue).

I guess my question is how does one properly read large BLOBs from an OdbcDataReader?

    public static String SaveBinaryFile(String Key)
    {
        try
        {
            Connect();

            OdbcCommand Command = new OdbcCommand("SELECT [_filename_],[_filesize_],[_content_] FROM [_sys_content] WHERE [_key_] = '" + Key + "';", Connection);
            OdbcDataReader Reader = Command.ExecuteReader(CommandBehavior.SequentialAccess);

            if (Reader.HasRows == false)
                return null;

            String FileName = Reader.GetString(0);
            int FileSize = int.Parse(Reader.GetString(1));
            byte[] Buffer = new byte[FileSize];
            long BytesRead = Reader.GetBytes(2, 0, Buffer, 0, FileSize);

            String BlobString = (String)Reader["_content_"];
            String FieldType = Reader.GetDataTypeName(2);
            Type ColumnType = Reader.GetFieldType(2);

            return null;
        }
        catch (Exception ex)
        {
            Tools.ErrorHandler.Catch(ex);
            return null;
        }
    }

© Stack Overflow or respective owner

Related posts about c#

Related posts about sqlite