Dim cache As Cursor
cache = BLUFcache.ExecQuery2("SELECT memberid FROM thumbs WHERE memberid = ?",Array As String(sequence))
Dim needThumb As Boolean = False
If cache.RowCount = 0 Then
Log("SVC No entry in database for api thumb " & sequence)
' no entry in the database for this member
' we'll save the api thumb
needThumb = True
End If
Dim idString As String = NumberFormat(sequence,4,0)
Dim tmpFile As OutputStream
tmpFile = File.OpenOutput(File.DirInternalCache,"A" & idString & ".png",False)
pictureData.WriteToStream(tmpFile,100,"PNG")
tmpFile.Close
Log("Saved api thumb")
Dim thumbData() As Byte
Dim inS As InputStream
Dim outS As OutputStream
inS = File.OpenInput(File.DirInternalCache,"A" & idString & ".png")
outS.InitializeToBytesArray(1000)
File.Copy2(inS,outS)
thumbData = outS.ToBytesArray
If needThumb = False Then
' already have an entry in the database, so just update it with the api thumb
Log("SVC Updating existing record for api thumb")
BLUFcache.AddNonQueryToBatch("UPDATE thumbs SET apiThumb = ? WHERE memberid = " & sequence, Array As Object(thumbData))
Else
' no entry, so make a new one
Log("SVC Creating new record for apithumb")
Dim now As Long
now = (DateTime.now/1000) - Main.timeOffset ' convert back to UTC
BLUFcache.AddNonQueryToBatch("INSERT INTO thumbs VALUES ( ?, null, ?, ? , ?)", Array As Object(sequence,thumbData,now,now))
End If
Main.batchpending = True