tags:

views:

39

answers:

4

I have the this SELECT query that returns nothing from the specified table yet the path to the file is stored in that table;

SELECT * from tableName WHERE imageFile = "C:\Documents and Settings\Albert Bayita\Desktop\MovieImages\TheLordOfTheRingsTheFellowship.jpg";

Any advice is appreciated.

A: 

Your table tableName probably has no imageFile row with theat exact path.

Parhaps the path is stored differently (perhaps the \ is quoted to \)?

How do you know that is does exist exactly as you have entered in the query?

Oded
Well I know it exists in my database because I have been using it to load thumbnail images on a listview. I have been advised to use double slashes and I got what i expected. Thanks for the concern.
Albert
A: 

why you store the whole path in the database

you should figure out something to store just the image name

or if you want to keep on storing the whole path

try

to double the backslash \

SELECT * from tableName WHERE imageFile = "C:\\Documents and Settings\\Albert Bayita\\Desktop\\MovieImages\\TheLordOfTheRingsTheFellowship.jpg";
peacmaker
Thank you for your help. the double slash works perfect
Albert
you can always vote me up for the correct answer
peacmaker
A: 

You probably need to escape the backslashes. Try this to see what I mean:

SELECT "C:\Documents and Settings\Albert Bayita\Desktop";

I expect you'll see this

C:Documents and SettingsAlbert BayitaDesktop

Replace single backslashes by double backslashes in your query:

WHERE imageFile = "C:\\Documents and Settings\\Albert ... etc
martin clayton
Thank you Martin. The double slashes work perfect.
Albert
+4  A: 

The backslash character is the escape character in strings in MySQL. To put a backslash in a string literal in a query you have to escape it using double backslashes. Also a string in SQL uses apostrophes as delimiter, not quotation marks.

SELECT * from tableName WHERE imageFile = 'C:\\Documents and Settings\\Albert Bayita\\Desktop\\MovieImages\\TheLordOfTheRingsTheFellowship.jpg';

The best option is of course to use a parameterised query instead.

Guffa
Thank you very much Guffa for your help
Albert