PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → [WD20] SQL code
[WD20] SQL code
Iniciado por guest, 11,ago. 2016 16:57 - 4 respuestas
Publicado el 11,agosto 2016 - 16:57
Good morning, I'm trying to do a simple query to a MySQL DB using the SQLWDR function, so I need the query to be created in the editor, the problem is I don't know how to pass parameters to it. My query is the following:

SELECT mantis_user_table.PASSWORD, mantis_user_table.id, mantis_user_table.username
FROM mantis_user_table
WHERE mantis_user_table.username = {username}

the {username} must be a parameter entered by the user, any help?

TIA
Publicado el 11,agosto 2016 - 17:01
Hi

Are you looking for QueryName.UserName=Value before the execution?

Best regards
Publicado el 11,agosto 2016 - 17:09
Hello,

I'm not sure I'm understanding can you be a little more clear please? I execute the Query like this:

SQLExecWDR(QRY_Login,EDT_Usuario)

If I write QRY_Login. it doesn't autocomplete to the value
EDT_usuario is the parameter I need to pass to the query, I did this before by using SQLExec and stringbuild, but can't do that with SQLExecWDR :(
Publicado el 11,agosto 2016 - 19:15
I managed to pass the desired parameter, but now Windev adds a letter "L" to my query where the parameter is passed, it tries to execute the next query:

SELECT mantis_user_table.username AS username , mantis_user_table.PASSWORD AS PASSWORD , mantis_user_table.enabled AS enabled , mantis_user_table.id AS id , mantis_user_table.access_level AS access_level
FROM mantis_user_table
WHERE ( mantis_user_table.username = L'testadmin')
Publicado el 12,agosto 2016 - 08:38
Hi,

you can put your query into a string variable and pass the username from a variable, e.g.

MyData is data source
sMyQry is string

sMyQry = [
SELECT mantis_user_table.PASSWORD, mantis_user_table.id, mantis_user_table.username
FROM mantis_user_table
WHERE mantis_user_table.username = %1
]

sMyQry = StringBuild(sMyQry, varUsername)
IF NOT HExecuteSQLQuery(MyData, hQueryDefault, sMyQry) THEN
Error(HErrorInfo())
ELSE
Info("The query contains "+ HNbRec(QRY) + " records.")
END