Welcome to Linux Forums!

With a comprehensive Linux Forum, information on various types of Linux software and many Linux Reviews articles, we have all the knowledge you need a click away, or accessible via our knowledgeable members.

Linux Forum ArticlesLinux ForumsLinux Forum DownloadsLinux Hosts
Home|Register|FAQ|Member List|Calendar|Unanswered Posts|Forum Rules|Today's Posts|Advanced Search|
SEARCH FOR IN
Go Back   Linux Forums > GNU Linux Zone > Servers
Reload this Page inserting into BLOB column type
Linux Forums
Linux Forums
Welcome To The Linux Forums!
Welcome to Linux Forums. We pride ourselves in being one of the largest Linux communities on the web, we encourage you to REGISTER on our forums and participate in the community. There are over 150,000 members ready to answer your questions. JOINING US today will allow you to make new posts, get support, send messages to other members and submit downloads to our downloads directory and many other great features!

Servers Anything server related, Apache, MySQL, Samba, server security, sendmail, exim, etc

Reply
 
Thread Tools Display Modes
Old 08-05-2003   #1 (permalink)
Allblack
Linux User
 
Allblack's Avatar
 
Join Date: May 2003
Location: Godzone
Posts: 414
inserting into BLOB column type

Maybe I got this totally wrong but I believe you can put MP3, video etc in a blob column.

How do I insert it? I believe mp3.com uses mysql to store there mp3 files.

Can anyone help me?
__________________
I am on a journey to mastering Linux and I got a bloody long way to go!!!
Allblack is offline   Reply With Quote
Old 08-05-2003   #2 (permalink)
genlee
Linux Engineer
 
Join Date: Jan 2003
Location: Lebanon, pa
Posts: 994
Same way you would text data:

INSERT into <table> (blob_col) values ('data here');

With something like perl you could just do this:

open(FILE, "/path/to/file");
$blob=<FILE>;
$query='insert into blob_table (blob) values (?);';
$sth=$db -> prepare($query);
$sth -> execute($blob);
genlee is offline   Reply With Quote
Old 08-05-2003   #3 (permalink)
Allblack
Linux User
 
Allblack's Avatar
 
Join Date: May 2003
Location: Godzone
Posts: 414
Thanks Genlee

Is there a way I can specify a path into the Insert command?
Something like Insert into mytable mp3column values(\path\to\mp3\)?

Let's say that I have all my files on the same box but in a different directory. What is the best way of doing this without using script
__________________
I am on a journey to mastering Linux and I got a bloody long way to go!!!
Allblack is offline   Reply With Quote
Old 08-06-2003   #4 (permalink)
genlee
Linux Engineer
 
Join Date: Jan 2003
Location: Lebanon, pa
Posts: 994
INSERT INTO blob_tabl (some_col) values(load_file('/path/to/file')); ;
genlee is offline   Reply With Quote
Old 08-06-2003   #5 (permalink)
Dolda2000
Linux Guru
 
Join Date: Oct 2001
Location: Täby, Sweden
Posts: 7,575
In that case, the easiest way to automate it is probably to run this command:
Code:
(for file in /path/to/files/*; do echo 'INSERT INTO blob_tabl (some_col) values (load_file('\'"$file"\''));'; done) | mysql -D some_db -u some_user -p
Dolda2000 is offline   Reply With Quote
Old 08-06-2003   #6 (permalink)
Allblack
Linux User
 
Allblack's Avatar
 
Join Date: May 2003
Location: Godzone
Posts: 414
Thanks guys, I will give that a go. Is there a special way to extract it as well? Lets say that I want to extract it to an other folder. Can I do this with a select statement?

Cheers
__________________
I am on a journey to mastering Linux and I got a bloody long way to go!!!
Allblack is offline   Reply With Quote
Old 08-06-2003   #7 (permalink)
andutt
Linux Engineer
 
Join Date: Apr 2003
Location: Sweden
Posts: 796
Use my program DBloader (engine) on my page (the link below) to load info of music or ftproot structures (or any other structure) in to mysql,mssql,postregsql..

you can easily modify it to load the mp3-file like a blob instead, if you need any help with that just let me know. Or if you have questions about the program.
__________________
Regards

Andutt
andutt is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 09:18 AM.




© 2000 - 2008 - All Rights Reserved - Property of  MAS Media

Content Relevant URLs by vBSEO 3.0.0