Discussion:
How to store files
(too old to reply)
ZeeGeek
2005-08-23 14:49:08 UTC
Permalink
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?unsub=3Dmysql-***@freebsd.csie.nctu.edu.tw
Haines, Charles A.
2005-08-23 17:08:25 UTC
Permalink
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: ***@nv.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:***@gmail.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?unsub=***@nv.doe.gov
--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
To unsubscribe: http://lists.mysql.com/plusplus?unsub=mysql-***@freebsd.csie.nctu.edu.tw
ZeeGeek
2005-08-23 17:24:53 UTC
Permalink
Post by Haines, Charles A.
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
Post by Haines, Charles A.
in a directory structure and store a file path in the database. This met=
hod
Post by Haines, Charles A.
keeps the database small, while maintaining the file structure.
=20
yeah, I was thinking about that. I think I'll follow your suggestion.
Post by Haines, Charles A.
--chuck
=20
--
Charles Haines
Software Engineer / QA
Remote Sensing Lab - Andrews
------------------------------
Phone: (301) 817-3409
Pager: (800) 759-8888 #1209278
------------------------------
=20
This e-mail and any attachments may contain privacy act information. If y=
ou
Post by Haines, Charles A.
received this message in error or are not the intended recipient, you sho=
uld
Post by Haines, Charles A.
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
Post by Haines, Charles A.
you for your cooperation.
-----Original Message-----
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.
Post by Haines, Charles A.
Do I use a char * to store the file into the memory and then put it in th=
e
Post by Haines, Charles A.
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
e.gov
Post by Haines, Charles A.
=20
=20
=20
--
MySQL++ Mailing List
For list archives: http://lists.mysql.com/plusplus
com
Post by Haines, Charles A.
=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?unsub=3Dmysql-***@freebsd.csie.nctu.edu.tw
Chris Frey
2005-08-23 21:17:34 UTC
Permalink
Post by Haines, Charles A.
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?unsub=mysql-***@freebsd.csie.nctu.edu.tw
Warren Young
2005-08-24 09:12:05 UTC
Permalink
Post by ZeeGeek
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?unsub=mysql-***@freebsd.csie.nctu.edu.tw
Warren Young
2005-08-24 09:13:21 UTC
Permalink
Post by Haines, Charles A.
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?unsub=mysql-***@freebsd.csie.nctu.edu.tw
Loading...