Histórico da Página
Composition Setup |
---|
import.css=/download/attachments/3279126062824/newLayouttecnologia.css |
Portuguese |
Pagetitle |
---|
...
...
|
...
Executa
...
uma
...
sentença
...
de
...
sintaxe
...
SQL
...
(Structured
...
Query
...
Language).
Sintaxe
TCSQLExec ( < cStatement> ) --> nStatus
Bloco de código | ||
---|---|---|
| ||
TCSqlExec( < cStatement > )
|
Parâmetros
Nome | Tipo | Descrição | Obrigatório | Referência |
---|---|---|---|---|
cStatement |
...
caractere | Indica a string que contém a sentença que será informada à função e executada no banco de dados. | X |
|
Retorno
Nome |
---|
...
Tipo |
---|
...
Descrição |
---|
nStatus |
...
numérico | Retorna o status da execução. Se menor que 0 indica que a sentença não foi executada com sucesso. |
Observações
A sentença <cStatement> é extremamente dependente do SGBD (
...
Sistema Gerenciador de Banco de Dados) e deve ser construída visando o banco de dados utilizado
...
.
É aconselhável que o parâmetro <cStatement> execute uma única instrução por vez
...
. Isto porque a solicitação de execução de mais de uma instrução no Statement está sujeito ao comportamento do SGBD (Sistema Gerenciador de Banco de Dados
...
)
...
Exemplos
Bloco de código | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
USER FUNCTION TEST()
TCLink()
TCDelFile("T1")
DBCreate("T1", {{"FIELD_NAME", "C", 10, 0}, ;
#DEFINE CRLF Chr(13)+Chr(10)User Function Exemplo() Local cEstrutura := "", cStatement := "" If !(TCIsConnected()) Return MsgAlert("Você precisa abrir uma conexão com o banco de dados") EndIf If !("MSSQL"$TCGetDB()) Return MsgStop(TCGetDB() + " - Nao tratado!") Endif cEstrutura := "MyTempTable" cStatement := "if exists(select name from sysobjects where name like '" + cEstrutura + "%' and xtype = 'U')" + CRLF cStatement += "begin" + CRLF cStatement += " drop table " + cEstrutura + "" + CRLF cStatement += "end" + CRLF If (TCSQLExec(cStatement) < 0) Return MsgStop("TCSQLError() " + TCSQLError()) EndIf cStatement := "create table " + cEstrutura + " (" + CRLF cStatement += " campo_caractere varchar(20) not null default ' ', " + CRLF cStatement += " campo_numerico float default 0, " + CRLF cStatement += " campo_logico varchar(1) not null default 'F', " + CRLF cStatement += " campo_data varchar(8) not null default ' ' " + CRLFcStatement += ")" If (TCSQLExec(cStatement) < 0) Return MsgStop("TCSQLError() " + TCSQLError()) EndIf cStatement := "insert into " + cEstrutura + " values ('1st ', 1, 'T', '20080101')" If (TCSQLExec(cStatement) < 0) Return MsgStop("TCSQLError() " + TCSQLError()) EndIf cStatement := "insert into " + cEstrutura + " values ('3nd {"FIELD_TYPE", "C", 10, 0}}, "TOPCONN")', 2, 'F', '20080103')" If (TCSQLExec(cStatement) < 0) Return MsgStop("TCSQLError() " + TCSQLError()) EndIf cStatement nStatus := TCSqlExec("insert into" + cEstrutura + " values ('3rd ', 3, 'T', '20080103')" If (TCSQLExec(cStatement) < 0) Return MsgStop("TCSQLError() " + TCSQLError()) EndIf cStatement := "insert into " + cEstrutura + " values ('4th ', 4, 'F', '20080104')" If (TCSQLExec(cStatement) < 0) Return MsgStop("TCSQLError() " + TCSQLError()) EndIf cStatement := "update " + cEstrutura + " " + CRLF cStatement += " set campo_caractere = '2nd ', campo_data = '20080102'" + CRLF cStatement += "where campo_caractere = '3nd ' and campo_data = '20080103'" If (TCSQLExec(cStatement) < 0) Return MsgStop t1 (field_name, field_type) values ('name', 'type')") if (nStatus < 0) conout("TCSQLError() " + TCSQLError()) EndIf cStatement := "delete " + cEstrutura + " where campo_caractere = '4th '" If (TCSQLExec(cStatement) < 0) Return MsgStop("TCSQLError() " + TCSQLError()) EndIf Return Microsiga Protheus 8.11 , Protheus 10 , TOTVS Application Server
endif
TCUnlink()
RETURN
|