Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LOAD,SAVE and RETRIVE PICTURE FROM MySql database USING DELPHI - HELP PLEASE !!!

Status
Not open for further replies.

havsys

Programmer
Jul 23, 2012
5
RS
Hello,

I need help with delphi project. I use delphi 2007 and MySql Database.

1. I want to load picture from TOpenPictureDialog to TImage (or TDBImage).
2. Picture from Timage (or TDBImage) I want to save to MySql database in table Picture field 'IMG'(longblob).
3. I want to retrieve image from my database table 'IMG' and show in TImage (or TDBImage).
4. I will have DBGrid on my main form. When I clik on GBgrid row or when I scroll GBGrid I want to see that picture are changing.
5. How to convert jpg to gif, or how to Shrink picture or limit picture to be H:161px and W:138px, that is a size of my TImage.

My database(MySql) have 4 table (contacts, city, country and picture).
Database will be small maybe 200 contacts so I think that saving picture in database is not a problem.

On my Main form I have DBGrid, TImage (or TDBImage), AddContact button, ChangeContact Button, DeleteContact Button,
ChoosePicture Button, Save and Cancel Button, and DBEdit's from AdoDataSet,
TAdoConnection,TAdoDataSet and DataSource, TOpenPictureDialog.

This is my database:
Code:
CREATE TABLE `picture` (
 `ID` int(10) unsigned NOT NULL auto_increment,
 `CAPTION` varchar(45) default NULL,
 `IMG` longblob,
 PRIMARY KEY (`ID`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 CREATE TABLE `country` (
 `ID` int(10) unsigned NOT NULL auto_increment,
 `NAME` varchar(45) NOT NULL,
 `AREACODE` varchar(45) default NULL,
 PRIMARY KEY (`ID`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 CREATE TABLE `city` (
 `ID` int(10) unsigned NOT NULL auto_increment,
 `NAME` varchar(45) NOT NULL,
 `ZIPCODE` int(5) unsigned default NULL,
 `COUNTRYID` int(10) unsigned default NULL,
 PRIMARY KEY (`ID`),
 KEY `FK_city_1` (`COUNTRYID`),
 CONSTRAINT `FK_city_1` FOREIGN KEY (`COUNTRYID`) REFERENCES `country` (`ID`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 CREATE TABLE `contacts` (
 `ID` int(10) unsigned NOT NULL auto_increment,
 `FIRSTNAME` varchar(45) NOT NULL,
 `LASTNAME` varchar(45) NOT NULL,
 `ADDRESS` varchar(45) default NULL,
 `PHONE` int(10) unsigned default NULL,
 `CITYID` int(10) unsigned default NULL,
 `PICID` int(10) unsigned default NULL,
 PRIMARY KEY (`ID`),
 KEY `FK_contacts_1` (`CITYID`),
 KEY `FK_contacts_2` (`PICID`),
 CONSTRAINT `FK_contacts_2` FOREIGN KEY (`PICID`) REFERENCES `picture` (`ID`),
 CONSTRAINT `FK_contacts_1` FOREIGN KEY (`CITYID`) REFERENCES `city` (`ID`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Thank you for your time and knowledge.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top