# blob & image

Discussion in 'Questions (Windows Mobile)' started by dennishea, Aug 28, 2007.

Ok I have added a picture table to a dbase that I have created. I am saving a form.image to a image file and thought I would try to save to the dbase instead. I found the example in the sql help file of how to load the file into the dbase and how to retrieve it from the dbase and have succeed with no problems. My question is how do you save form1.image directly to the dbase instead of to a file and then the dbase.

:sign0085: :sign0085: :sign0085: Well ok maybe 1 :sign0085:

dennishea

You will need to use ImageLibEx library to save the image to a temporary file and then FileToBlob to add the file to the database.
There is no direct way to serialize an image and store it in the db.

image & blob

Thanks for the quik reply Erel. I was hopeing, oh well. Well on to setting that path up. Again thanks for your help and a very nice programming language that you just keep making better & better. Am looking forward to the future of basic4ppc.

dennishea

I have tried several ways to use this textbox (txtAngle.text) to replace smiley.gif in the line of code below. I want it to use the textbox information in place of smiley.gif. Everything works fine if I type in the name of the file in place of smiley.gif but I can't seem to get the syntax right for using a textbox. Does anybody know the way to replace

----------------------------------------------- txtAngle.text----
cmd.CommandText = "INSERT INTO pictures values('smiley.gif'," &
-------------------------- txtAngle.text---------
cmd.FileToBLOB(AppPath & "\smiley.gif") & ")"

dennishea :sign0148:

You have smiley.gif as a string literal and cannot just replace a literal with a variable value - you need to build the variable value into a string

i.e replace "... 'smiley.gif'..."
with "...'" & txtAngle.text & "'..."

doublequote - characters - singlequote doublequote & txtAngle.text & doublequote singlequote characters doublequote

agraham

This is what I am trying to get to work.

cmd.CommandText = "INSERT INTO pictures(name)values ('" & txtAngle.text & "', " cmd.FileToBLOB & AppPath & "\" & "'" txtAngle.text "')"

It's the only thing I have been able to get to compile and run up to it, then it spits out error. Basicly it is saying that it can't find the file. The textbox txtAngle.text is giving it it's contents, but they look like this 'Al 0008.bmp')' and I don't know why it has single quotes and the close character. I figure it is to do with the way I have it coded but can't seem to get it to compile any other way. This one is stubborn.

dennishea

This last bit looks wrong to me

... cmd.FileToBLOB & AppPath & "\" & "'" txtAngle.text "')"

There are two missing parentheses I think and if your original command using smiley.gif is correct then the single quotes are not needed in a parameter to FileToBlob. Try this

... & cmd.FileToBLOB (AppPath & "\" & txtAngle.text) & ")"

I think that FileToBlob needs to be executed while building the string, not be part of it

I just noticed that the file name you posted 'Al 0008.bmp' has a space in it. This is possibly not good as you may then need to double quote the filename to FileToBlob. If can, try it with a filename with no spaces otherwise you may be fighting on two fronts. Also if the single quotes and closing parenthesis really are in txtAngle.text then that seems wrong to me as well - surely it should only have a filename string in it? If you have put them in then remove them - they are clouding the issue.

EDIT: I've downloaded the SQL library and tried the example - this works with just the filename string in the text box

"INSERT INTO pictures values('" & txtAngle.Text & "'," & cmd.FileToBLOB(AppPath & "\" & txtAngle.Text) & ")"

Last edited: Aug 29, 2007

This was my last attemp for the day.
This doesn't work, I don't understand. This line of code shouldn't be any different then the below it and the one below works good.

---------------doesn't work-----------------------------------------
cmd.CommandText = "INSERT INTO pictures values('" & txtAngle.text & "', & cmd.FileToBLOB(" AppPath " & "\" & '" & txtAngle.text & "') &")"

------------------does work----------------------------------------
cmd.CommandText = "insert into WorkData values('" & txtInternal.Text & "','" & txtColdOd.Text & "','" & txtColdFp.Text & "','" & txtHotOd.Text & "','" & txtHotFp.Text & "','" & txtAmtWire.Text & "','" & txtPph.Text & "','" & txtWireSize.Text & "','" & txtCyctime.Text & "','" & txtMach.Text &"')"

delete , update and insert uses the format above and seems to be working fine. The data base checks out fine when I use these three commands with the above format. The top one with filetoblob is being a real stickleer. Well tomorrow another day. Being a third shift person it's my bed time. Tomorrow is another day. Have a good one all.

dennishea

Compare your failing command string (above) with the one I posted earlier that does work (below).
Your present problems are with the filename parameter of cmd.FileToBLOB(...).

1) You are quoting AppPath as a string literal so it will not be evaluated correctly. Also in a previous post I said
2) You are trying to put add these unnecessary single quotes around the filename and are producing a string that doesn't parse correctly.

SQLlite needs literal strings, like a filename, to be quoted with single quotes. The values(....) bit of the statement is executed by the SQLlite engine and so needs those single quotes. The cmd.FileToBLOB(...) bit of the statement is executed by B4PPC while it is building the string for cmd.commandText and so needs either a string literal quoted by double quotes or (as in this case) a string expression that evaluates to a valid path.

I must have something wrong, when I try to use filetoblob it locks up basic4ppc and ask me to end program at which point it quits basic4ppc altogether. It is the only code for sql that does that. Will type more later, have to take dog to vet for surgery.

dennishea

edit:
I understand your last explantion a lot better agraham. I know I am going to still make way more then my share of mistakes but at least I now have a better unstanding and place to come back to for a reference. Now that the syntax is right where do I look to solve the problem of my system choking on that paticular line of code. Thanks again for your patience and help in trying to solve this.

dennishea

Last edited: Aug 30, 2007

Check that you are using the correct SQL library. When you do Tools -> Components you should have SQLDevice.dll in the left hand pane for the device and SQLDesktop.dll in the right pane for the desktop.

Check that it really is choking on FileToBlob by trying something like this

Code:
s=cmd.FileToBLOB(AppPath & "\gamma.gif")    Msgbox(StrLength(s))

If it has worked properly then the length of s should be about twice the size of the gif file.

Cut and paste on here the exact contents of the line that it is choking on.

@agraham

please read in bug report (msgbox). I finally got it to work but I don't think any one will believe me.

dennishea

edit
I could have swore that I posted this but I'll do it here. I had a msgbox(cmd.commandtext) right after the line of code that I thought was the problem trying to see contents of cmd.commandtext and when I went into debug mode it hung up on the msgbox so I rem it out and tried again and wa la it worked like it is suppose to. Just to make sure I wasn't imaging it I unremarked it and then it quit working again. I don't understand why it just does. Any way I guess I will have to pay more attension to debug mode.

dennishea

p.s.