It is storing files of various types, some text and some with binary data. The code is generic to handle any type of file with any extension, some user defined. My C# code cannot accurately know in advance whether it is retrieving text or binary data. The result set could have multiples of text files and multiples of binary files in any order. If the first row contains a binary file, GetFieldType returns byte[] for all rows, text or binary, since it uses an internally cached value for that SQL statement. When checking this, GetSQLiteType pulls the SQLiteType from _fieldTypeArray[i] if that position is not null.
Tim On Fri, May 6, 2011 at 11:40 AM, Robert Simpson <[email protected]> wrote: > So you're always wanting to call GetBytes() even if the column is text? > What about calling GetFieldType() beforehand to determine whether or not to > call GetString() or GetBytes()? > > -----Original Message----- > From: [email protected] > [mailto:[email protected]] On Behalf Of Tim Butterfield > Sent: Friday, May 06, 2011 9:31 AM > To: General Discussion of SQLite Database > Subject: Re: [sqlite] System.Data.SQLite blob column exception > > I am using a DbDataReader to return the columns for a SQL SELECT > statement. For the blob column, I am calling reader.GetOrdinal to get > the column number, calling reader.GetBytes to get the size of the > data, allocating the byte[], and then calling reader.GetBytes to read > into the buffer. > > Tim > > On Fri, May 6, 2011 at 11:12 AM, Robert Simpson <[email protected]> > wrote: >> How are you fetching the data? Are you using the generic reader[x] on a >> datareader? Are you using a DataSet/DataTable? >> >> >> -----Original Message----- >> From: [email protected] >> [mailto:[email protected]] On Behalf Of Tim Butterfield >> Sent: Friday, May 06, 2011 8:58 AM >> To: General Discussion of SQLite Database >> Subject: Re: [sqlite] System.Data.SQLite blob column exception >> >> On Fri, May 6, 2011 at 7:44 AM, Simon Slavin <[email protected]> wrote: >>> >>> On 6 May 2011, at 3:43am, Tim Butterfield wrote: >>> >>>> The blob values are always inserted and read as a byte[]. If those >>>> bytes are those of a text file, it fails. If I add a leading 0x00 >>>> byte to force it to be binary, it works. >>> >>> Are you binding your parameters ? If so, check that you're using >> sqlite3_bind_blob() when binding something to your BLOB column. Binding > it >> as text will not trigger an error, since SQLite is quite happy to bind > text >> into a BLOB column. But if you take blobby data, and bind it using >> sqlite3_bind_blob() into a column defined as a BLOB SQLite should be >> retaining and reporting it as as blob, not as text. >>> >>> If you're creating a fully text 'INSERT' or 'UPDATE' command rather than >> binding parameters, them make sure you're using the correct format to >> specify you have blob data (is it \x ?) rather than just supplying text. >> >> I'm using the System.Data.SQLite interface and not the direct C >> interface methods. All of my inserts are done using DbParameter (@p1, >> @p2, etc.) and DbCommand insert statements. The DbParameter.Value is >> the C# object type. In the case of the blob column, that type is a C# >> byte[], which sets the parameter type to DbType.Binary whether the >> first byte is 0x00 or a more textual value. >> >> Tim _______________________________________________ sqlite-users mailing list [email protected] http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

