New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JOIN queries return SQL error code -104 [DNET432] #429
Comments
Modified by: @cincuranetstatus: Open [ 1 ] => In Progress [ 3 ] |
Modified by: @cincuranetpriority: Critical [ 2 ] => Major [ 3 ] |
Modified by: @cincuranetComponent: Entity Framework support [ 10110 ] Component: http://ADO.NET Provider [ 10041 ] => |
Commented by: @cincuranet How does the LINQ query looks like? |
Commented by: José María Sánchez (jmsanchez) Hi Jiri, There's no LINQ query. I am not sure if the problem is in the information or structures that the Entity Framework is sending to the ADO NET Provider in order to create that query or in the ADO NET Provider itself. Wrong Query that returns sql error code -104 That query should be Possible explanation. I think that the symbol retrieved for "A" should be a "JoinSymbol" and not a normal "Symbol" in order for the rest of the process to have all the necessary information and create the query correctly. I beg your apologies. I've been struggling with this issue for several days and I have dived a bit into the ADO NET Provider code before contacting you. Best regards. |
Commented by: @cincuranet The root cause is how the SKIP clause is handled. I've fixed it. It's now even a simpler query. Could you send me an email (jiri (foobar) http://cincura.net) I would send you the fixed build to try it? We could see whether the fix is OK, as I was guessing the original LINQ query. |
Modified by: @cincuranet |
Modified by: @cincuranetstatus: In Progress [ 3 ] => Resolved [ 5 ] resolution: Fixed [ 1 ] Fix Version: 2.7.7 [ 10466 ] |
Modified by: @cincuranet |
Submitted by: José María Sánchez (jmsanchez)
Relate to DNET208
Is duplicated by DNET404
Hi all,
I am working on a project to create a front-end application for a Firebird database with Microsoft Lightswitch. I am using Firebird Server 2.5, Firebird NETProvider 2.7.5 and Firebird DDEX Provider 2.0.5. Some days ago I found a problem that has puzzled me for several days. I think that the issue is due to a problem in the NETProvider, but it also could be related to the information that the DDEX provider sends to NETProvider for generating the SQL queries.
I report it because I think it may be a bug and maybe could help others to solve a similar problem.
Simple SQL queries for screens displaying data from a single table seem to generate correctly, but I found a problem in complex JOIN queries for screens that display information from different related tables using Foreign Keys.
In my Firebird database I have several related tables. I include some of them as an example.
/* Original table name is "memos" */
CREATE TABLE "memos" (
"id_memo" INTEGER CONSTRAINT "IDPK_id_memo" NOT NULL PRIMARY KEY /* "id_memo" */ ,
"id_text_grup" INTEGER NOT NULL /* "id_text_grup" */
);
/* Original table name is "memos_data" */
CREATE TABLE "memos_data" (
"id_memo_data" INTEGER CONSTRAINT "IDPK_id_memo_data" NOT NULL PRIMARY KEY /* "id_memo_data" */ ,
"id_memo" INTEGER NOT NULL /* "id_memo" */ ,
"id_idioma" INTEGER NOT NULL /* "id_idioma" */ ,
"text" BLOB SUB_TYPE 1 /* "text" */
);
/* Original table name is "texts_grups" */
CREATE TABLE "texts_grups" (
"id_text_grup" INTEGER CONSTRAINT "IDPK_id_text_grup" NOT NULL PRIMARY KEY /* "id_text_grup" */ ,
"nom_grup" VARCHAR(255) CHARACTER SET UTF8 COLLATE UTF8 /* "nom_grup" */
);
/* Original table name is "idiomes" */
CREATE TABLE "idiomes" (
"id_idioma" INTEGER CONSTRAINT "IDPK_id_idioma" NOT NULL PRIMARY KEY /* "id_idioma" */ ,
"tag" CHAR(3) CHARACTER SET UTF8 COLLATE UTF8 /* "tag" */ ,
"descrip" VARCHAR(255) CHARACTER SET UTF8 COLLATE UTF8 /* "descrip" */
);
ALTER TABLE "memos" ADD CONSTRAINT "FK_memos_id_text_grup" FOREIGN KEY ("id_text_grup") REFERENCES "texts_grups"("id_text_grup") ON UPDATE CASCADE;
ALTER TABLE "memos_data" ADD CONSTRAINT "FK_memos_data_id_idioma" FOREIGN KEY ("id_idioma") REFERENCES "idiomes"("id_idioma") ON UPDATE CASCADE;
ALTER TABLE "memos_data" ADD CONSTRAINT "FK_memos_data_id_memo" FOREIGN KEY ("id_memo") REFERENCES "memos"("id_memo") ON UPDATE CASCADE;
The NETProvider returns the following SQL error code to my Lightswitch application.
FirebirdSql.Data.FirebirdClient Information: 0 : Command:
SELECT
"A"."Extent1"."id_memo" AS "id_memo",
"A"."Extent1"."id_text_grup" AS "id_text_grup",
"A"."Extent2"."id_text_grup" AS "id_text_grup1",
"A"."Extent2"."nom_grup" AS "nom_grup"
FROM ( SELECT FIRST (45) SKIP (0) "C"."id_memo" AS "id_memo", "C"."id_text_grup" AS "id_text_grup1", "D"."id_text_grup" AS "id_text_grup2", "D"."nom_grup" AS "nom_grup"
FROM "memos" AS "C"
INNER JOIN "texts_grups" AS "D" ON "C"."id_text_grup" = "D"."id_text_grup"
ORDER BY "C"."id_memo" ASC
) AS "A"
FirebirdSql.Data.FirebirdClient Information: 0 : Parameters:
[Microsoft.LightSwitch.DataService][Application:Error][LightSwitchApplication.SodecaCatalogDatasource:memos_All] An exception has occurred: Microsoft.LightSwitch.DataServiceOperationException: Se produjo un error al ejecutar la definición del comando. Vea la excepción interna para obtener detalles. ---> System.Data.EntityCommandExecutionException: Se produjo un error al ejecutar la definición del comando. Vea la excepción interna para obtener detalles. ---> FirebirdSql.Data.FirebirdClient.FbException: Dynamic SQL Error
SQL error code = -104
Token unknown - line 2, column 14
. ---> FirebirdSql.Data.Common.IscException: Dynamic SQL Error
SQL error code = -104
Token unknown - line 2, column 14
That query is not correct. It should be something like:
SELECT
"A"."id_memo" AS "id_memo",
"A"."id_text_grup1" AS "id_text_grup",
"A"."id_text_grup2" AS "id_text_grup1",
"A"."nom_grup" AS "nom_grup"
FROM ( SELECT FIRST (45) SKIP (0) "C"."id_memo" AS "id_memo", "C"."id_text_grup" AS "id_text_grup1", "D"."id_text_grup" AS "id_text_grup2", "D"."nom_grup" AS "nom_grup"
FROM "memos" AS "C"
INNER JOIN "texts_grups" AS "D" ON "C"."id_text_grup" = "D"."id_text_grup"
ORDER BY "C"."id_memo" ASC
) AS "A"
So to get a better idea of what was going on, I downloaded the trunk source code, studied it for some days and found a possible solution to this problem.
I am not really sure if this is the best way to solve the issue but now all is working as expected.
The generation process for this query is something like:
1) the inner query is generated JOINING tables "C" and "D"
2) next the provider generates an intermediate query for the result of the previous JOIN as "B"
3) finally the global query is generated. As it requires no more information and to simplify the final query, "B" is reused and renamed to "A"
Debugging the process I saw that the information for the JoinSymbol required to generate "A" was somehow lost in the process. That produces this issue because the provider does not have all the internal join information ("C" and "D") needed to create the external query for "A".
I changed the following and seem to have gotten it to work:
NETProvider\source\FirebirdSql\Data\Entity\SqlGenerator.cs
SqlSelectStatement CreateNewSelectStatement(SqlSelectStatement oldStatement,
string inputVarName, TypeUsage inputVarType, bool finalizeOldStatement, out Symbol fromSymbol)
{
fromSymbol = null;
}
Maybe this is not the best solution to solve the problem, but I include it as a possible solution.
Thank you very much for this wonderful project Jiri.
The text was updated successfully, but these errors were encountered: