OpenBD / openbd-core

The original open source Java powered GPL CFML runtime engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Locale and database queries

LiQz0r opened this issue · comments

Hey,

I have a <cfquery> that I use to get some numbers from a Microsoft SQL database, and in Norway we use commas instead of dots for decimal separators. My problem arises when I try to calculate directly on the query result because it now contains commas. I could solve this by using Replace() but that gets messy quite fast.

Is there a way to tell OpenBD to ignore the host machine's locale and force it to a specific locale when dealing with database queries or am I missing something else? My hope is that there is some xml file like bluedragon.xml that allows me to set the locale.

I'm quite new to CF/OpenBD so forgive me if the answer to this is obvious.

Hi. I am not skilled with locale which use comma for decimal separator but when you look at the topic from a java perspective, how do you calculate? Can you use the comma for float values?
I did some research now and I wonder if you can tell your db to print dot instead of comma, aka setting a locale? Or use NumberFormat on the cfquery result cell...?

Thanks for taking time out of your day to answer me, dtsw!

The calculation I was talking about is actually me reusing the results from the first query in a second query to create a POINT (needed for geography datatype stuff) - which takes two decimal numbers, and is the source of the issue. I find it strange that the query result is formatted like this when all I do is perform a select statement and then read it out in another query.

The problem with having each query replace "," with "." or using using the NumberFormat is that this issue might be present elsewhere in the system as well. This system consists of a rather large codebase that I've recently begun working on which is why I'm hoping that there is some overarching way of eliminating the locale issue in the first place.

so, you do query of query (dbtype="query") ?
What driver are you using in connecting to MS SQL?

My queries look like this:
<cfquery datasource="#myDS#" name="someName">SELECT att1, attr2 ...</cfquery>
<cfquery datasource="#myDS#" name="someOtherName">SELECT ... WHERE #someName.attr1# AND #someName.attr2#</cfquery>

Is dbtype="query" recommended? According to http://openbd.org/manual/?/tag/CFQUERY if I set dbtype="query" on a <cfquery> then datasource should be blank, and that doesn't make much sense to me.

I use Microsoft's official driver (com.microsoft.sqlserver.jdbc.SQLServerDriver).

By the way, I confirmed my suspicion concerning the locale. I switched my (Windows) locale to US locale and it worked immediately without any other changes to my setup or the code itself.

if you do QueryOfQuery, you give dbtype="query" and in the SQL, you would select x from y where y is the name of the query you did in first place. Because y is the name of a cfquery result, you do not need a datasource when you select from that object.
I use QueryOfQuery with CFX Tags, they return an unordered query result and i select from that to have a specific order, like so:

<CFX_GroupJDO RELOAD="#cfxReload#" COMMAND="findAllByUsername" USERNAME="#SESSION.username#" NAME="unsorted" />
<cfquery dbtype="query" name="result">
	select *
	from unsorted
	order by name
</cfquery>
<cfdump var="#result#" />

i see your point in changing the Region of your Windows System, your Servlet container will use that and so also OpenBD will. But this changes all your cfm stuff to US locale, and this might not always be what you want... you could then also set a locale for the servlet container (jetty/tomcat) only to be different from your operating system...

I think changing the locale of my Tomcat might be the easiest route if I can't change it for OpenBD alone.

Thanks for your help!

Or you use SetLocale in Application.cfc / cfm

But if you want it container-wide, for Tomcat on windows, create a setenv.bat in the bin folder and put in:

set JAVA_OPTS=-Duser.language=fr -Duser.country=FR

with the correct letters for your selection if course ;)