today i write a sql like this
<select id="selectVoByEtpsId" parameterType="java.lang.String"
resultMap="BaseResultMap" >
SELECT P.ETPS_APTT_PUTREC_ID, P.ETPS_ID, P.PARA_CD,P.PARA_VAL,
C.PARA_NAME,C.PARA_TYPE,C.PARA_SEQNO,P.CREATE_USER, P.INDB_TIME, P.UPDATE_USER,P.UPDATE_TIME
FROM USER_ETPS_APTT_PUTREC P
RIGHT JOIN USER_ETPS_APTT_CONFIG C
ON ETPS_ID=#{etpsId,JDBCTYPE=VARCHAR}
AND P.PARA_CD=C.PARA_CD
</select>
but i get error like this
org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalArgumentException: Result Maps collection already contains value for com.dao.IUserEtpsApttPutrecDao.BaseResultMap
at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:120)
when i change sql to this
<select id="selectVoByEtpsId" parameterType="java.lang.String"
resultMap="BaseResultMap" >
SELECT P.ETPS_APTT_PUTREC_ID, P.ETPS_ID, P.PARA_CD,P.PARA_VAL,
C.PARA_NAME,C.PARA_TYPE,C.PARA_SEQNO,P.CREATE_USER, P.INDB_TIME, P.UPDATE_USER,P.UPDATE_TIME
FROM USER_ETPS_APTT_PUTREC P
RIGHT JOIN USER_ETPS_APTT_CONFIG C
ON ETPS_ID=#{etpsId}
AND P.PARA_CD=C.PARA_CD
</select>
it works.
can anyone tell me why? thanks.
The error message states there are duplicate result map definitions with id BaseResultMap.
Furthermore, case for property names must be respected. Write ETPS_ID=#{etpsId,jdbcType=VARCHAR} or expect Error parsing SQL Mapper Configuration if you leave uppercase.
Related
I'm trying to find how should be the correct syntax for Sum(FIELD) where field Condition=Value
I'm using this code;
if ({VatCodes.VatValue} =12) then Sum({InventoryTransTemp.Price})
The problem is that this syntax works but for all my report fields and either contain this value or not.My syntax in sql server is Select Sum(InventoryTransTemp.Price) where Vatcodes.VatValues=12.
How should i write it for succedd my desired result?
I get this error when trying out this command in the BIRT Classic Models sample database in Data Studio
select xmlelement(name "custno", customers.customernumber) from customers
Syntax error: Encountered "\"custno\"" at line 1, column 24.
I do not know how to correct it.
Thanks.
I'm not familiar with db2, but according to this your statement looks quite alrigth (although I'd place an alias to name this field...)
But this
Syntax error: Encountered "\"custno\"" at line 1, column 24.
seems to be a quite clear hint, that your error is connected to the NAME of the element.
I'm pretty sure, that this statement was created on string level.
Did you try to escape the "-characters with \"?
The SQL reaching the engine might look like
select xmlelement(name \"custno\", customers.customernumber) from customers
or
select xmlelement(name "\"custno"\", customers.customernumber) from customers
... which is wrong of course...
But to be honest: just guessing...
I've been having trouble with eloquent that keeps returning error. Below is the query that i tried to run in laravel.
$actives = ProjectVersion::join('version_employees as ve', 've.report_id' ,'=', 'project_versions.id')
->join('employees as e', 've.employee_id', '=', 'e.id')
->whereBetween(\DB::raw("'1985-05-27'::date"),[
\DB::raw("to_date(timeline->>'start_time', 'YYYY-MM-DD')"),
\DB::raw("to_date(timeline->>'release_time', 'YYYY-MM-DD')")])
->groupBy('e.name')
->select(\DB::raw('count(e.id), e.name'))
->get();
Now this returns an error of
Invalid datetime format: 7 ERROR: invalid input syntax for type date: "to_date(timeline->>'start_time', 'YYYY-MM-DD')"
The full query returned by the error message is
SELECT count(e.id), e.name
FROM "project_versions" inner join "version_employees" as "ve" on "ve"."report_id" = "project_versions"."id" inner join "employees" as "e" on "ve"."employee_id" = "e"."id"
WHERE '1985-05-27'::date
BETWEEN to_date(timeline->>'start_time', 'YYYY-MM-DD')
AND to_date(timeline->>'release_time', 'YYYY-MM-DD')
GROUP BY "e"."name"
The thing is that when i run this query in pgadmin, it runs fine and returns the result that i wants.
I've been stuck for hours debugging this. Any idea on where the problem is ?
Well first off, it's not really eloquent in the way you're using it with all those Raw statements ;-)
Try using the Carbon class: Carbon::now()->toDateString() will return a date in the Y-m-d format.
For the where clause, if I'm understanding your query correctly, you can use 2 where clauses instead of the whereBetween with Raw SQL: ->where('start_time', '>', $start_time_preprocessed_by_carbon)->where('release_time', '<', $release_time_preprocessed_by_carbon)
And you seem to want the count which means you can end with a ->count() instead of a ->get()
I'd love to give you the full query but couldn't decipher it completely. However these implementations should give you a nudge in the right direction! They will help you abstract your query further to the point that Laravel's internal query generator will translate the code into the correct syntax for your database!
I have this Linq To Entites query below. When I execute this query from a Console Application, it produces SQL and executes perfectly.
But when I execute it from a web application, I get an error message that says the Min() function is not recognized by Linq To Entites and it cannot be translated to a store expression.
It is EXACTLY the same query. Both project have the same settings (concerning EF 6) in their config files, and they reference the same assemblies.
from ce in db.CustomEvents
where ce.fld_start > DateTime.Now
group ce by ce.fld_ownerId into g
select new
{
fld_ownerId = g.Key,
next_appointement_date = g.Min(i => i.fld_start)
}
It seems this happens only when the Min aggregate is on DateTime property. I hadn't this issue when I had Min on decimals, for instance.
The error message I get when I execute this in the web site is this
LINQ to Entities does not recognize the method 'System.Nullable`1[System.DateTime]
Min[CustomEvent](System.Collections.Generic.IEnumerable`1[CustomEvent],
System.Func`2[CustomEvent,System.Nullable`1[System.DateTime]])'
method, and this method cannot be translated into a store expression.
But when I execute it from the Console app, it successfully generates the SQL statement below
SELECT
1 AS [C1],
[GroupBy1].[K1] AS [fld_ownerId],
[GroupBy1].[A1] AS [C2]
FROM ( SELECT
[Extent1].[fld_ownerId] AS [K1],
MIN([Extent1].[fld_start]) AS [A1]
FROM [dbo].[mtbl_CustomEvent] AS [Extent1]
WHERE [Extent1].[fld_start] > (SysDateTime())
GROUP BY [Extent1].[fld_ownerId]
) AS [GroupBy1]
Does anyone have a clue on what is happening?? Why the same query generates SQL when run in the console app, but fails with an exception when run in the web site??
UPDATE:
It seems that the problem was an ambiguity between two different implementations of Min<T>(this IEnumerable<T>) (.net's implementation, and our own implementation). Removing the "using OurLibrary;" namespace from the file fixed the problem.
After vittore's suggestion to use extension methods syntax we found that the problem was that in the web project we referenced one of our libraries that included an implementation of Min<T>(this IEnumerable<T>), and we also had the using OurLibrary.Namespace; directive in the file where the linq query was.
When we used the linq syntax, the compiler picked our implementation of Min for the query and did not throw any errors. Then, at runtime, the LINQ to Entities framework crashed because it could not recognise our implementation of Min.
from ce in db.CustomEvents
where ce.fld_start > DateTime.Now
group ce.fld_start by ce.fld_ownerId into g
select new
{
fld_ownerId = g.Key,
next_appointement_date = g.Min()
}
Here there was no compiler error.
But when we used the extension method syntax, the compiler stopped with an ambiguity error, and that's how we identified the problem.
db.CustomEvents
.Where(ce => ce.fld_start > DateTime.Now)
.GroupBy(ce => ce.fld_ownerId, ce => ce.fld_start)
.Select(g => new { g.Key, next_appointement_date = g.Min() })
Here the compiler threw an error of ambiguous call to .Min
It's weird that the compiler does not recognise the ambiguity in the Linq syntax. After all, linq is only syntactic sugar.
I'm using Subsonic 2.1 and I'm having an error with the next query:
SqlQuery queryResTitle = new Select(
new Aggregate(ResTitle.ResourceTitleIDColumn, "ResourceTitleID", AggregateFunction.GroupBy),
new Aggregate(ResTitle.ResourceTitleColumn, "ResourceTitle", AggregateFunction.GroupBy),
new Aggregate(VenVendor.TitleColumn, "Title", AggregateFunction.GroupBy),
new Aggregate(ResTitleStatus.StatusColumn, "Status", AggregateFunction.GroupBy))
.From(Tables.ResTitleOngoing)
.InnerJoin(ResTitleStatus.ResourceTitleIDColumn, ResTitle.ResourceTitleIDColumn)
.LeftOuterJoin(VenVendor.VendorIDColumn, ResTitle.VendorIDColumn);
I'm getting the error:
"The ORDER BY clause is invalid in
views, inline functions, derived
tables, subqueries, and common table
expressions, unless TOP or FOR XML is
also specified"
I also added .Top("1") but I still got the same error.
You should debug the generated query that SubSonic returns:
var queryString = queryResTitle.BuildSqlStatement();
and execute it in your favorite database administration tool.
Maybe you can figure out what's going wrong.