Database With Users and Images - database

How to form database with users and images and to know every user which images belongs to him. For example if I have in database users with (id=1 name=Peter) and another user (id=2 name=Alex) and etc. ? How to know with FK and PK which images belongs to him, how to form this database ?

I suggest to store the location of the images in the database using VARCHAR datatype instead of any BLOB or other binary datatype.So you can use a column for ImageUrl Or path no need to use different table.
Storing the database location reduces the size of database greatly as well updating or replacing the image are much simpler as it is just an file operation instead of massive update/insert/delete in database.
Note:Before saving Image to actual folder don't forget to rename it Because uploaded image can have same name try to use GUID as it Gives unique value.
http://blog.sqlauthority.com/2007/12/13/sql-server-do-not-store-images-in-database-store-location-of-images-url/

Related

How does SQLITE DB saves data of multiple tables in a single file?

I am working on a project to create a simplified version of SQLite Database. I got stuck when trying to figure out how does it manages to store data of multiple tables with different schema, in a single file. I suppose it should be using some indexes to map the data of different tables. Can someone shed more light on how its actually done? Thanks.
Edit: I suppose there is already an explanation in the docs, but looking for some easier way to understand it better and faster.
The schema is the list of all entities (tables, views etc) (the database as a whole) rather than a database existing of many schemas on a per entity basis.
Data itself is stored in pages each page being owned by an entity. It is these blocks that are saved.
The default page size is 4k. You will notice that the file size will always be a mutliple of 4K. You could also, with experimentation create a database with some tables, note it's size, then add some data, and if the added data does not require another page, see that the size of the file is the same. This demonstrating how it's all about pages rather than a linear/contiguos stream of data.
It, the schema, is saved in a table called sqlite_master. This table has columns :-
type (the type e.g. table etc),
name (the name given to the entity),
tbl_name (the tale to which the entity applies )
root page (the map to the first page)
sql (the SQL used to generate the entity, if any)
note that another schema, sqlite_temp_master, may also exist if there are temporary tables.
For example :-
Using SELECT * FROM sqlite_master; could result in something like :-
2.6. Storage Of The SQL Database Schema

Can we Store and Retrieve Multiple Images in one SQL column?

Hello Everyone I'm new in programming. I am working on small project in my project
I have
windows form where user will upload 4 to 6 Images and i want to store these images
in SQL Database Table After that i want to retrieve these Images regarding one user.
Now my question is how can i store these images in one SQL column without any new row in Database Table?
Is it right way to store and retrieve Images ?
You store image names in your database, and not images themselves.
Also, store image names of the 4-6 pictures belonging to one customer in one cell and not a column. Try this, hope it works.
If you are going to store images rather than paths in the database use a varbinary field. Once in the database it is easy to use the images in reports (ssrs) of you can extract and use in your application.
There used to be an image datatype but that is being removed. Also consider the size of the image 1MB + and you really should be storing paths.
You will need to import your image and convert to varbinary. Example:
             
MemoryStream ms = newMemoryStream();
pictureBox1.Image.Save(ms,ImageFormat.Jpeg);
byte[] photo_aray = newbyte[ms.Length];
ms.Position = 0;
ms.Read(photo_aray, 0, photo_aray.Length);
Here is a link to a demonstration that should help: tutorial

How to attach and view pdf documents to access database

I have a very simple database in access, but for each record i need to attach a scanned in document (probably pdf). What is the best way to do this, the database should not just link to a file on the pc, but should copy and keep the file with it, meaning if the original file goes missing the database is moved or copied, the file should still be accessable from within the Database. Is This possible? and what is the easiest way of doing it? If is should i can write a macro, i just dont know where to start. and also when i display a report of the table, i would like to just see thumbnails of the documents.
Thank you.
As the other answerers have noted, storing file data inside a database table can be a questionable practice. That said, I wouldn't personally rule it out, though if you are going to take that option, I'd strongly suggest splitting out the file data into its own table in its own backend file. For example:
Create a new database file called Scanned files.mdb (or Scanned files.accdb).
Add a single table called Scans with fields such as FileID (AutoNumber, primary key), MainTableID (matches whatever is the primary key of the main table in the main database file), FileName (Text), FileExt (Text) and FileData ('OLE object', really just a BLOB - don't actually use OLE Objects because they will bloat the database horribly).
Back in the frontend, add a reference to Scans as a linked table.
Use a bit of VBA to upload and extract files from the Scans table (if you're interested in the mechanics of this, post a separate question).
Use the VBA Shell routine (if you must) or ShellExecute from the Windows API (= the better option IMO) to open extracted data.
If you are using the newer ACCDB format, then you have the 'attachment' field type available as smk081 suggests. This basically does most of the above steps for you, however doing things 'by hand' gives you greater flexibilty - for example, it allows giving each file a 'DateScanned' or 'DateEffective' field.
That said, your requirement for thumbnails will require explicit coding whatever option you take. It might be possible to leverage the Windows file previewing API, though I'd be certain thumbnails are a definite requirement before investigating this - Access VBA is powerful enough to encourage attempts at complex solutions, but frequently not clean and modern enough to allow fulfilling them in a particularly maintainable fashion.
There is an Attachment type under Data Type when you go into Design View of your table. You can add an attachment field here. When you go into the Datasheet view of the table you can select this field for a particular row and a window will open for you to specify the attachment. This will cause your database to quickly grow in size if you add a lot of large attachments.
You can use an OLE field in a table, but I would really suggest you not use this approach. The database is going to be HUGE in no time, and you're going to regret it.
Instead, you should consider adding a field that stores the path to the file, and keep the files in one folder on your network. Then you can use a SHELL() command to open the file. What's the difference between restoring an Access database and restoring PDF files if something goes wrong? This will keep your database at a manageable size and reduce the possibility of corruption.

Delphi 7-How to save pictures in a database

I have been trying to create a select-your-picture-and-upload function of a normal user's profile in Delphi 7, but I am running in some problems.
Basically what I want is the following:
User uploads a picture from a folder (which I have achieved through a normal
OpenPictureDialog component)
Said picture gets stored in a database, which is where I'm stuck.
The database is a normal access database.
The table has a unique ID to identify the members and next to that is the picture of each member on the "Picture field" (which is set as a BLOB object).
So in other words my question is the following:
What components do I need to use in order to save a picture to a specified place in my database?
I have found some random code in the net but I'm running into troubles understanding what it does.
ADOQuery.SQL.Text := 'SELECT PictureField FROM YourTable';
ADOQuery.Open();
ADOQuery.Edit();
TBlobField(ADOQuery.FieldByName('PictureField')).LoadFromFile('PathToPictureFile');
ADOQuery.Post();
You can use imageEn component.
Web Site url to get information and download trial

should user's avatar be a field in table OR searching through file systems?

There is a situation in which we can have a VARCHAR field for users's avatar and store their image name in that field like most of the apps.
The other approach which I'm interested in is removing that field and store user's avatar in a folder like avatars in which avatar's file name is an MD5 of user id. Then all we need to do is to do a lookup in avatar's folder to see is there any MD5(userid) in there, if there is not then we show the default picture.
The question is which approach would be more efficient for a huge social networking site, looking around in avatar's folder or avatar field in user table?
I should also note that we have folders based on date for example we have a folder in the name of 1000 and then another folder with the name of 2000. For example /avatar/1000 contains one thousand picture, and so on.
Having a single call to the database would be more efficient than having the call to pull back the user details from the database and a separate call to the file system check if a file exists.

Resources