Problem: fetch and store image to/from database

Discussion in 'Questions (Windows Mobile)' started by willisgt, May 12, 2008.

  1. willisgt

    willisgt Active Member Licensed User

    I'm trying to (1) store an image in a database, and (2) fetch that image from the database and display it.

    The 'fetch and display' routine:

    Code:
    Sub btnShow_Click

       cmd.CommandText = 
    "SELECT photodata FROM photos"
       reader.Value = cmd.ExecuteReader
       reader.ReadNextRow
       Form1.Image = reader.GetImage(
    0)

    End Sub
    produces an error:

    'File opened that is not a database file
    file is encrypted or is not a database
    Continue?'

    The 'capture' routine:

    Code:
    Dim img
       
       pfn = 
    camera.GetImage( 6404800"Form1""Camera" )

       
    Msgbox( pfn )

       
    If pfn <> "" Then

          query = 
    "REPLACE INTO photos ( id, photodata ) VALUES ( 1, " & cmd.FileToBLOB( pfn ) & " ) WHERE ( id = 1 )"

          cmd.CommandText = query
          cmd.ExecuteReader

       
    End If

    End Sub
    produce an error:

    'File opened that is not a database file
    near 'WHERE': syntax
    error
    Continue?'


    The entire program follows:

    (the 'camera' object is from dz's camera capture library; 'con' and 'cmd' are SQL library objects)

    Code:
    Sub Globals

       dbfn = 
    ""

    End Sub

    Sub App_Start

       Con.New1
       Cmd.New1( 
    "", con.Value )
       dbfn = AppPath & 
    "\photos.s3db"
       Con.Open( 
    "Data Source = " & dbfn )

       reader.New1

       
    camera.New1


       formHeader.Color = cBlack
       formHeader.FontColor = cWhite
       formHeader.FontSize = 
    9
       formHeader.Width = form1.Width
       formHeader.Height   = 
    23
       
       btnShow.Top = 
    25
       btnCapture.Top = 
    25


       Form1.Show

    End Sub


    Sub btnCapture_Click

       
    Dim img
       
       pfn = 
    camera.GetImage( 6404800"Form1""Camera" )

       
    Msgbox( pfn )

       
    If pfn <> "" Then

          query = 
    "REPLACE INTO photos ( id, photodata ) VALUES ( 1, " & cmd.FileToBLOB( pfn ) & " ) WHERE ( id = 1 )"

          cmd.CommandText = query
          cmd.ExecuteReader

       
    End If

    End Sub

    Sub btnShow_Click

       cmd.CommandText = 
    "SELECT photodata FROM photos"
       reader.Value = cmd.ExecuteReader
       reader.ReadNextRow
       Form1.Image = reader.GetImage(
    0)

    End Sub

    Sub btnClose_Click

       AppClose

    End Sub
    I'm slowly losing my mind in my old age; does anyone see what I'm doing wrong?


    Gary

    :sign0085:
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    How did you first create the database?
     
  3. willisgt

    willisgt Active Member Licensed User

    Problem solved

    I first created the database with SQLite Administrator.

    However, I found the problem - the syntax of this line:

    Code:
    query = "REPLACE INTO photos ( id, photodata ) VALUES ( 1, " & cmd.FileToBLOB( pfn ) & " ) WHERE ( id = 1 )"
    is completely incorrect. No whereclause was required for this REPLACE INTO.


    Gary

    :sign0161:
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice