473,387 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Blobs

19
Can anyone please tell me how to decide which blob field to use?
I'm creating a DB using phpmyadmin and mysql. choices are
Tinyblob - maximum length of 255 characters.
Blob- maximum length of 65535 characters.
Mediumblob - maximum length of 16777215 characters.
Longblob - maximum length of 4294967295 characters.
How do i tell how many characters are in the images i want to use? does it depend on the file type (jpeg, gif, etc?) or the actual size of the image.
thanks,
Diz :confused:
Mar 1 '06 #1
6 1806
Banfa
9,065 Expert Mod 8TB
OK firstly I never bother putting images into a DB in that way, I put in a field that contains the name of the image file which can then be used to access the image file directly. This also doesn't have a problem of needing to know what size blob to use.

However should you wish carry on using a blob then you will have to decide the maximum size of image that you want to be able to store. The size of the image is only dependent of the type is so far as the different image types have different ways of storing and compressing the image and so result in a different size. Obviously (I think) the image size is also dependent on the size of the image and it's colour depth, amazingy the more information you wish to store the larger the size of the image file :D

Since you have not said what operating system you are using it is hard to tell you how to find out your image sizes but a couple of methods would be

Windows

In explorer the the view to "Details", the files will be listed with their approximate sizes in kBytes, if you want to know more accurately the right click on a file and select Properties and the files size in bytes will be displayed in the properties box.

On *nix the use of the ls or dir commands should provide the required information.
Mar 2 '06 #2
Diz
19
:p ok, i realise my questions are probably very basic, but give us a break, i'm just starting out!

I will go with your suggestion to link to the images....would that be a varchar field? maybe called link???
i'm also having trouble trying to link my tables together. i am using phpmyadmin and mysql. There isn't an option when creating the tables to specify a foreign key. Any idea how to do it?
thanks for your help,
Diz
Mar 2 '06 #3
Banfa
9,065 Expert Mod 8TB
lol, I don't mind basic questions :D

Yep VARCHAR(255) to hold the file name of the image, personally in my implementation I called the field filename but you may call it what ever you want (although I caution against using Supercalifragilisticexpialidocious as it will quickly become irritating to type :p )

OK I kind of need to know how you created your PRIMARY KEY to answer that but assuming like me that you used INT UNSIGNED then you just declare a field with a simlar type in second table.

Since the fields can have any name you want them to it is a good idea to use a naming convention for your PRIMARY and public keys. The convention I use is that the primary key in a table is always called ID and the reference to it in another table is called <TableName>IX but you can do it any way you want.

So you might get something like

Expand|Select|Wrap|Line Numbers
  1. CREATE TABLE IF NOT EXISTS CarManufacturer (
  2.   ID           INT UNSIGNED NOT NULL  AUTO_INCREMENT PRIMARY KEY,
  3.   Name      VARCHAR(255)
  4. );
  5.  
  6. CREATE TABLE IF NOT EXISTS CarModel(
  7.   ID                           INT UNSIGNED NOT NULL  AUTO_INCREMENT PRIMARY KEY
  8.   CarManufacturerIX    INT UNSIGNED
  9.   Name                      VARCHAR(255)
  10.  
  11. );
  12.  
When you fill in a CarModel entry you set CarManufacturerIX to the value of the ID field in CarManufacturer. You can then use this in your select statements like so

SELECT CarModel.Name AS Model, CarManufacturer.Name AS Manufacturer FROM CarModel, CarManufacturer WHERE CarModel.CarManufacturerIX=CarManufacturer.ID;

One of the problems of the naming scheme I use is that I can not use the USING keyword when JOINING tables because the USING keyword expects the column name to be the same in both tables.
Mar 2 '06 #4
Diz
19
thanks for replying so quickly. i used INT unsigned zerofill for PKs. (in all tables), but have named them exactly the same in each column. as following:

artwork
Field Type Null Default Links to Comments MIME
artworkID int(10) No
title varchar(25) No
dateCreated year(4) No 0000
category enum('Abstract', 'Figurative', 'Landscape') No Abstract
cost int(6) No 0
forSale enum('Yes', 'No') No Yes


Indexes :
Keyname Type Cardinality Field
PRIMARY PRIMARY 0 artworkID
title INDEX None title
dateCreated
category
cost
forSale

Space usage : Type Usage
Data 0 Bytes
Index 1,024 Bytes
Total 1,024 Bytes
Row Statistic : Statements Value
Format dynamic
Rows 0
Next Autoindex 1
Creation Feb 28, 2006 at 02:33 PM
Last update Feb 28, 2006 at 02:33 PM




