PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV Mobile 22 → Example Run an MS SQL Procedure with Windev, Webdev using HExecuteSQLQuery (Executar uma MS SQL Procedure com o Windev, Webdev usando o HExecuteSQLQuery)
Example Run an MS SQL Procedure with Windev, Webdev using HExecuteSQLQuery (Executar uma MS SQL Procedure com o Windev, Webdev usando o HExecuteSQLQuery)
Débuté par adrianoboller, 08 jan. 2015 17:24 - 6 réponses
Membre enregistré
2 681 messages
Popularité : +89 (91 votes)
Posté le 08 janvier 2015 - 17:24
Example to Run an MS SQL Procedure with Windev, Webdev using HExecuteSQLQuery (Exemplo para Executar uma MS SQL Procedure com o Windev, Webdev usando o HExecuteSQLQuery)

CODIGO MSSQL:

--PEGA O VALOR DA ULTIMA CORRIDA

USE [producao]
GO

CREATE PROCEDURE NG0002_Procedure_UltimaCorrida
AS

DECLARE @num_corrida int;

SELECT @num_corrida = num_ultima_numera FROM numeracao WHERE ide_numera = 'ACT263_CORRIDA' AND num_ano_refere = year(getdate());

SELECT @num_corrida AS num_corrida;

return @num_corrida;

GO




CODIGO NO WINDEV, WEBDEV - USO EM WEBSERVICE:

//Executar procedure

numero_corrida is int = 0
MyProcedureUltimaCorrida is Data Source
IF HExecuteSQLQuery(MyProcedureUltimaCorrida, ConnNativa, hQueryWithoutCorrection,"NG0002_Procedure_UltimaCorrida") THEN
HReadFirst(MyProcedureUltimaCorrida, num_corrida)
WHILE HOut() = False
ok = HReadNext(MyProcedureUltimaCorrida, num_corrida)
numero_corrida = MyProcedureUltimaCorrida.num_corrida
END
ELSE
Error(HErrorInfo())
END
Trace(numero_corrida)



Veio valor sem dar erro no Trace()
Membre enregistré
2 681 messages
Popularité : +89 (91 votes)
Posté le 08 janvier 2015 - 19:06
Informação adicional:

http://doc.windev.com/en-US/…
Membre enregistré
2 681 messages
Popularité : +89 (91 votes)
Posté le 09 janvier 2015 - 17:24
HClose(dsIntegraIn_Destino_Criar)

sCodeSqlStoredProcedure is string = [
Insert_IntegraIn X_Id_IntegraOut, X_Data, X_Hora, 'X_Sql', 'X_IP', X_Flag_Atualiza, X_Id_Filial, 'X_Usuario', 'X_Programa', 'X_Nome_PC', 'X_Nome_Procedure', XFlag_Erro
]

sCodeSqlStoredProcedure = Replace(sCodeSqlStoredProcedure,"X_Id_IntegraOut",dsIntegraOut.Id_IntegraOut)
sCodeSqlStoredProcedure = Replace(sCodeSqlStoredProcedure,"X_Data",dsIntegraOut.Data)
sCodeSqlStoredProcedure = Replace(sCodeSqlStoredProcedure,"X_Hora",dsIntegraOut.Hora)
sCodeSqlStoredProcedure = Replace(sCodeSqlStoredProcedure,"X_Sql",dsIntegraOut.Sql)
sCodeSqlStoredProcedure = Replace(sCodeSqlStoredProcedure,"X_IP",dsIntegraOut.IP)
sCodeSqlStoredProcedure = Replace(sCodeSqlStoredProcedure,"X_Flag_Atualiza","0")
sCodeSqlStoredProcedure = Replace(sCodeSqlStoredProcedure,"X_Id_Filial",dsIntegraOut.Id_Filial)
sCodeSqlStoredProcedure = Replace(sCodeSqlStoredProcedure,"X_Usuario",dsIntegraOut.Usuario)
sCodeSqlStoredProcedure = Replace(sCodeSqlStoredProcedure,"X_Programa",dsIntegraOut.Programa)
sCodeSqlStoredProcedure = Replace(sCodeSqlStoredProcedure,"X_Nome_PC",dsIntegraOut.Nome_PC)
sCodeSqlStoredProcedure = Replace(sCodeSqlStoredProcedure,"X_Nome_Procedure",dsIntegraOut.Nome_Procedure)
sCodeSqlStoredProcedure = Replace(sCodeSqlStoredProcedure,"XFlag_Erro","0")

//info(sCodeSqlStoredProcedure)

