Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Storing images in a Database

Options
  • 04-12-2010 4:19am
    #1
    Registered Users Posts: 1,155 ✭✭✭


    Hi, before everyone comes and says don't, it's ok :) I don't actually want to store images in a database. From looking around on Google, everyone says to store the images somewhere else and then use a URI to point to it. However in most of these examples they then go onto demonstrate how to store images as BLOBs in a DB for some reason :confused:

    So i was wondering if anyone had an example of how to point to the images using URI's? Do i just declare another attribute in the database and store the URI's in here? If so is there any particular data type that should be used?

    At the moment i'm just messing around trying to get the structure and syntax correct in Oracle but i'll be starting development on an Android app after Christmas, so then i'll be using SQLite. If anyone could give me an example using either Oracle SQL or SQLite (or even just a psuedo-code example) that would be great.


Comments

  • Registered Users Posts: 1,452 ✭✭✭tomED


    You sound like you don't need code, but just some advice on how to approach it! :) I think you're thinking about it too much and expecting it to be really difficult!

    All you need to do is get the name of the file, save the name of the file in the db at the same time save the file to a location, (in your case) most likely the sd card.

    When you want to reference the image, simply use the save location and name of the file from the db to get the full path to the file.

    Make sense?


  • Registered Users Posts: 1,155 ✭✭✭johnnykilo


    Hi Tom,

    Yes that makes sense, thanks. So all i need to do is store the file name (possibly the path) as a varchar attribute in a table and that's it?


  • Registered Users Posts: 981 ✭✭✭fasty


    It is indeed that simple!


  • Registered Users Posts: 23,212 ✭✭✭✭Tom Dunne


    johnnykilo wrote: »
    Hi, before everyone comes and says don't, it's ok :) I don't actually want to store images in a database. From looking around on Google, everyone says to store the images somewhere else and then use a URI to point to it. However in most of these examples they then go onto demonstrate how to store images as BLOBs in a DB for some reason

    I would imagine one of the reasons is for backup/recovery (and possibly performance). If images are stored outside of the database, they need to be backed up in a different manner to regular data that is inside the database.

    Plus, from a performance perspective, pulling images from a database would probably be quicker than pulling them from a filesystem.


  • Registered Users Posts: 1,452 ✭✭✭tomED


    Tom Dunne wrote: »
    Plus, from a performance perspective, pulling images from a database would probably be quicker than pulling them from a filesystem.

    Not at all. It would be much quicker to pull directly from the filesystem than the db itself.


  • Advertisement
Advertisement