473,549 Members | 3,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

insert blob

Having created a table with a longblob column, what is the insert syntax to
set the value of the longblob column? The data will be read from a file.
Jul 20 '05 #1
3 34317
"Frank Natoli" <fr****@nospam. com> wrote in message
news:eR******** *********@newsr ead3.news.atl.e arthlink.net...
Having created a table with a longblob column, what is the insert syntax to set the value of the longblob column? The data will be read from a file.


example:

UPDATE table_name SET filesize = $filesize, data = LOAD_FILE('$fil edata')
WHERE id = 1

where $filedata is equal to 'drive:/path/to/your/file'
Norman
--
Avatar hosting at www.easyavatar.com
Jul 20 '05 #2
Thanks. Will this work if the data in $filedata is binary? Or must I base64
the data first?

"Norman Peelman" <np******@cfl.r r.com> wrote in message
news:AN******** ***********@tor nado.tampabay.r r.com...
"Frank Natoli" <fr****@nospam. com> wrote in message
news:eR******** *********@newsr ead3.news.atl.e arthlink.net...
Having created a table with a longblob column, what is the insert syntax to set the value of the longblob column? The data will be read from a file.


example:

UPDATE table_name SET filesize = $filesize, data = LOAD_FILE('$fil edata')
WHERE id = 1

where $filedata is equal to 'drive:/path/to/your/file'
Norman
--
Avatar hosting at www.easyavatar.com

Jul 20 '05 #3
If $filedata is a file on your filesystem -> 'c:\\images\\it em_1.jpg' then
there appears to be no need to do anything. MySQL will load the data as-is.
If you 'read' $filedata into a variable first via fopen,fread,fcl ose then it
seems that you must either base64 or addslashes it before MySQL will except
it. In this case:

$data = '';
$fp = fopen($filedata ,'r');
while (!feof($fp))
{
$data .= fread($fp,1024) ;
}
fclose($fp);
$slashed_data = addslashes($dat a);
UPDATE table_name SET filesize = $filesize, data = '$slashed_data' WHERE id
= 1
---

notice no LOAD_FILE, and quotes around the variable...
Norman
--
Avatar hosting at www.easyavatar.com
"Frank Natoli" <fr*********@wo rldnet.att.net. nospam> wrote in message
news:KV******** *********@newsr ead2.news.atl.e arthlink.net...
Thanks. Will this work if the data in $filedata is binary? Or must I base64 the data first?

"Norman Peelman" <np******@cfl.r r.com> wrote in message
news:AN******** ***********@tor nado.tampabay.r r.com...
"Frank Natoli" <fr****@nospam. com> wrote in message
news:eR******** *********@newsr ead3.news.atl.e arthlink.net...
Having created a table with a longblob column, what is the insert syntax

to
set the value of the longblob column? The data will be read from a file.


example:

UPDATE table_name SET filesize = $filesize, data = LOAD_FILE('$fil edata')
WHERE id = 1

where $filedata is equal to 'drive:/path/to/your/file'
Norman
--
Avatar hosting at www.easyavatar.com

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
17774
by: Ole Hansen | last post by:
Hi, Is it possible to insert BLOB data without doing a select first? I have data available and want to insert a row with BLOB data. Should I use the callback function with OCILobWrite() or is it not possible at all without doing a select? How about using a temporary LOB? I have tried everything I could come up with but nothing seems to...
2
6857
by: Niraj | last post by:
Hi, I am trying to do bulk insert of binary data (array of bytes) in an Oracle table. The data type of the table is BLOB. I am using Oracle Objects for OLE (OO4O) in C++. The binary data that I have to insert is in the form of byte array. My problem is that the bulk inserts happen only as long as the length of array is less than 4K. Any...
15
12292
by: Daniel Schuchardt | last post by:
Hi @ all, i'm sure there was a psql-function to transfere my Blob-Data to the server but I can't remember. I have a script like this : UPDATE xy SET z = lo_import('localpath_and_file'); but i want to execute this script from the client and so my blob-data is
0
3133
by: Paul Kennedy | last post by:
I have a situation where I am utilizing code from MSDN to insert XLS files into a Microsoft Access Table in a column of Ole Object using VBA and DAO. That code also provides me with a method to extract the XLS files later. This works wonderfully. The Article is 103257, ACC: Reading, Storing, & Writing Binary Large Objects (BLOBs)...
11
22998
by: Chris Fink | last post by:
I have setup an Oracle table which contains a blob field. How do I insert data into this field using C# and ADO.net?
3
2900
by: Chris | last post by:
Hi all, I am trying to use System.Data.ODBC to insert a file into a binary field in SQL Server 2000. Now, before you yell at me, the reason I am doing this is that I am only writing intitial code against SQL, but this app will need to be able to run against any ODBC compliant DB, so I am also not using stored procedures. I have tangles...
1
16206
by: shallowpool | last post by:
Can someone provide me the simple syntax necessary to insert or update to a row containing a single BLOB column, where the BLOB data will be obtained from a file? This is on a linux installation. The table has 2 INTs and 1 BLOB column. So, I've scoured various docs and such, and the closest I've come up with is some sort of animal that...
0
5172
by: Nesa | last post by:
Hi, I am accessing DB2 8.2 (Windows) via JDBC type 4 and am having troubles making Blob.setBinaryStream(long) work to update a BLOB column. Here is the excerpt of code that I am using: Connection conn = ds.getConnection(); conn.setAutoCommit(false); // insert a file FileInputStream fis = new FileInputStream(fileName);
2
5022
by: wizardry | last post by:
hello - i'm trying to insert a blob into my table, it will insert but the string that i insert when i query the inserted data returns null with 0 bytes in the column. I have other tables set up this way and i'm able to insert text data into it with no problems. I've checked the database design its basiclly a duplicate. I did have to remove...
0
7520
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7718
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7470
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6041
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5368
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5088
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3498
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...

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.