If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Query with >= doesn't work as I expect

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-29-11, 08:22
Digitstudios Digitstudios is offline
Registered User
 
Join Date: Aug 2011
Posts: 4
Query with >= doesn't work as I expect

Hello everybody, I've a question.
A client application that I can't change, sends queries like the following:

SELECT * FROM TABLENAME WHERE TABLENAME.FIELD1>='DUMMY ' AND
TABLENAME.FIELD1<='DUMMY '

filling the string dummy with spaces as the length of the field.
The interested field is a CHAR(9) type
In this case, the DB Manager returns zero records found, but if I try to execute the query manually trimming the spaces like the query below,

SELECT * FROM TABLENAME WHERE TABLENAME.FIELD1>='DUMMY' AND
TABLENAME.FIELD1<='DUMMY'

then the DB Manager returns records working very well..
Is there a way to solve this trouble???

Unfortunately I can't change the source query because I don't have the source code of the application

------------------------------------------------------------------------

Buongiorno a tutti, avrei un quesito.
Un applicativo che non posso modificare effettua alcune query su un db MySql con condizioni del tipo:

SELECT * FROM TABELLA WHERE TABELLA.CAMPO1>='STRINGA ' AND
TABELLA.CAMPO1<='STRINGA '
completando la query con tanti spazi quanti ne servono per raggiungere la dimensione del campo di tipo CHAR

Il database manager non restituisce alcun risultato, ma se provo ad eseguire esternamente la query, togliendo gli spazi

SELECT * FROM TABELLA WHERE TABELLA.CAMPO1>='STRINGA' AND
TABELLA.CAMPO1<='STRINGA'

il Db manager mi torna il risultato atteso.
Posso agire su qualche parametro di configurazione per risolvere il mio problema'
Reply With Quote
  #2 (permalink)  
Old 08-29-11, 09:25
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
Quote:
Originally Posted by Digitstudios View Post
A client application that I can't change...
if you cannot change it, you will have to live with it
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-29-11, 09:27
Digitstudios Digitstudios is offline
Registered User
 
Join Date: Aug 2011
Posts: 4
Quote:
Originally Posted by r937 View Post
if you cannot change it, you will have to live with it
Are you mocking me?
Reply With Quote
  #4 (permalink)  
Old 08-29-11, 09:37
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
no, i am telling you the truth

if your application generates a query that doesn't work properly, and you cannot change the application, then you will have to live with it
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 08-29-11, 09:55
shammat shammat is offline
Registered User
 
Join Date: Nov 2003
Posts: 2,407
You could try to change the CHAR(9) column to a VARCHAR(9) column.

But that might break other areas in the application if it relies on getting back 9 characters all the time for that column.
Reply With Quote
  #6 (permalink)  
Old 08-29-11, 10:17
Digitstudios Digitstudios is offline
Registered User
 
Join Date: Aug 2011
Posts: 4
Quote:
Originally Posted by shammat View Post
You could try to change the CHAR(9) column to a VARCHAR(9) column.

But that might break other areas in the application if it relies on getting back 9 characters all the time for that column.
It works fine.

Thank you!
Reply With Quote
  #7 (permalink)  
Old 08-29-11, 10:42
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
you say it works fine, but you need to check the whole application to make certain that this fixes the problem, but as you don't have access to the source coded thats going to be tough to prove that changing the daytype is sufficient

Either read the application's set up notes to find out if the datatype shoudl have been varchar from day one
OR
contact the application's author to find what they recommend. the problem is that you have fixed on issue, but there is no proof that you have resolved the underlying problem.
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #8 (permalink)  
Old 08-30-11, 05:54
Digitstudios Digitstudios is offline
Registered User
 
Join Date: Aug 2011
Posts: 4
Quote:
Originally Posted by r937 View Post
no, i am telling you the truth

if your application generates a query that doesn't work properly, and you cannot change the application, then you will have to live with it
Hi, looking better to the user guide of MySql I've tried to use this

SET sql_mode = 'PAD_CHAR_TO_FULL_LENGTH'

This directive solves my problem

Have a nice day.
Gianluca
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On