RE: Binary Data and BLOB Problem

2002-12-31 Thread Kevin Wixson
Mike,

Thank you very much for responding to my question. Haven't been able to 
find much out there. Your article, to which you referred in your response, 
was something I have already used to get me as far as I had gotten. I'd 
found it in my search for an answer. I found the connection string and the 
explanation of the options you used particularly useful. The comment you 
made about the cursor location confirmed what I read elsewhere, though put 
a different way. I've read that MySQL simply doesn't support cursors, so 
you have to set the cursor location to client. In the MySQL docs I've seen 
where they indicate that in the near future they plan to support cursors.

I was able to follow the example on stardeveloper.com 
(http://www.stardeveloper.com/articles/display.html?article=2001033101page=1) 
for uploading files and inserting them into a database as described without 
trouble.

The troubles start when I try to adapt the example for use with MySQL 
instead of MS Access.

I can't for the life of me get it to work consistently. I have changed the 
cursor location to client, I have changed the max_allowed_packed to 
1600, I have swapped out the table names that you can use with Access 
with the complete select statements that MySQL requires. Still, when I try 
to upload a file larger than 1 MB I get the following error: Microsoft OLE 
DB Provider for ODBC Drivers error '80040e21' [MySQL][ODBC 3.51 
Driver][mysqld-4.0.5-beta-max-nt]Lost connection to MySQL server during 
query. Sometimes the error is: Microsoft OLE DB Provider for ODBC Drivers 
error '80040e21' [MySQL][ODBC 3.51 Driver][mysqld-4.0.5-beta-max-nt]Got a 
packet bigger than 'max_allowed_packet'
I'm sure the file is less than 2MB.

With this code:

' Checking to make sure if file was uploaded
If fileSize  0 Then

set rsImage = Server.CreateObject(ADODB.Recordset)
rsImage.ActiveConnection = MM_connShooters_STRING
rsImage.Source = select * from web_lab.Images limit 0
rsImage.CursorType = adOpenKeyset
rsImage.CursorLocation = adUseClient
rsImage.LockType = adLockPessimistic
rsImage.Open()
rsImage_numRows = 0

' Adding data
rsImage.AddNew
rsImage(userID) = userID
rsImage(imageType) = contentType
rsImage(imageSize) = fileSize
rsImage(imageName) = fileName
rsImage(imageCaption) = caption
ERROR--rsImage.Update

rsImage.Close
Set rsImage = Nothing

Response.Write font color=greenFile was successfully uploaded...
Response.Write /font
Else
Response.Write font color=brownNo file was selected for uploading
Response.Write .../font
End If

When I adapt the code to use the Stream object instead of .AppendChunk, I 
get this error: Arguments are of the wrong type, are out of acceptable 
range, or are in conflict with one another. The code for the insert is as 
follows:

' Checking to make sure if file was uploaded
If fileSize  0 Then

set adoImageStream = Server.CreateObject(ADODB.Stream)
adoImageStream.Type = adTypeBinary

set rsImage = Server.CreateObject(ADODB.Recordset)
rsImage.ActiveConnection = MM_connShooters_STRING
rsImage.Source = select * from web_lab.Images limit 0
rsImage.CursorType = adOpenKeyset
rsImage.CursorLocation = adUseClient
rsImage.LockType = adLockPessimistic
rsImage.Open()
rsImage_numRows = 0

' Adding data
rsImage.AddNew
adoImageStream.Open
ERROR-- adoImageStream.Write fileData
rsImage(userID) = userID
rsImage(imageType) = contentType
rsImage(imageSize) = fileSize
rsImage(imageName) = fileName
rsImage(imageCaption) = caption
rsImage(imageData) = adoImageStream.read
rsImage.Update

adoImageStream.Close
rsImage.Close
Set rsImage = Nothing

Response.Write font color=greenFile was successfully uploaded...
Response.Write /font
Else
Response.Write font color=brownNo file was selected for uploading
Response.Write .../font
End If

I'm almost sure this error arises because the class object used for the 
page (found on the site with the tutorial, called 'loader.asp') changes the 
binary form data to a string, so the stream of type adTypeBinary doesn't 
accept the data, but when I change the stream type to text then I get an 
error because the field is expecting binary data. I haven't found an 
efficient enough way to change the data back to binary or to alter the 
class so that it doesn't turn the file data into a string in the first 
place. The relevant code from the class is this subroutine, which gets 
called when the object is initialized, to parse the form data:

Private Sub getData(rawData)
Dim separator
separator = MidB(rawData, 1, InstrB(1, rawData, ChrB(13)) - 1)

Dim lenSeparator
lenSeparator = LenB(separator)

Dim currentPos
currentPos = 1
Dim inStrByte
inStrByte = 1
Dim value, mValue
Dim tempValue
tempValue = 

While inStrByte  0
inStrByte = InStrB(currentPos, rawData, separator)
mValue = inStrByte - currentPos

If mValue  1 Then
value = MidB(rawData, currentPos, mValue)

Dim begPos, endPos, midValue, nValue
Dim intDict
Set intDict = Server.CreateObject(Scripting.Dictionary)

begPos = 1 + InStrB(1, value, ChrB(34))
endPos = 

RE: Binary Data and BLOB Problem

2002-12-30 Thread Mike Hillyer
BEGIN SHAMELESS PLUG

Hi Kevin;

You may want to look at the online article I wrote at
http://www.dynamergy.com/mike/articles/blobaccessvb.html which covers use of
the stream object in detail. While written for VB, it should be easy enough
to convert to ASP.

Mike Hillyer

END SHAMELESS PLUG


-Original Message-
From: Kevin Wixson [mailto:[EMAIL PROTECTED]]
Sent: Monday, December 30, 2002 10:29 AM
To: [EMAIL PROTECTED]
Subject: Binary Data and BLOB Problem



Having trouble with my first MySQL database. I want to upload and install
image files to a database for online sample photo gallery for our
customers. The system I've created so far sometimes works, sometimes
doesn't. It seems to depend on the size of the file being uploaded, but
tests have been inconclusive. Having trouble diagnosing the problem since
the error is most often Internal Server Error, which doesn't tell me
much. Otherwise I get:


Microsoft OLE DB Provider for ODBC Drivers error '80040e21'

[MySQL][ODBC 3.51 Driver][mysqld-4.0.5-beta-max-nt]Lost connection to MySQL
server during query

/shooters/Insert.asp, line 148

The relevant code is:

' Checking to make sure if file was uploaded
If fileSize  0 Then

set rsImage = Server.CreateObject(ADODB.Recordset)
rsImage.ActiveConnection = MM_connShooters_STRING
rsImage.Source = select * from web_lab.Images limit 0
rsImage.CursorType = adOpenKeyset
rsImage.CursorLocation = adUseClient
rsImage.LockType = adLockPessimistic
rsImage.Open()
rsImage_numRows = 0

' Adding data
rsImage.AddNew
rsImage(userID) = userID
rsImage(imageType) = contentType
rsImage(imageSize) = fileSize
rsImage(imageName) = fileName
rsImage(imageCaption) = caption
Do While lngOffset  fileSize
varChunk = LeftB(RightB(fileData, fileSize - lngOffset), conChunkSize)
rsImage(imageData).AppendChunk varChunk
lngOffset = lngOffset + conChunkSize
Loop

ERROR--rsImage.Update

'adoImageStream.Close
rsImage.Close
Set rsImage = Nothing

Response.Write font color=greenFile was successfully uploaded...
Response.Write /font
Else
Response.Write font color=brownNo file was selected for uploading
Response.Write .../font
End If

My connection string is:

MM_connShooters_STRING = driver={MySQL ODBC 3.51 Driver};
database=[name];uid=[id];pwd=[pass];OPTION=16427;

The constant conChunkSize is 100. I have checked the max packet size (set
to 1550) and as you can see, set cursors to client.

Alternatively, I have also tried to use the stream object, but I haven't
had any luck there either. I'm sure I'm not doing it right.



Thank you,

Kevin Wixson
IT Manager
Norman Camera  Video

(616) 567-5552
1-800-900-6676
Fax: (616) 343-6410
e-mail: [EMAIL PROTECTED]

Visit us on the web at: http://www.normancamera.com



-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php