PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → [WB17] Error on initialization of a query
[WB17] Error on initialization of a query
Débuté par Gianni Spano, 26 mar. 2015 12:06 - 11 réponses
Posté le 26 mars 2015 - 12:06
Hello to all

I'm trying to extract some value from a MySql db based on this query

sSql is string dsMyQUery is Data Source bRes is boolean bDati is boolean nAnni is int=EditEtaAnniRis nMesi is int=EditEtaMesiRis nGiorni is int=EditEtaGiorniRis nRisposte is int=EDT_Risposte_esatte sSql="SELECT * FROM tfl_valori WHERE (" sSql+=nAnni+" BETWEEN eta_anni_min and eta_anni_max)" sSql+=" AND ("+nMesi+" BETWEEN eta_mesi_min and eta_,mesi_max)" sSql+=" AND ("+nGiorni+" BETWEEN eta_giorni_min and eta_giorni_max)" sSql+=" AND ("+nRisposte+" BETWEEN val_min and val_max)" sSql+=" AND tipo='C'" bRes=HExecuteSQLQuery(dsMyQUery,hQueryDefault,sSql) IF bRes THEN bDati=HReadFirst(dsMyQUery) IF bDati THEN STC_esatte=dsMyQUery.val_percentile+"°" END END
The 'bRes' field returns a 'False' value after the execution of the query.
And the 'HErrorInfo" says "Error in the SQL code of query. Unable to initialize the query.
Unexpected word: ,

If i execute this query using MySql Admin client the query is correct and i see the result correctly...
What does it means: Unxexpected word: , ????
Why this different beahviour?

Tips and trick are welcome.

Thanks in advance

Gianni
Posté le 26 mars 2015 - 12:21
Gianni,

it looks like you made a typo
BETWEEN eta_mesi_min and eta_,mesi_max)
should be
BETWEEN eta_mesi_min and eta_mesi_max)
Posté le 26 mars 2015 - 12:31
Hi Arie

Yes...now i see the "," before "mesi_max"
You have an eagle eye <img src="/NG2013_WEB/ui/smiley/5.gif" align=absmiddle border=0 alt=":D">

Thanks
Gianni
Posté le 26 mars 2015 - 12:48
Hello Arie

Despite the correction of typos in the query string, i'm unable to obtain the result from it.

the "HErrorInfo" fields (in debug mode) says:
"Error in the SQL code of query. Unable to initialize the query."

Any help??

Thanks
Gianni
Posté le 26 mars 2015 - 12:53
Giannni,

Can you grab the generated SQL from within the debugger (put it in the "watch" area).
And then test it in mysql admin?
Posté le 26 mars 2015 - 13:12
Arie,

Yes, i did a copy/paste from the "sSql" field that contains the generated sql script and executed in SqlYog (a MySql tool) and the query is executed without error showing me the correct result of the query.

I don't understand why..it is the first time.
This code is part of a LocalProcedure (Server) and not GlobalProcedure of the project.
The unique thing i see is this procedure has not been included in the GlobalProcedure.
Could it the reason why it not running??
Now, i try to move the code from LocalProcedure to GlobalProcedure to see if there is something that is annoying the execution of the query..

I will let you know..
Thanks again for your support.

Gianni
Posté le 26 mars 2015 - 13:38
Hello Arie

I confirm. The error "Error in the SQL code of query. Unable to initialize the query" continues to appear, despite the move from LocalProcedure (Server) to GlobalProcedure...

Is it possibile that the reason could be the number of BETWEEN's in the query???

I'm crazing...i don't understand why!!!!

Gianni
Posté le 26 mars 2015 - 14:17
Hi Gianni

There is a good chance that your problem comes from hQueryDefault... Try with hwithoutcorrection, as you are typing a query in specific MYSQL language

Or use the built in query editor to make your query and get the wlanguage compatible SQL code

Best regards
Posté le 26 mars 2015 - 14:19
Hi there,

In MSSQL we use:

bRes=HExecuteSQLQuery(dsMyQUery,hQueryWithoutCorrection,sSql)

So, Windev does not change anything in the 'query' code..
Posté le 26 mars 2015 - 15:38
Hello to all


Thanks for your suggestions...


Gianni
Posté le 26 mars 2015 - 17:33
Could be your field names, if ones called name or count or total etc.
Posté le 28 mars 2015 - 13:02
Hi Gianni,
are you sure you checked the sSql variable before execution?
Look at your second line - the following:

sSql+=nAnni+" BETWEEN eta_anni_min and eta_anni_max)"

I think it should be, something like this:
sSql+=nAnni+" BETWEEN " +NumToString(eta_anni_min)+ " and " + ............

Ofcourse if eta_anni_min is a field in your query then your code shouldn't be a problem, but if it is a VARIABLE it is a problem...

Steven Sitas