Problem with MySql not changing an image into a BLOB - mysql

So i have a set of code which will enter specific data from a .sql file into Wamp to use for a database and place it into a table this table has images in it which are from the www folder in wamp aswell as another source folder in my system. calling the images from the www folder works fine but it keeps having the images from the source folder as NULL even though the path is correct.
Here is the table code
create table emp (
Picture LONGBLOB DEFAULT NULL,
Picture_Path varchar(20) DEFAULT NULL
)
Here is the table values
INSERT INTO emp (Picture, picture_path)
VALUES
(load_file('c:/kittens/cat1.jpg'),'/cat1.jpg')
I tried to change make sure i didnt make any mistakes but i am new to SQL so i cant really be sure exactly what i did wrong
edit sorry i changed my original code to show the part i had an issue with there is more code but i forgot to adjust the text to have no comma at the end

Related

mysql using the command line client- Image Loading

I am trying to load an image into mysql using the command line client and following is the the code that i have been using;
INSERT INTO AutomobileParts (Part_ID, Part_Name,Img_Path)
VALUES (
"101AA",
"BikePanel",
load_file("F:/PYQT Projects/bikepanel.jpg")
) WHERE i=1;
can someone please help me out in understanding as in where i am going wrong on entering this piece of code.
MySQL LOAD_FILE() reads the file and returns the file contents as a string.
That will probably not work with an image I guess.
Your field name "Img_Path" indicates that you only save the path in that field, not the image, and that the image itself is on your file system # F:/PYQT Projects/bikepanel.jpg. This would be the normal way of saving images: The image file itself is in some folder on your server and you save the path to that folder in your table.
So if you want to show the image you would select the saved path from your MySQL table and read the file with your respective programming language (e.g. PHP or whatever you are using).
This might do the job unless there is an issue with variable "i" below:
INSERT INTO AutomobileParts (Part_ID, Part_Name,Img_Path)
VALUES (
"101AA",
"BikePanel",
"F:/PYQT Projects/bikepanel.jpg"
) WHERE i=1;

SQL - Changing Stored img URL in SQL db to local file path

I have image URLs stored in my SQL database, but the source of the images has not been reliable recently and causing long load time on my pages. The contents of my database update regularly. Is there a method I can use to store the images locally and display the images on my page via my server file path? Most of the images or over 1 MB so I was told not to store them in SQL directly as a blob. I am using ASP, HTML, SQL Server
You can do something like this: Create a Column to store path to pictures.
Then in the ImagePath enter: For each image/images
C:Users/JohnDoe/Documents/Pictures/SQLimages/JohnDoe.jpg
Update !!!
Save the images in your chosen Directory for Example.
Currently Your Table might look like this:
ID ImagePath
---------------------------------
1 \\fakeURL\image111
2 \\fakeURL\image222
3 \\fakeURL\image333
4 \\fakeURL\image444
Once you have saved your images to chosen local folder you can run this script
UPDATE dbo.yourDatabase
SET Value = REPLACE(Value, '\fakeURL\', '')
WHERE ID <=100000 --arbitrary number can be any number
This will replace the current URL path to your local path(You won't have to manually enter path name).

MySQL - How to alter part of a table element while keeping part of it the same

I have a database table (let's call it MyTable). In this database there is a column of paths for a file, with paths such as "C:/Users/me/test.txt". I can find table objects with a given file like this:
select * from MyTable where path = "C:/Users/me/test.txt";
I also know how to get all objects whose paths are in a particular directory, like this:
select * from MyTable where path regexp "^C:/Users/me/.*$";
I have a new directory that all the files in the test folder was moved to, called newFolder, and I need to write a command to update the paths in the database table. For example, if the object's original path was saved in the database as "C:/Users/me/test.txt", I need the new value saved to be "C:/Users/newFolder/test.txt". I can figure out how to do it without the file name included (if just the path was present), but I'm not sure how to preserve the file name while updating the path. If anyone knows a way to do this I'd realy appreciate it. Thanks!
Have you read about the REPLACE() function?
UPDATE MyTable
SET path = REPLACE(path, 'C:/Users/me/', 'C:/Users/newFolder/');

importing a csv file into mysql as BLOB

I'm working on test scripts and I want to load the results.csv file into a database as a BLOB.
Basically I want my table to look like:
serial_number | results |.
So one row for each device. My code would look like this for a device with serial number A123456789 (changed names and path for simplicity). The table is called test.
create table test (serial_number varchar(20), results longblob);
insert into test values ('A123456789',load_file('C:/results.csv'));
When I do this, however, the second column which should contain a BLOB, comes out containing NULL, with no exceptions raised.
If I open my results.csv file in notepad, then save as .txt file with no changes whatsoever, I get exactly what I want when I run the same code substituting ".csv" with ".txt" in the path. Basically it would also solve my problem if I could load the csv file as a text file.
thanks for anything you may be able to contribute.

How can I insert blob in xml, using mysql?

I am using mysql and I'm trying to populate the database in build.xml.
How can I insert a blob file in this table:
CREATE TABLE CONTENT (
idContent varchar(30) not null,
price int,
url blob,
primary key (idContent)
);
I've tried this:
INSERT INTO CONTENT VALUES ("Tecnico.png", 0, LOAD_FILE("src/Tecnico.png"));
but the url return is null, then I tried the entire path to the .png and returned null to.
Can anyone help me please?
MySQL LOAD_FILE() reads a file that is already present on the server, do not uploads the file.
So, if the file is on the server, and the full path is something like "/var/www/[AnotherFolfer]/src/Tecnico.png"
Try, to use:
INSERT INTO CONTENT VALUES ("Tecnico.png", 0, LOAD_FILE('/var/www/[AnotherFolder]/src/Tecnico.png'));