Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4ppc (Windows Mobile) > Questions (Windows Mobile)
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Questions (Windows Mobile) Post any question regarding Basic4ppc.

Problem: fetch and store image to/from database

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-12-2008, 02:00 PM
willisgt's Avatar
Senior Member
 
Join Date: Aug 2007
Location: Nacogdoches, Texas USA
Posts: 162
Default Problem: fetch and store image to/from database

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

__________________
PC: Windows XP Pro SP3 / Basic4PPC v6.5
PPC: HTC 8925 (AT&T Tilt) / Windows Mobile 6
Reply With Quote
  #2 (permalink)  
Old 05-13-2008, 06:18 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,733
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

How did you first create the database?
Reply With Quote
  #3 (permalink)  
Old 05-13-2008, 03:10 PM
willisgt's Avatar
Senior Member
 
Join Date: Aug 2007
Location: Nacogdoches, Texas USA
Posts: 162
Default 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

__________________
PC: Windows XP Pro SP3 / Basic4PPC v6.5
PPC: HTC 8925 (AT&T Tilt) / Windows Mobile 6
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
MouseMove over Image - problem DaveW Questions (Windows Mobile) 10 11-04-2008 08:27 AM
send sms and store Roadrunner Questions (Windows Mobile) 3 10-24-2008 07:47 AM
Image problem with ImageButtons klaus Bug Reports 3 02-15-2008 08:10 AM
Getting ImageButton image from database glook Questions (Windows Mobile) 5 11-16-2007 07:31 AM
Image size problem agraham Bug Reports 4 10-24-2007 05:40 PM


All times are GMT. The time now is 09:26 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0