Forums
Welcome
• Lo
gin
• Wa
Query.get tch
SingleRes Lis
Top of Form
ult returns t
Reply »
a Vector? 10903682
• Be
gin
2010 Jan Bottom of Form
ner
11 03:53 s
Qui
ck
Hallo Sta
rt
I tested on glassfish 2.1 with
oracle.toplink.essentials.PersistenceProvider. Running a • My
test with the entitymanager i noticed that getSingleResult For
returns a vector containing only one element rather than um
an object that i could cast accordingly. s
• Fee
Looking in the web and also taking a look at the spec all dba
example cast the result directly rather than assuming a ck
vector/list. • FA
Q
Since the specification just wants Object as result type
this is not wrong but does that really pass compatibility • Co
tests? de
of
regards Co
ndu
ct
Top of Form
Top of Form
Bottom of
10903962
jtahlborn Form
Re: Query.getSingleResult returns a Vector? Search
Posts:2.066 2010 Jan 11 08:14 (reply 1 of 8) (In reply to original Reply » Forums
post ) D is c u s s io n »F o r u m
Registered: Bottom of
26/01/08 Form f o r u m s .s u n .c o m
Search
Top of Form
10903971
mark197
1 Re: Query.getSingleResult returns a Vector?
Reply »
Registered:
Bottom of
2/28/03 Form
Content Feeds
The BINARY operator casts the string following it to a binary string. This is an easy way to
force a column comparison to be done byte by byte rather than character by character.
This causes
You arethe comparison
right to be case
it is not nailed down.sensitive
From myeven
bookif the
andcolumn is not defined as
various examples i thought that an Object or Object[]significant.
BINARY or BLOB . BINARY also causes trailing spaces to be was
returned
mysql> and'a'
SELECT you =then cast accordingly but maybe this is
'A';
-> 1
only true for hibernate. Since i am bound to toplink in this
mysql> SELECT BINARY 'a' = 'A';
case ->
i am0 screwed.
mysql> SELECT 'a' = 'a ';
Regarding
-> 1 the additional paramaeter, this also fails, i tried
thatSELECT
mysql> before: BINARY 'a' = 'a ';
Query query = em.createNativeQuery("select
count(*) from soc",Integer.class);
results in
[TopLink Warning]: 2010.01.11 06:24:23.070--
UnitOfWork(12359283)--Exception [TOPLINK-6007]
(Oracle TopLink Essentials - 2.1 (Build b60e-
fcs (12/23/2008))):
ption
Exception Description: Missing descriptor for
[class java.lang.Integer].
Query: ReadAllQuery(java.lang.Integer)
Exception in thread "main" Local Exception
Stack:
Exception
-> 0 [TOPLINK-6007] (Oracle TopLink
Essentials - 2.1 (Build b60e-fcs
In a comparison, BINARY affects the entire operation; it can be given before either
(12/23/2008))):
oracle.toplink.essentials.exceptions.QueryExce
operand with the same result.
ption
BINARY str is shorthand
Exception for CAST(
Description: BINARY).
str AS descriptor
Missing for
[class java.lang.Integer].
Note Query:
that in some contexts, if you cast an indexed column to BINARY, MySQL is not able
ReadAllQuery(java.lang.Integer)
to use the indexatefficiently.
• oracle.toplink.essentials.exceptions.QueryExce
CAST(expr AS type)
ption.descriptorIsMissing(QueryException.java:
The CAST()
419) function takes a value of one type and produce a value of another type,
similar
. to CONVERT(). See the description of CONVERT() for more information.
• CONVERT(expr,type), CONVERT(expr USING transcoding_name)
The CONVERT() and CAST() functions take a value of one type and produce a value of
Top of Form
another type.
jtahlborn
The type can be one of the following values:
Re: Query.getSingleResult returns a Vector?
Posts:2.066○ 2010
BINARY[(N)]
Jan 11 10:57 (reply 5 of 8) (In reply to #4 )
○ CHAR[(N)]
Registered: Bottom of
26/01/08 ○ DATE Form
○ DATETIME
○ DECIMAL[(M[,D])]
○ mark1971
SIGNED wrote:
[INTEGER]
You are right it is not nailed down. From my book and
○ various
TIME examples i thought that an Object or Object[] was
○ returned
UNSIGNEDand you then cast accordingly but maybe this is
[INTEGER]
only true for hibernate.
BINARY produces a string with the BINARY data type. See Section 10.4.2, “The BINARY
and VARBINARY
i think thatTypes” for a down
is all nailed description
for jpaofquery
how this affects comparisons. If the optional
language
lengthqueries,
N is given, BINARY(N) causes
just not for native queries.the cast to use no more than N bytes of the argument.
As of MySQL 5.0.17, values shorter than N bytes are padded with 0x00 bytes to a length
of N. speaking of which are you querying a table which is
CHAR(mapped
N) causesto an
theentity?
cast to ifuse
so,noyou could
more thandoNthis query using
characters of the argument.
the jpa query language, and then i think the result
The DECIMAL type is available as of MySQL 5.0.8.
would/should be a single value.
CAST() and CONVERT(... USING ...) are standard SQL syntax. The non-USING form of
CONVERT() is ODBC syntax.
CONVERT() with USING is used to convert data between different character
Top of Form sets. In
MySQL, transcoding names are the same as the corresponding character set names. For
mark197
example,
1 Re: this statement converts the
Query.getSingleResult string a'abc'
returns in the default character set to the
Vector?
corresponding
2010 Janstring in the
12 01:02 utf8 character set:
(reply 6 of 8) (In reply to #5 )
Posts:62
SELECT CONVERT('abc' USING utf8);
Registered:
Normally, Bottom of
2/28/03 you cannot compare a BLOB value or other binary string in case-insensitive
Form
fashion
because binary strings have no character set, and thus no concept of lettercase. To perform a
case-insensitive comparison, use the CONVERT() function to convert the value to a nonbinary
User Comments
Posted by Are you mortal? Then prepare to die. on November 3 2004 [Delete]
11:31am [Edit]
Be careful that this 'feature' of MySQL dosn't bit you in the ass.
For example, imagine I have a table with two 'unsigned' integer columns (still with me?). Lets
call those columns 'one' and 'two'. Now imagine the following query...
If the result of 'one - two' is negative (imagine that the value of two is bigger than one), then you
end up with values of 18446744073709551615.
This isn't a bug mind you, as this fact is documented this is the expected behaviour!
So, still looking for the 10 biggest differences you might try...
To convert to numeric, the convert() and cast() functions are less forgiving then the implicit
conversion when it comes to the data to be converted. If you want to convert "1a" or "1 apple",
"2 apples", " 3 things" to 1, 1, 2 and 3 respectivly, the cast and convert function will produce an
error. Instead use select 0+'1a', 0+'1 apple', 0+'2 apples', 0+' 3 things'.
Posted by Ronald Rudy on December 5 2006 5:07pm [Delete] [Edit]
Here's a workaround for not being able to cast/convert a value during table creation with just a
create:
The cast() function is amazingly useful when working with dates - not to mention date+time.
But there are REALLY useful practical situations where we'd HAVE to use this function. Here's
a case:
I want to pick all records from a table "Sales", where the "TransactionDate" field is between 25-
Dec-2007 and 25-Jan-2008. Bear in mind that the field is of type DateTime.
Here's the BASIC query that I'd put in a string if I were to do it in PHP:
In the above case, I'm assuming that $D1 and $D2 are posted variables in PHP. Unfortunately
The above line won't work. And THIS is where we can use the CAST() function.
For example:
Table T1
n: INT
n_squared: INT,
n n_squared
00
11
24
39
4 16
...
n n_squared
00
Posted by The Lynxy on March 9 2009 8:56am [Delete] [Edit]
MySQL 5.1 returns a 64-bit integer when using CAST(). For those looking to cast a 32-bit
signed integer to a 32-bit unsigned integer: you can use the function this way.
Converting -1062731519 to an unsigned integer (this number is the decimal value of
192.168.1.1):
To save others time in searching for something that wasn't immediately obvious to me...
A list of character sets is in 9.1.12. Character Sets and Collations That MySQL Supports,
http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html
Here's another workaround for the lack of data types: create your own conversion function. I am
working with a DB (unfortunately) converted from and used by MS Access. All the primary keys
are therefor of type INT(10) SIGNED. When UNIONing a constant integer (SELECT 0 AS Key)
with a queried value the result is of the wrong type. So, since "CAST(0 AS INT(10))" is not an
option I created my own:
Now, whenever I need to force a result to be of type int(10) I just run it through this function. I'm
sure it would work for other types too (although a bit more involved if converting between two
different classes of data such as numeric to alpha). Hope that helps.
Posted by guillaume - on June 23 2010 3:14pm [Delete] [Edit]