artworkmedium
Field Type Null Default Links to Comments MIME
artworkID int(10) No 0000000000 auto
mediumID int(5) No 00000 auto


Indexes :
Keyname Type Cardinality Field
PRIMARY PRIMARY 0 artworkID
mediumID

Space usage : Type Usage
Data 0 Bytes
Index 1,024 Bytes
Total 1,024 Bytes
Row Statistic : Statements Value
Format fixed
Rows 0
Creation Feb 28, 2006 at 02:58 PM
Last update Feb 28, 2006 at 02:58 PM



medium
Field Type Null Default Links to Comments MIME
mediumID int(5) No 00000 medium -> mediumID auto
type enum('Acrylics', 'Charcoal', 'Ink', 'Pastels', 'Pencil', 'Oil', 'Canvas', 'Paper', 'Board') No Acrylics artworkmedium -> mediumID


Indexes :
Keyname Type Cardinality Field
PRIMARY PRIMARY 0 mediumID
type INDEX None type

Space usage : Type Usage
Data 0 Bytes
Index 1,024 Bytes
Total 1,024 Bytes
Row Statistic : Statements Value
Format fixed
Rows 0
Creation Feb 28, 2006 at 02:52 PM
Last update Feb 28, 2006 at 02:52 PM
Last check Feb 28, 2006 at 02:52 PM


So do i need to rename the fields that will be foreign keys?

thanks, Diz
Mar 2 '06 #5
Banfa
9,065 Expert Mod 8TB
So do i need to rename the fields that will be foreign keys?
No in all cases the names are arbitary, the concept of foreign keys is just that, a concept. In MySql this concept has no support in the underlying database system it just refers to a way in which you use the data stored in the tables.

The fact you have named your primary and foreign keys the same has no impact ecxept that when doing JOINs you can use the USING keyword.

For example, using the database structure you have provided, the following 2 select statements should return the same result

Expand|Select|Wrap|Line Numbers
  1. SELECT title, type 
  2.               FROM artworkmedium, artwork, medium 
  3.               WHERE artworkmedium.artworkID=artwork.artworkID 
  4.                  AND artworkmedium.mediumID=medium.mediumID;
  5.  
  6. SELECT title, type 
  7.               FROM artworkmedium 
  8.               LEFT JOIN artwork USING(artworkID) 
  9.               LEFT JOIN medium USING(mediumID);
  10.  
Because you have used the same name for your primary and foreign keys you can use both of these methods, because I use ID for primary keys and <TableName>IX for foreign keys I can only use the first of these 2 methods (in hindsight a possible mistake on my part but I am a C programmer and I named the fields in a programming manor rather than a database manor).



On your table structures I notice that the cost is in the artwork table, however I would have expect that a given piece of artwork produced on 2 different mediums would have 2 different costs (because it will be more expensive to reproduce on 1 medium than the other). In this case shouldn't the cost go into the artworkmedium table?
Mar 2 '06 #6
Diz
19
artworkmedium table is there solely to join the other two tables together. this is because each piece of artwork can be made up of more than one medium- eg pastels and oil on board. so i need to select three option from the medium table. Each piece of artwork is individually priced, so all works on canvas may be more expensive than works on paper, but the price will vary from painting to painting, hence the cost is in the artwork table...thanks so much for your help with this, you've made it much clearer :)
Mar 2 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Ole Hansen | last post by:
Hi, Is it at all possible to insert BLOBs using the Array Interface? Today I have an application using the array interface. It works fine but so far I haven't been using BLOBs. I insert...
7
by: Howard Lowndes | last post by:
My situation is that I am interacting PHP 4.1.2 to PostgreSQL 7.2.2 I have no difficulty inserting and managing BLOBs into the Large Object system table, and I have a user table called images...
7
by: Nilabhra Banerjee | last post by:
Hi, I am still not sure whether the BLOBS are actually stored in the database or they have the pointer to the database for that file in the filesystem. If I remove the files (sources) for BLOBS...
0
by: Bing | last post by:
Hi there, I am using the DB2 universal JDBC driver type 4 to insert BLOBs into a DB2 database. The Method I used for supplying the BLOB data value is setBinaryStream(). Everything works fine as...
2
by: Jerry LeVan | last post by:
Hi, I am just getting into large objects and bytea "stuff". I created a small db called pictures and loaded some large objects and then tried to do a restore. Here is how I got the dump. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.