Groups | Blog | Home
all groups > sql server programming > october 2003 >

sql server programming : Single Quotes, SQL Inserts, Identifiers and Base 64...


David Browne
10/23/2003 6:11:09 PM
[quoted text, click to view]

Ok here's your first problem. NTEXT is unicode. You should not store
anything but text in an NTEXT column: most of these file types are not text
files. The ones that are text files are probably not stored in unicode
anyway. I guess you're using NTEXT because VB strings are unicode, and vb
will let you read practically anyting into a string. And VB6 makes reading
binary files kind of a pain.

But that's what you need to do. Use an IMAGE column instead of NTEXT, and
hanlde the files as binary files. You will need to read the files into a
byte array and write the bytes into your IMAGE column. Forget about
building an insert statement, and use your client library to insert the
binary data. In ADO use AppendChunk() to write binary data into your IMAGE
column.

Oh, and don't crosspost so much.


David

Hilary Cotter
10/23/2003 9:14:36 PM
you have to replace the double quotes as well.

The encoding is unlikely to be the problem as most of the document types are
binary - with the exception of txt, and xml (although xml does support the
binary datatype).

I have done many imports in a similar manner and I find it helpful to do
some tracking and having the script stop on errors. This way I can examine
the document it stopped on and try to load that document by itself and see
what makes that document problematic. Then after I trap for that condition
and have a work around I can continue to load where I left off.

[quoted text, click to view]

Liddle Feesh
10/23/2003 10:38:26 PM
Hi all!

Please - I really hope someone can help me...

As part of a document management tool, I am trying to read and write files
(of varying content - some txt, bmp, jpg, doc, xls, xml, etc) to and from
the windows filesystem and a SQL database.

The file content is stored as an ntext in a SQL Server 2002 table.

I am using the Replace() VB function in the application to swap out single
quotes (apostrophies: ' ) at runtime before saving/retrieving the data to
and from the files and the database.

My problem is this:

1. When attempting to load a file (using FileSystemObject), I continually
get "Unquoted Identifier" SQL errors on INSERT-ing the string into my table.

2. I can load and save plain text files (and xml files) to and from the
filesystem and database, and back again - with no problems.

3. When I do a debug.print of my SQL insert statement that falls over, I can
copy and paste the SQL string into notepad - but it does not paste properly
into query analyser.... WHY IS THIS ?! (argh!!!)

-----

I think that the problem is to do with the encoding (?!?!) of some of the
types of files - but I honestly don't have a clue - and I can't seem to
figure it out.

Setting QUOTED_IDENTIFIER OFF does not solve the issue - as it's not
strictly single quote related (even when I've stripped every single
single-quote out of the string.

Do I need to do a conversion (i.e. read the file in as base64/ASCII), and
how would I go about doing this? I'd rather not use any third party stuff
unless I have to...

-----

Please help!


--

Liddle Feesh
' O 0 o <"//>< ' o'^
(Remove UNDERPANTS to reply)

AddThis Social Bookmark Button