[Gambas-user] Blob management
Ron
ron at ...1740...
Fri Jun 26 16:57:12 CEST 2009
David Villalobos Cambronero wrote:
> I do this:
>
> DIM hResultado AS Result
> DIM sImagen AS String
>
> IF NOT Exist("/tmp/mas") THEN MKDIR "/tmp/mas"
> hResultado = $hConn.Exec("SELECT * FROM `Imagenes`")
> sImagen = hResultado["Imagen"].Data <----------------------- Fails here "Not an object"
> File.Save("/tmp/mas/1.jpg", sImagen)
>
>
> and
>
> DIM hResultado AS Result
> DIM sImagen AS String
>
> IF NOT Exist("/tmp/mas") THEN MKDIR "/tmp/mas"
> hResultado = $hConn.Exec("SELECT * FROM `Imagenes`")
> sImagen = hResultado["Imagen"]
> File.Save("/tmp/mas/1.jpg", sImagen)
>
> Saves an empty file
I guess you have a problem with more then one/or false result being
returned, or with the syntax you use.
Does the following line work??:
sImagen = hResultado!Imagen.Data
The code beneath is part of my project which does something similar and
works 24/7.
Regards,
Ron_2nd.
PUBLIC SUB SendCaptureByMail(sSubject AS String, sBody AS String, iCam
AS Integer, OPTIONAL sTo AS String)
DIM hMsg AS NEW SmtpClient
DIM rResult AS Result
DIM sTable AS String = "capture_camera"
DIM sTempFile AS String = Temp() & ".jpg"
DIM hFile AS File
DIM sImage AS String
IF NOT Main.bEmailEnabled THEN RETURN
sTable = sTable & iCam
' get last image
rResult = Main.hDB.Exec(Subst("SELECT * FROM &1 ORDER BY stamp DESC
LIMIT 1", sTable))
IF rResult.Available THEN
IF rResult.Count = 1 THEN
TRY File.Save(sTempFile, rResult!image.Data)
END IF
END IF
IF Exist(sTempFile) THEN
hMsg.Add(File.Load(sTempFile), "image/jpeg", "FrontDoor" &
Format(Now(), "yyyy-mm-dd-hh-nn-ss") & ".jpg ")
KILL sTempFile
END IF
' sent msg to alternate address instead of default one
IF (Len(sTo)) THEN
hMsg.To.Add(sTo)
ELSE
hMsg.To.Add(Main.sEmailToAddress)
END IF
IF Main.bEMailDebug THEN
Main.WriteDebugLog(Main.sEmailFromAddress)
Main.WriteDebugLog(Main.sEmailSMTPServer)
Main.WriteDebugLog(Main.iEmailSMTPPort)
END IF
hMsg.Subject = sSubject
hMsg.Add(sBody & "\n\n" & "-- \nPowered by " & Application.Name & " V"
& Application.Version & "\n")
hMsg.From = Main.sEmailFromAddress
hMsg.Host = Main.sEmailSMTPServer
hMsg.Port = Main.iEmailSMTPPort
hMsg.Send()
IF Main.bEMailDebug THEN Main.WriteDebugLog("[e-mail] Message is sent.")
CATCH
Main.WriteLog("e-mail Error: Sending e-mail message failed!")
END
Table is defined with:
tableCaptures = Main.hDB.Tables.Add("capture_camera")
tableCaptures.Fields.Add("id", db.Serial)
tableCaptures.Fields.Add("stamp", db.Date, 32)
tableCaptures.Fields.Add("image", db.Blob)
tableCaptures.PrimaryKey = ["id"]
tableCaptures.Update()
More information about the User
mailing list