dbTalk Databases Forums  

How to store files

mailing.database.mysql-plusplus mailing.database.mysql-plusplus


Discuss How to store files in the mailing.database.mysql-plusplus forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
ZeeGeek
 
Posts: n/a

Default How to store files - 08-23-2005 , 09:49 AM






I'm not sure about how to store a file into the database. I know that
the field type is blob and I have to open the file with fstream in
binary mode. Do I use a char * to store the file into the memory and
then put it in the database?

--=20
Dell Inspiron 600m
Pentium-M 1.6G
512MB, 60G
ATI 9000 Mobility

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #2  
Old   
Haines, Charles A.
 
Posts: n/a

Default RE: How to store files - 08-23-2005 , 12:08 PM






To be honest, storing files in a database is a big debate. I wouldn't
recommend storing the files in the database as it causes the database to
become huge very quick. Rather another solution would be to store the files
in a directory structure and store a file path in the database. This method
keeps the database small, while maintaining the file structure.

--chuck

--
Charles Haines
Software Engineer / QA
Remote Sensing Lab - Andrews
------------------------------
Phone: (301) 817-3409
Pager: (800) 759-8888 #1209278
Email: hainesca (AT) nv (DOT) doe.gov
------------------------------

This e-mail and any attachments may contain privacy act information. If you
received this message in error or are not the intended recipient, you should
destroy this message and any attachments, and you are prohibited from
retaining, distributing, disclosing, or using any information contained
herein. Please inform us of the erroneous delivery by return e-mail. Thank
you for your cooperation.
-----Original Message-----
From: ZeeGeek [mailto:zeegeek (AT) gmail (DOT) com]
Sent: Tuesday, August 23, 2005 10:49 AM
To: mysql++
Subject: How to store files

I'm not sure about how to store a file into the database. I know that the
field type is blob and I have to open the file with fstream in binary mode.
Do I use a char * to store the file into the memory and then put it in the
database?

--
Dell Inspiron 600m
Pentium-M 1.6G
512MB, 60G
ATI 9000 Mobility

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu... (DOT) doe.gov



--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw


Reply With Quote
  #3  
Old   
ZeeGeek
 
Posts: n/a

Default Re: How to store files - 08-23-2005 , 12:24 PM



On 8/24/05, Haines, Charles A. <HainesCA (AT) nv (DOT) doe.gov> wrote:
Quote:
To be honest, storing files in a database is a big debate. I wouldn't
recommend storing the files in the database as it causes the database to
become huge very quick. Rather another solution would be to store the fi=
les
in a directory structure and store a file path in the database. This met=
hod
keeps the database small, while maintaining the file structure.
=20
yeah, I was thinking about that. I think I'll follow your suggestion.

Quote:
--chuck
=20
--
Charles Haines
Software Engineer / QA
Remote Sensing Lab - Andrews
------------------------------
Phone: (301) 817-3409
Pager: (800) 759-8888 #1209278
Email: hainesca (AT) nv (DOT) doe.gov
------------------------------
=20
This e-mail and any attachments may contain privacy act information. If y=
ou
received this message in error or are not the intended recipient, you sho=
uld
destroy this message and any attachments, and you are prohibited from
retaining, distributing, disclosing, or using any information contained
herein. Please inform us of the erroneous delivery by return e-mail. Th=
ank
you for your cooperation.
-----Original Message-----
From: ZeeGeek [mailto:zeegeek (AT) gmail (DOT) com]
Sent: Tuesday, August 23, 2005 10:49 AM
To: mysql++
Subject: How to store files
=20
I'm not sure about how to store a file into the database. I know that the
field type is blob and I have to open the file with fstream in binary mod=
e.
Do I use a char * to store the file into the memory and then put it in th=
e
database?
=20
--
Dell Inspiron 600m
Pentium-M 1.6G
512MB, 60G
ATI 9000 Mobility
=20
--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...) nv (DOT) do=
e.gov
=20
=20
=20
--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu... gmail (DOT) =
com
=20
=20

--=20
Dell Inspiron 600m
Pentium-M 1.6G
512MB, 60G
ATI 9000 Mobility

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #4  
Old   
Chris Frey
 
Posts: n/a

Default Re: How to store files - 08-23-2005 , 04:17 PM



On Tue, Aug 23, 2005 at 10:07:06AM -0700, Haines, Charles A. wrote:
Quote:
To be honest, storing files in a database is a big debate. I wouldn't
recommend storing the files in the database as it causes the database to
become huge very quick. Rather another solution would be to store the files
in a directory structure and store a file path in the database. This method
keeps the database small, while maintaining the file structure.
This is fine if the database and the filesystem are on the same machine,
or accessible from the same machine. Putting files in the database
harmonizes the access rules for getting at the data: you only need to
worry about the security settings of your mysql installation instead
of both your mysql and NFS/Samba/permissions filesystem setup.

Of course, it is a tradeoff, but sometimes it is valid to store files in
the database, especially if they are small.

As for how to do it, look at the cgi_image.cpp example for how to
retrieve it. For writing, ZeeGeek was correct originally: load the data
into memory and then put it into an SQL statement to write it to the
database. See the load_file.cpp example.

Alternately, if your mysql database is on the same machine as the file
you wish to load, and if the file is readable by the uid that mysql
is running as, then you can use the LOAD_FILE() sql function.

- Chris


--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #5  
Old   
Warren Young
 
Posts: n/a

Default Re: How to store files - 08-24-2005 , 04:12 AM



ZeeGeek wrote:
Quote:
I'm not sure about how to store a file into the database.
See examples/load_file. And please read the docs and all the examples
before posting another question. I've pointed you to such resources
several times now.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
  #6  
Old   
Warren Young
 
Posts: n/a

Default Re: How to store files - 08-24-2005 , 04:13 AM



Haines, Charles A. wrote:
Quote:
I wouldn't
recommend storing the files in the database as it causes the database to
become huge very quick.
Worse, a SQL database has a lot more overhead (on the order of 3x in
some tests I've seen) relative to the filesystem.

--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsu...ie.nctu.edu.tw



Reply With Quote
Reply




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



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.