//dsIntegraOut.Id_IntegraOut+","+dsIntegraOut.Data+","+dsIntegraOut.Hora+","+dsIntegraOut.Sql+","+dsIntegraOut.IP+",0,"+dsIntegraOut.Id_Filial+","+dsIntegraOut.Usuario+","+dsIntegraOut.Programa+","+dsIntegraOut.Nome_PC+","+dsIntegraOut.Nome_Procedure+",0"
//IF NOT HExecuteSQLQuery(dsIntegraIn_Destino_Criar,gctConectar_Destino, hQueryWithoutCorrection, "Insert_IntegraIn "+dsIntegraOut.Id_IntegraOut+","+dsIntegraOut.Data+","+dsIntegraOut.Hora+",'"+dsIntegraOut.Sql+"' , '"+dsIntegraOut.IP+"' ,0,"+dsIntegraOut.Id_Filial+", '"+dsIntegraOut.Usuario+"' , '"+dsIntegraOut.Programa+"' , '"+dsIntegraOut.Nome_PC+"' , '"+dsIntegraOut.Nome_Procedure+"',0") THEN
IF NOT HExecuteSQLQuery(dsIntegraIn_Destino_Criar,gctConectar_Destino, hQueryWithoutCorrection, sCodeSqlStoredProcedure) THEN
Error("HFSQL error: " + HErrorInfo())
ELSE
Info("OK!")
END
Membre enregistré
2 681 messages
Popularité : +89 (91 votes)
Posté le 09 janvier 2015 - 17:25
CREATE PROCEDURE Insert_IntegraIn
(
@Id_IntregraIN Int,
@Data FLOAT,
@Hora FLOAT,
@Sql VARCHAR(4999),
@IP VARCHAR(49),
@Flag_atualiza TINYINT,
@Id_Filial Int,
@Usuario VARCHAR(49),
@Programa VARCHAR(49),
@Nome_PC VARCHAR(49),
@Nome_procedure VARCHAR(49),
@Flag_Erro TINYINT)
AS
Begin
INSERT INTO IntegraIn (ID_INTEGRAIn, Data, Hora, Sql, IP, Flag_atualiza, Id_Filial, Usuario, Programa, Nome_PC, Nome_procedure, Flag_Erro) VALUES
(@Id_IntregraIN, @Data, @Hora, @Sql, @IP, @Flag_atualiza, @Id_Filial, @Usuario, @Programa, @Nome_PC, @Nome_procedure, @Flag_Erro)
Membre enregistré
2 681 messages
Popularité : +89 (91 votes)
Posté le 07 novembre 2016 - 12:16
Manual do comando:

http://help.windev.com/en-US/…

Para ter certeza que nao vai ter duplicados e vai incluir com segurança use:

hQueryWithoutCorrection

hQueryWithoutHFCorrection

hCheckDuplicates

hCheckIntegrity

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
2 681 messages
Popularité : +89 (91 votes)
Posté le 27 décembre 2016 - 13:24
Exemplo de HexecuteSqlQuery
SqlExecuta is string = [
Select * from clientes where codigo <= §codigo§
]

SqlExecuta = Replace(SqlExecuta , "§codigo§", 100)

DS_Executa is Data Source

ok is boolean = HExecuteSQLQuery(DS_Executa, QueryDefault, SqlExecuta)

IF ok = True
For each DS_Executa
IF HFound(DS_Executa) = True
//leitura dos dados
Info(DS_Executa.codigo, DS_Executa.Nome, DS_Executa.CPF)
END//if
END//for

ELSE
Info(ErrorInfo())
END


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
2 681 messages
Popularité : +89 (91 votes)
Posté le 03 février 2017 - 14:51
Exemplo

Procedure Existdatabase(TOKEN, CNPJ)

ok is boolean = False

Resultado, Msg is string = ""

IF TOKEN = GloToken AND CNPJ <> "" AND Length(CNPJ) = 14 AND IsNumeric(CNPJ) = True

OkConn is boolean = HConnectionOpen(ConnModel)

IF OkConn = True THEN

SQL_Exec is string = [
sp_roteiroinicial01_existdatabase '@CNPJ@'
]

SQL_Exec = Replace(SQL_Exec,"@CNPJ@",CNPJ,IgnoreCase+WholeWord) //Instrucao SQL

QryAdriano is Data Source

ok = HExecuteSQLQuery(QryAdriano, ConnModel,hQueryWithoutCorrection, SQL_Exec) // <---Obrigatorio ter hQueryWithoutCorrection

Resultado = ErrorInfo() + " " + HErrorInfo()


IF ok = True THEN

FOR EACH QryAdriano
IF HFound(QryAdriano) = True
Msg = QryAdriano.Existe
END
END

HFreeQuery(QryAdriano)

END


ELSE
Msg = "Erro de conexão com o servidor"
END

ELSE

Msg = "Token errado ou CNPJ errado"

END

RESULT (Msg)


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/