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.

Image usage with sqllite

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-09-2009, 01:41 AM
tremara1's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Ballarat Victoria Australia
Posts: 175
Default Image usage with sqllite

I am playing around trying to learn how to store images in a db. I have come up against an error I cant seem to lick. I have put the image in the db but when I select sql the image to an image control I get a 'specified cast not valid' error.
This is probably an obvious code snafu but I guess I will learn from it.
ps I am v6.80 and checked the manual my code seems close.
The example I am using is in the zip........
Thanks again guys...
Reply With Quote
  #2 (permalink)  
Old 07-09-2009, 09:51 AM
tremara1's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Ballarat Victoria Australia
Posts: 175
Default looks like the insert sql

I have tried a few more things it seems the problem is with the insert sql using addParameters and setParameters.......
It does not seem to save the blob image....
I tried a standard sql insert statement(a real cow to write with all those quotes) and it worked.....
Any chance the addParameters could work??
Anyone help??
Trev Ballarat Victoria Australia

Last edited by tremara1 : 07-09-2009 at 10:02 AM.
Reply With Quote
  #3 (permalink)  
Old 07-09-2009, 04:12 PM
Basic4ppc Veteran
 
Join Date: Dec 2008
Posts: 203
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Code:
Any chance the addParameters could work??
Should work fine.
Post the code you got now and somebody will tell how to change to using
parameters.

RBS
Reply With Quote
  #4 (permalink)  
Old 07-09-2009, 08:48 PM
tremara1's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Ballarat Victoria Australia
Posts: 175
Default

Code:
cmd.AddParameter("value1")
    cmd.AddParameter(
"value2")
    cmd.CommandText = 
"INSERT INTO picA VALUES (@value1,@value2)"
    con.BeginTransaction
        cmd.SetParameter(
"value1",txtId.text)
        cmd.SetParameter(
"value2",cmd.FileToBLOB(AppPath & "\abc.gif"))
        cmd.ExecuteNonQuery
    con.EndTransaction
This is the code I used to insert the image........this does the insert but the image(blob) part is not inserting properly when you look at the field in the db (sqllite expert personal a great tool) you can look at it as the hex or an image viewer. There is hex info but the image viewer shows blank. When I used the regular insert the image shows as a thumbnail when viewed in sqllite expert personal
Trev Ballarat Victoria Australia

Last edited by tremara1 : 07-09-2009 at 08:59 PM.
Reply With Quote
  #5 (permalink)  
Old 07-09-2009, 09:14 PM
Basic4ppc Veteran
 
Join Date: Dec 2008
Posts: 203
Awards Showcase
Beta Tester 
Total Awards: 1
Default

That code seems OK.
What is your create table SQL?
How did you decide the blob was not in the database?
Did txtId.text get in the database?

RBS
Reply With Quote
  #6 (permalink)  
Old 07-09-2009, 09:32 PM
Basic4ppc Veteran
 
Join Date: Dec 2008
Posts: 203
Awards Showcase
Beta Tester 
Total Awards: 1
Default

Just tried this out by adapting the example that is in the SQL help file and it all works fine:

Code:
Sub App_Start

    Form1.Show
    
    con.New1
    reader.New1
    
    con.Open(
"Data Source = " & AppPath & "\BlobTest.db3"'Opens the database.
    cmd.New1("CREATE TABLE IF NOT EXISTS pictures([NAME] TEXT, [IMAGE] BLOB)",con.Value)
    cmd.ExecuteNonQuery
      
    
'Save the image in the database (change the image name to an existing image file).
    cmd.AddParameter("value1")
    cmd.AddParameter(
"value2")
    cmd.SetParameter(
"value1""Image66.gif")
    cmd.SetParameter(
"value2", cmd.FileToBLOB(AppPath & "\Image66.gif"))

    cmd.CommandText = 
"INSERT INTO pictures values(@value1, @value2)"
    cmd.ExecuteNonQuery
    
    
'Load the image from the database.
    cmd.CommandText = "SELECT image FROM pictures"
    reader.Value = cmd.ExecuteReader
    reader.ReadNextRow
    Form1.Image = reader.GetImage(
0)

End Sub

RBS
Reply With Quote
  #7 (permalink)  
Old 07-09-2009, 10:09 PM
Basic4ppc Veteran
 
Join Date: Dec 2008
Posts: 203
Awards Showcase
Beta Tester 
Total Awards: 1
Default

For some reason I can't do this with a .jpg file and I get:
Specified cast is not valid at the last line:
Form1.Image = reader.GetImage(0)

Also tried with an image control, but same error.

How do show the .jpg blob with reader.GetImage(0) ?


RBS
Reply With Quote
  #8 (permalink)  
Old 07-10-2009, 06:55 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,733
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

cmd.FileToBlob and cmd.BytesToBlob create strings which can't be used with SetParameter. For now you will need to add the blob without using parameters (like in the example from the manual).
I will add this feature in the next update.
Reply With Quote
  #9 (permalink)  
Old 07-10-2009, 08:17 AM
Basic4ppc Veteran
 
Join Date: Dec 2008
Posts: 203
Awards Showcase
Beta Tester 
Total Awards: 1
Default

I thought I got it to work with a .gif. Will check again later.

RBS
Reply With Quote
  #10 (permalink)  
Old 07-10-2009, 08:31 PM
tremara1's Avatar
Senior Member
 
Join Date: Oct 2008
Location: Ballarat Victoria Australia
Posts: 175
Default thanks.....

Thanks everyone......just a bit relieved I was not missing something really basic.
I too tried the example from the manual and got it to work...again the team comes good.
Trevor
Ballarat Victoria Australia
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
Me And SQLLite Again ceaser Questions (Windows Mobile) 3 08-12-2008 04:36 AM
Dim memory usage JamesC Questions (Windows Mobile) 2 07-21-2008 08:09 AM
Way to decrease memory usage Andrew_572 Questions (Windows Mobile) 3 01-04-2008 09:44 AM
FormLib: download? Usage? laiyilam Questions (Windows Mobile) 2 09-10-2007 01:53 PM
Memory Usage Scubaticus Questions (Windows Mobile) 6 07-03-2007 05:37 PM


All times are GMT. The time now is 08:20 AM.


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