Diese Seite mit anderen teilen ...

Informationen zum Thema:
Forum:
WinDev Forum
Beiträge im Thema:
12
Erster Beitrag:
vor 2 Jahren, 11 Monaten
Letzter Beitrag:
vor 2 Jahren, 11 Monaten
Beteiligte Autoren:
Gianni Spano, Arie, Steven Sitas, iso, Fabrice Harari, Harry W

[WB17] Error on initialization of a query

Startbeitrag von Gianni Spano am 26.03.2015 11: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

Antworten:

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)

von Arie - am 26.03.2015 11:21
Hi Arie

Yes...now i see the "," before "mesi_max"
You have an eagle eye :D

Thanks
Gianni

von Gianni Spano - am 26.03.2015 11:31
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

von Gianni Spano - am 26.03.2015 11:48
Giannni,

Can you grab the generated SQL from within the debugger (put it in the "watch" area).
And then test it in mysql admin?

von Arie - am 26.03.2015 11:53
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

von Gianni Spano - am 26.03.2015 12:12
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

von Gianni Spano - am 26.03.2015 12:38
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

von Fabrice Harari - am 26.03.2015 13:17
Hi there,

In MSSQL we use:

bRes=HExecuteSQLQuery(dsMyQUery,hQueryWithoutCorrection,sSql)

So, Windev does not change anything in the 'query' code..

von Harry W - am 26.03.2015 13:19
Hello to all


Thanks for your suggestions...


Gianni

von Gianni Spano - am 26.03.2015 14:38
Could be your field names, if ones called name or count or total etc.

von iso - am 26.03.2015 16:33
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

von Steven Sitas - am 28.03.2015 12:02
Zur Information:
MySnip.de hat keinen Einfluss auf die Inhalte der Beiträge. Bitte kontaktieren Sie den Administrator des Forums bei Problemen oder Löschforderungen über die Kontaktseite.
Falls die Kontaktaufnahme mit dem Administrator des Forums fehlschlägt, kontaktieren Sie uns bitte über die in unserem Impressum angegebenen Daten.