Hi, I am not sure if I am encountering a Glorp bug or if my code is incorrect. Glorp creates a subselect referencing a table as s1t2 which is not used anywhere in the query. Here's my Smalltalk code: query := SimpleQuery read: KontolinoPurchase. query where: [:k | (k package id = 1) AND: (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1)) AND: (k dateWelcomeMail = nil)]. query where: [:k | k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]]]. And the resulting SQL code: SELECT t1.id, "long list of columns prefixed with t1" FROM DB2INST1.PURCHASE t1 WHERE EXISTS (SELECT s1t1.id, "long list of attributes prefixed with s1t1" FROM DB2INST1.USER s1t1 WHERE ((s1t1.company_id = s1t2.id) AND s1t1.active)) And this is what DB2 shouts at me: [SQLSTATE=42S22 - [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N "S1T2.ID" is not valid in this context. SQLSTATE=42703 [Native Error=-206]] I tend to absolutely agree with DB2 here. But what am I doing wrong in my subselect? There is a 1:n relationship between Purchase and User, and the purpose of the query is to find package purchases that were bought yesterday and the day before and which have not received a welcome mail yet. At least one of the users in that company have to be activated (otherwise we do not want to send a mail message to the company). Why does Glorp use a s1t2 prefix here? Any ideas are welcome Joachim You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/43abbfcc-13f1-41f4-91b0-5056d601f564%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. |
Hi Jocheim, Sorry I don’t have time to look at this in detail, but you might want to examine the glorp clauses and the SQL produced in GlorpDBTests. For example, GlorpAnySatisfyTest>>testAnySatisfyTwiceNested There is at least some overlap with your description. Hth, Dave
From: [hidden email] [mailto:[hidden email]]
On Behalf Of jtuchel Hi, I am not sure if I am encountering a Glorp bug or if my code is incorrect. Glorp creates a subselect referencing a table as s1t2 which is not used anywhere in the query. Here's my Smalltalk code: query := SimpleQuery read: KontolinoPurchase. And the resulting SQL code: SELECT t1.id, "long list of columns prefixed with t1" And this is what DB2 shouts at me: [SQLSTATE=42S22 - [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N "S1T2.ID" is not valid in this context. SQLSTATE=42703 [Native Error=-206]] I tend to absolutely agree with DB2 here. But what am I doing wrong in my subselect? There is a 1:n relationship between Purchase and User, and the purpose of the query is to find package purchases that were bought yesterday and the day
before and which have not received a welcome mail yet. At least one of the users in that company have to be activated (otherwise we do not want to send a mail message to the company). Why does Glorp use a s1t2 prefix here? Any ideas are welcome Joachim -- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/BY5PR13MB30319AD8B1D6730BF004CA52C9090%40BY5PR13MB3031.namprd13.prod.outlook.com. For more options, visit https://groups.google.com/d/optout. |
Sorry, Joachim, I’m the world’s absolute worst speller! Dave From: Wallen, David
Hi Jocheim, Sorry I don’t have time to look at this in detail, but you might want to examine the glorp clauses and the SQL produced in GlorpDBTests. For example, GlorpAnySatisfyTest>>testAnySatisfyTwiceNested There is at least some overlap with your description. Hth, Dave
From:
[hidden email] [[hidden email]]
On Behalf Of jtuchel Hi, I am not sure if I am encountering a Glorp bug or if my code is incorrect. Glorp creates a subselect referencing a table as s1t2 which is not used anywhere in the query. Here's my Smalltalk code: query := SimpleQuery read: KontolinoPurchase. And the resulting SQL code: SELECT t1.id, "long list of columns prefixed with t1" And this is what DB2 shouts at me: [SQLSTATE=42S22 - [IBM][CLI Driver][DB2/LINUXX8664] SQL0206N "S1T2.ID" is not valid in this context. SQLSTATE=42703 [Native Error=-206]] I tend to absolutely agree with DB2 here. But what am I doing wrong in my subselect? There is a 1:n relationship between Purchase and User, and the purpose of the query is to find package purchases that were bought yesterday and the day
before and which have not received a welcome mail yet. At least one of the users in that company have to be activated (otherwise we do not want to send a mail message to the company). Why does Glorp use a s1t2 prefix here? Any ideas are welcome Joachim -- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/BY5PR13MB30310B1CA8130CDB0F50D25AC9090%40BY5PR13MB3031.namprd13.prod.outlook.com. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by jtuchel
Hi Joachim, maybe it is a side effect of twice setting the where-block for
the query? At least I cannot see anything wrong, and we also have
exists-queries written that way that work. I assume you simplified the code for testing the exists only and
modified the where: assignment. Or did you want to add the exists
with AND: instead of where:? Thomas Am 14.05.2019 um 12:05 schrieb jtuchel:
-- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/3c440e6a-1285-86e7-55cf-ddc77cf4e0cf%40porabo.ch. For more options, visit https://groups.google.com/d/optout. |
Hi Thomas,
thanks for taking such a sharp look at
my code. Indeed, I had a "second" where: in my code. *facepalm*
So I replaced the second where: with
AND:
Unfortunately, it doesn't solve the
problem, however. Instead I now have two ;-)
The first one is that the prefix s1t2
ist still there. The second is that I get another Error which says
there is no decscrptor for User. I seem to remember this is a bug
which has been discussed here and needs some extra care with
#asGlorpExpressionOn: and such. I need to investigate further.
I also tried expressing this with only
a single block (you are of course right, the code I wrote here is
a simple extract from the original) and still I get the s1t2
problem:
query := SimpleQuery read:
KontolinoPurchase.
query where: [:k | (k package id = 1) AND: (k dateOfPurchase between: (Date today subtractDays: 2) and: (Date today subtractDays: 1)) AND: (k dateWelcomeMail = nil) AND:
(k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]])]. Joachim
Am 15.05.19 um 10:58 schrieb Thomas
Brodt:
-- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel [hidden email] Fliederweg 1 http://www.objektfabrik.de D-71640 Ludwigsburg http://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1-- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/a1510648-d301-0ce1-86f8-f985cca2fe7c%40objektfabrik.de. For more options, visit https://groups.google.com/d/optout. |
I'm guessing here, but the problem you refer to is probably that when building complex queries, a block can either get built without a proper base expression, or you can get it built with two different base expressions. So if there are two different ones, you could get the problem that they don't know about the joined tables that each other has created, so you can get an orphan table like s1t2. And if a base expression doesn't have a descriptor associated with it then you could get the second error. The usual fix is to explicitly do an asGlorpExpression on the baseExpression of the other part.
You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/CAGWHZ9-GmFDLAJ1uGCg3mMvMSjjCux9RXCD%2BC9LCAOo7pW0VGg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout. |
Alan,
this sounds reasonable. I just don't
understand it ;-)
Let me try to rephrase:
I'd ask the query after it has been
created with #where: for its #baseExpression and then
send asGlorpExpressionOn: baseExpressionFromFirstPart to
the Block that's handed over to AND: ?
Joachim
Am 15.05.19 um 15:26 schrieb Alan
Knight:
-- ----------------------------------------------------------------------- Objektfabrik Joachim Tuchel [hidden email] Fliederweg 1 http://www.objektfabrik.de D-71640 Ludwigsburg http://joachimtuchel.wordpress.com Telefon: +49 7141 56 10 86 0 Fax: +49 7141 56 10 86 1-- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/29908544-b8bc-4a11-26f0-b71a25f90695%40objektfabrik.de. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by jtuchel
Hi Joachim, have you tried (k exists: (Query read: User where: [:b | b company = k company AND: (b isActive)])) instead of (k exists: [Query read: User where: [:b | b company = k company AND: (b isActive)]]) giving the exists: a query in parentheses instead of a BlockClosure in square brackets? Thomas
Am 15.05.2019 um 11:41 schrieb
[hidden email]:
-- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/c6541c88-cfd6-1830-9fb1-9321a19875ff%40porabo.ch. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Alan Knight
Alan,
I tried this:
query := SimpleQuery read: KontolinoPaketKauf.
But still get the same error....
Jaochim
You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/6e0c6868-6b44-a53a-0ad4-8b713edc5f8b%40objektfabrik.de. For more options, visit https://groups.google.com/d/optout. |
We had something like this: Query Maybe reducing the retrieve block to only one column and some constant for each rows helps? Thomas Am 15.05.2019 um 16:15 schrieb
[hidden email]:
-- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/bc667e31-d216-73aa-2983-a9f9b54f9865%40porabo.ch. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by jtuchel
Yes, exactly. Although now that I think about it I'd expect the and: operation to do that anyway. So there might be something more subtle going on, perhaps with a nested block.
You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/CAGWHZ9-PvrBRTFXBAdv%3DW2jp-2cnme-8ym08t5hn%2B0NQ%2B-5yMw%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Thomas Brodt
In general, reducing the fields that subqueries retrieve to only the
ones you need to satisfy their conditional function is likely to
simplify the SQL generated and improve performance.
On 5/15/2019 8:26 AM, Thomas Brodt
wrote:
-- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/3019bba9-9b83-3ecf-c418-3bb76b3aeb89%40gmail.com. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Thomas Brodt
Thomas, thanks again for taking time to look at my problem. Unfortunately, it seems this still doesn't work. I now tried this: query := SimpleQuery read: KontolinoPaketKauf. query where: [:k | |sub| sub := Query read: Benutzer where: [:b | b mandant = k kunde AND: (b aktiv)]. sub retrieve: [:x| 'hit']. (k paket id = 1) AND: (k kaufDatum < Date today) AND: (k datumFrischAktiviertMail = nil) AND: (k exists: sub)]. and still got this SQl statement: SELECT t1.id, "long list of all mapped attributes in that table, not relevant here" FROM DB2INST1.PAKETKAUF t1 WHERE ((( (t1.paket_id = 1) AND (t1.DATUM < '2019-05-17')) AND (t1.DAT_AKTIVIERT_MAIL IS NULL)) AND EXISTS ( SELECT 'hit' FROM DB2INST1.BENUTZER s1t1 WHERE ((s1t1.firma_id = s1t2.id) AND s1t1.aktiv))) So the table pefix s1t2 is still occuring in this SQL and leads to an SQL error, the JOIN is not correctly determined. I'm giving up on this. I have also tried a few variations of sending several asGlorpExpressionOn: variants and stuff and never get any useful SQL. Joachim Am Mittwoch, 15. Mai 2019 16:26:35 UTC+2 schrieb Thomas Brodt:
You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/afa0a154-d575-4a9d-a290-cd6d6c496d04%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by Tom Robinson
Yeah, I'm a big fan of good performance, once things work ;-) I admit the SQL in my last attempt using the retrieve: trick makes the SQL much more readable as well. If only it was correct as well... Am Mittwoch, 15. Mai 2019 19:34:58 UTC+2 schrieb Tom Robinson:
You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/f4161294-6caf-455c-aac5-2440ba6eda10%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by jtuchel
Hi again, I've spent a little time with this, although I had decided to give up ;-) And I am not sure I am getting better in understanding all this, but I thought I'd share a little bit of what I found so far.. So I went and loaded GlorpTests into my VAST image and browse arund a little. And it seems there is a much simpler way to achieve what I want by using anySatisfy: in a Glorp Query. So I tried this: query := SimpleQuery read: KontolinoPurchase. query where: [:k | (k package id = 1) AND: (k dateOfPurchase < Date today) AND: (k dateWelcomeMail = nil) AND: (k company users anySatisfy: [::usr| usr isActive])]. And this will also transform to an EXISTS subselect where the join is correct: SELECT t1.id, "many more" FROM (DB2INST1.PURCHASE t1 INNER JOIN DB2INST1.COMPANY t2 ON (t1.company_id = t2.id)) WHERE ( (((t1.package_id = 1) AND (t1.date < '2019-05-20')) AND (t1.date_welcome_mail IS NULL)) AND EXISTS ( SELECT t3.id FROM DB2INST1.USER t3 WHERE ((t3.active = 1) AND (t2.id = t3.company_id)))) I wasn't aware of the fact that you can use anySatisfy: in query blocks, but this is much more convenient and makes the ST and SQL code much nicer. This brings me to a new conclusion: since several people told me here and privately that they didn't encounter this problem (most of them using VisualWorks and/or another Database), there might be something wrong with the definitition of the EXIST and NOT EXISTS function in either DB2Platform on all Glorp Dialects or in the DB2Platform in the Glorp port on VAST. DB2Platform>>#initializeFunctions overrides the defintion of EXISTS and NOT EXISTS from DatabasePlatform. Unfortunately it does so in write-only manner that I am unsable to understand.... "Like Oracle, SQL Server doesn't allow functions like EXISTS in a field list, but will allow a select there as an argument to a function, such as CASE. So print it that way if we're in the select list." baseExists := functions at: #exists:. dbSpecificExists := DualRoleFunction new. dbSpecificExists function: '#exists:'. dbSpecificExists whereClauseVersion: baseExists. selectList := Case new argumentTypes: (Array with: (self varchar: 1) with: self integer with: self integer). selectList argumentModifierBlock: [:function :args | function base: args first. Array with: 'x' asGlorpExpression with: 1 asGlorpExpression with: 0 asGlorpExpression]. dbSpecificExists selectListVersion: selectList. dbSpecificExists type: self integer. functions at: #exists: put: dbSpecificExists. Please note: the comment mentions SQL server, but this snippet is taken from DB2Platform. Maybe that is a hint? I will look a bit further, but for now I'll see if I can express some of my EXISTS subqueries using anySatisfy: and thus make our Application a bit faster in some places... This leads me to a very interesting question. If EXIST can be done with anySatisfy: in a query Block, chances are I can also do a NOT EXIST using noneSatisfy:, right? As always, thanks for listening and giving me hooks for looking at the right places. Even if exists: and notExists: don't work for me on VAST/DB2, I have the feeling I can express most of what I need using #anySatisfy: and #noneSatisfy: (or with anySatisfy: not). Joachim You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/ca5cb7da-37c5-4f77-b14d-a11d8a7f38ce%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. |
Hi Joachim, It looks like your version of GlorpDatabase may be from 2012. The #initialize function and many other things have been updated since then, all available in
the Cincom public repository. Dave
From: [hidden email] [mailto:[hidden email]]
On Behalf Of jtuchel Hi again, I've spent a little time with this, although I had decided to give up ;-) And I am not sure I am getting better in understanding all this, but I thought I'd share a little bit of what I found so far.. So I went and loaded GlorpTests into my VAST image and browse arund a little. And it seems there is a much simpler way to achieve what I want by using anySatisfy: in a Glorp Query.
So I tried this: query := SimpleQuery read: KontolinoPurchase. query where: [:k | And this will also transform to an EXISTS subselect where the join is correct: SELECT t1.id, "many more" (((t1.package_id = 1) AND (t1.date < '2019-05-20')) AND (t1.date_welcome_mail IS NULL)) AND EXISTS ( SELECT t3.id I wasn't aware of the fact that you can use anySatisfy: in query blocks, but this is much more convenient and makes the ST and SQL code much nicer. This brings me to a new conclusion: since several people told me here and privately that they didn't encounter this problem (most of them using VisualWorks and/or another Database), there might be something wrong with the definitition of
the EXIST and NOT EXISTS function in either DB2Platform on all Glorp Dialects or in the DB2Platform in the Glorp port on VAST. DB2Platform>>#initializeFunctions overrides the defintion of EXISTS and NOT EXISTS from DatabasePlatform. Unfortunately it does so in write-only manner that I am unsable to understand.... "Like Oracle, SQL Server doesn't allow functions like EXISTS in a field list, Please note: the comment mentions SQL server, but this snippet is taken from DB2Platform. Maybe that is a hint? I will look a bit further, but for now I'll see if I can express some of my EXISTS subqueries using anySatisfy: and thus make our Application a bit faster in some places...
This leads me to a very interesting question. If EXIST can be done with anySatisfy: in a query Block, chances are I can also do a NOT EXIST using noneSatisfy:, right? As always, thanks for listening and giving me hooks for looking at the right places. Even if exists: and notExists: don't work for me on VAST/DB2, I have the feeling I can express most of what I need using #anySatisfy: and #noneSatisfy:
(or with anySatisfy: not). Joachim -- You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/BY5PR13MB3031318FC5E48EE1B7D829C3C9060%40BY5PR13MB3031.namprd13.prod.outlook.com. For more options, visit https://groups.google.com/d/optout. |
In reply to this post by jtuchel
To make things a little more interesting: I forgot to mention that we actually do use exists: and notExists: for some queries and have been doing so for years. So it is not a general problem with these queries. This also means my last "suspect" about #initializeFunctions is probably not very accurate ;-) I guess it's more likely there are some differences between the ones that work and ones that don't in the information provided in the mappings or such. But I've heard from several sources in the meantime that this problem once occured also in VisualWorks and on Postgres and has been fixed in Glorp on VW a while ago now... so chances are this is a VAST only problem these days... Joachim Am Montag, 20. Mai 2019 14:36:08 UTC+2 schrieb jtuchel:
You received this message because you are subscribed to the Google Groups "glorp-group" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. To post to this group, send email to [hidden email]. Visit this group at https://groups.google.com/group/glorp-group. To view this discussion on the web visit https://groups.google.com/d/msgid/glorp-group/e6f3a006-e635-412f-afec-6b90d43e295e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. |
Free forum by Nabble | Edit this page |