|
Post by davos1 on Apr 15, 2009 13:18:18 GMT -5
Hi, I am trying to insert an image in a sqlite database, but at the moment, only errors I got, in this case A) when I get a file using httpget$, and then I tried to insert it in a blog field, a bad argument error appears any idea ? the code is:
cls 'create error handler on error goto [oops]
database$="test.db" fileName$=database$ if fileExists(fileName$) then print fileName$;" - oops,file exists" else print "new db" content$ = httpget$("http://libertybasic.com/lb3banner.jpg")
action3$ = "create table something ( title text, content blob)" action4$ = "insert into something ( title,content) values ('first',";content$;")" rem also I tried with action4$ = "insert into something ( title,content) values ('first','";content$;"')"
sqliteconnect #sqldb, database$ #sqldb execute(action3$) #sqldb execute(action4$) #sqldb disconnect()
Print "ok done" end if goto [last]
function fileExists(file$) files #f, file$ isfile = #f rowcount() fileExists = isfile end function
[oops] print "The program has encountered an error." print "Error number is ";Err;" and description is ";Err$
[last] end
=== the error is: new db The program has encountered an error. Error number is 0 and description is bad argument 2 The program has encountered an error. Error number is 0 and description is exception occured #(11 2509559590) Stefan: removed spaces inside the tags, do not use spaces inside of tags or they do not work, spaces are only used to display tags in posts
|
|
neal
Full Member
Posts: 104
|
Post by neal on Apr 16, 2009 22:22:39 GMT -5
You will need to escape any single quote characters in the blob, otherwise you will have trouble with the sql statement. Not sure if this is your problem or not however. eg. function doubleQuote$(string$) if instr(string$, "'") then for x = 1 to len(string$) if mid$(string$, x, 1) = "'" then doubleQuote$ = doubleQuote$ + "'" doubleQuote$ = doubleQuote$ + mid$(string$, x, 1) next x else doubleQuote$ = string$ end if end function
Or maybe you need to use a blob literal. From the sqlite docs: BLOB literals are string literals containing hexadecimal data and preceded by a single "x" or "X" character. For example: X'53514C697465'
|
|
|
Post by davos1 on Apr 18, 2009 12:41:29 GMT -5
I tried both suggestions but it didnt work. I checked for the ascii characters in all the text, and maybe it is because with httpget$ we got ascii values from 0 to 255..
|
|
|
Post by kokenge on Apr 18, 2009 12:55:08 GMT -5
Actually you have to escape all special characters.
Problem with loading a image to a DB is that you give up a lot of web functions. After doing lots of image processing, I have found it is a lot easier and better to upload the image to your photo sub-directory, and then point the DB to it.
Been there and done that - toooooo many times..
HTH..
|
|
|
Post by davos1 on May 4, 2009 11:42:32 GMT -5
thanks
|
|