Jump to content
Fivewin Brasil

Duvida com "BEGIN TRANSACTION" - Resolvido


Valdir

Recommended Posts

Boas..

Continuando meu aprendizado...

#Include "FiveWin.ch"

#define CRLF Chr( 13 ) + Chr( 10 )
#define HKEY_LOCAL_MACHINE      2147483650        // 0x80000002

//ANNOUNCE RDDSYS
REQUEST OrdKeyNo, OrdKeyCount, OrdKeyGoto
REQUEST DBFCDX, DBFFPT

REQUEST HB_LANG_PT
REQUEST HB_CODEPAGE_PT850

//--------------------------------------------------------------------------//
Function Main()
LOCAL oQry, cCmdSql, cText, wRowId:=0
PRIVATE cServer   := "localhost"
PRIVATE cUser     := "root"
PRIVATE cPassword := "Sua_Senha"
PRIVATE nPort     := 3306
PRIVATE cDBName   := "Seu_Bd"
PRIVATE nFlags    := 0
PRIVATE oServer   := NIL

PRIVATE cNOMBRE:="Nome"
PRIVATE cAPELLIDO1:="Apelido 1"
PRIVATE cAPELLIDO2:="Apelido 2"
PRIVATE cDIRECCION:="Endereco, 111"
PRIVATE cEDAD:=1
PRIVATE cPOBLACION:="Bairro"
PRIVATE cPROVINCIA:="Cidade"
PRIVATE cESTADO:=1

   IF ( oServer := ConnectTo() ) == NIL
      msgAlert("Erro de conexão")
      return nil
   ENDIF

   oQry = oServer:Query( "SELECT * FROM nombres" )

          oQry:GoBottom()

           cCmdSql:= "INSERT INTO nombres ( "
           cCmdSql += "nombre"    + ","
           cCmdSql += "apellido1" + ","
           cCmdSql += "apellido2" + ","
           cCmdSql += "direccion" + ","
           cCmdSql += "edad"      + ","
           cCmdSql += "poblacion" + ","
           cCmdSql += "provincia )"

           cCmdSql += "VALUES("
           cCmdSql += "'"+cNombre+"'"     +","
           cCmdSql += "'"+cApellido1+"'"  +","
           cCmdSql += "'"+cApellido2+"'"  +","
           cCmdSql += "'"+cDireccion+"'"  +","
           cCmdSql += ""+str(cEdad)+""    +","
           cCmdSql += "'"+cPoblacion+"'"  +","
           cCmdSql += "'"+cProvincia+"' )"

           oServer:Execute( cCmdSql )

           IF oServer:nError = 0
              BEEP()
              MSGRUN(OemToAnsi("Registros inclusos com Sucesso..."),OemToAnsi("ATENۂO..."))
           ELSE
              BEEP()
              MSGRUN(OemToAnsi("Nao foi possivel Incluir os Registros..."),OemToAnsi("ATENۂO..."))
              oServer:ShowError()
           ENDIF



   oServer:End()
   msginfo("Fim da Conexao...")


Return Nil


//----------------------------------------------------------
FUNCTION ConnectTo()
LOCAL oErr
LOCAL cText := ""

   FWCONNECT oServer HOST cServer USER cUser PASSWORD cPassword DATABASE cDBName

   if oServer == nil
      MsgAlert( "Failed to connect" )
      return nil
   ELSE
      cText += "Connection OK" + CRLF
      cText += "Host: " + cServer +CRLF
      cText += "Database: " +cDBName + CRLF
      cText += "" + CRLF
      cText += ""
      msginfo( cText ,"Dados da conexão ")
   ENDIF

RETURN(oServer)

//--------------------------------------------------------------------//
function BEEP()
   SndPlaySound(".\WAVES\LEMBRETE.WAV")
return nil

// FIM DO PROGRAMA



Amigos, utilizo o código acima para incluir informações no meu Bd.

Até ai sem problemas, funciona certinho.

Fazendo um curso de SQL pela internet, aprendi a importância de usar os Comandos:  BEGIN TRANSACTION. COMMIT E ROLLBACK no tratamento e segurança das informações.

Observem que no código acima, ainda não utilizo esses comandos.

Quando tento incluí-los no meu Código, não Compila e apresenta o erro de "Error E0030 Syntax error: ´syntax error at "TRANSACTION"´"

Será que está faltando algo ?

 

 

Link to comment
Share on other sites

 

Dear: Tem erro de sintaxe, e você não mostrou a linha do erro. Assim num dá, assim num podyyyy!! kkkkkkkkkkkkkkkkkk

Grande amigo Kapi...

Obrigado por responder.

Karo Kolega...

Se você colocar o Comando "BEGIN TRANSACTION" em qualquer parte do meu exemplo acima, ocorrerá o erro o qual me refiro.

Kapisco ?

Abrs.

Link to comment
Share on other sites

#include "FiveWin.ch"
	// #define CRLF Chr( 13 ) + Chr( 10 )  /// DESNECESSARIO
#define HKEY_LOCAL_MACHINE      2147483650        // 0x80000002
	// VALDIR: FALTA ALGUM ARQUIVO .CH QUE CONTEM #xcommand  BEGIN TRANSACTION
	#xcommand  BEGIN TRANSACTION => Begin Sequence; BeginTran()
#xcommand  BEGIN TRANSACTION EXTENDED => Begin Sequence; BeginTran()
#Translate END TRANSACTION   => EndTran(); End Sequence
#Translate END TRANSACTION EXTENDED   => EndTran(); End Sequence
#xcommand  CLOSETRANSACTION LOCKIN <aAlias,...>   => EndTran( \{ <aAlias> \}  ); End Sequence
	//ANNOUNCE RDDSYS
REQUEST OrdKeyNo, OrdKeyCount, OrdKeyGoto
REQUEST DBFCDX, DBFFPT
	REQUEST HB_LANG_PT
REQUEST HB_CODEPAGE_PT850
	//--------------------------------------------------------------------------//
Function Main()
	   LOCAL oQry, cCmdSql, cText, wRowId:=0
   PRIVATE cServer   := "localhost"
   PRIVATE cUser     := "root"
   PRIVATE cPassword := "Sua_Senha"
   PRIVATE nPort     := 3306
   PRIVATE cDBName   := "Seu_Bd"
   PRIVATE nFlags    := 0
   PRIVATE oServer   := NIL
	   PRIVATE cNOMBRE:="Nome"
   PRIVATE cAPELLIDO1:="Apelido 1"
   PRIVATE cAPELLIDO2:="Apelido 2"
   PRIVATE cDIRECCION:="Endereco, 111"
   PRIVATE cEDAD:=1
   PRIVATE cPOBLACION:="Bairro"
   PRIVATE cPROVINCIA:="Cidade"
   PRIVATE cESTADO:=1
	   IF ( oServer := ConnectTo() ) == NIL
      msgAlert("Erro de conexão")
      return nil
   ENDIF
	   oQry = oServer:Query( "SELECT * FROM nombres" )
	          oQry:GoBottom()
	           cCmdSql:= "INSERT INTO nombres ( "
           cCmdSql += "nombre"    + ","
           cCmdSql += "apellido1" + ","
           cCmdSql += "apellido2" + ","
           cCmdSql += "direccion" + ","
           cCmdSql += "edad"      + ","
           cCmdSql += "poblacion" + ","
           cCmdSql += "provincia )"
	           cCmdSql += "VALUES("
           cCmdSql += "'"+cNombre+"'"     +","
           cCmdSql += "'"+cApellido1+"'"  +","
           cCmdSql += "'"+cApellido2+"'"  +","
           cCmdSql += "'"+cDireccion+"'"  +","
           cCmdSql += ""+str(cEdad)+""    +","
           cCmdSql += "'"+cPoblacion+"'"  +","
           cCmdSql += "'"+cProvincia+"' )"
	           oServer:Execute( cCmdSql )
	           IF oServer:nError = 0
              BEEP()
              MSGRUN(OemToAnsi("Registros inclusos com Sucesso..."),OemToAnsi("ATEN€ÇO..."))
           ELSE
              BEEP()
              MSGRUN(OemToAnsi("Nao foi possivel Incluir os Registros..."),OemToAnsi("ATEN€ÇO..."))
              oServer:ShowError()
           ENDIF
	   oServer:End()
   msginfo("Fim da Conexao...")
	
Return Nil
	
//----------------------------------------------------------
FUNCTION ConnectTo()
	   LOCAL oErr
   LOCAL cText := ""
	   FWCONNECT oServer HOST cServer USER cUser PASSWORD cPassword DATABASE cDBName
	   if oServer == nil
      MsgAlert( "Failed to connect" )
      return nil
   ELSE
      cText += "Connection OK" + CRLF
      cText += "Host: " + cServer +CRLF
      cText += "Database: " +cDBName + CRLF
      cText += "" + CRLF
      cText += ""
      msginfo( cText ,"Dados da conexão ")
   ENDIF
	   USE CUSTUMER
	   BEGIN TRANSACTION
      //REPLACE hold_pay WITH "XXX"
   END TRANSACTION
	RETURN(oServer)
	FUNCTION BEEP()
	RETURN NIL
	FUNCTION BeginTran()
	RETURN NIL
	FUNCTION EndTran()
	RETURN NIL

Link to comment
Share on other sites

 

Begin transaction

Cmd sql

End transaction

Olá JmSilva...

Obrigado por responder.

Na hora de compilar o exemplo acima aparece o erro mencionado.

Veja a syntax que uso...

   oQry = oServer:Query( "SELECT * FROM nombres" )
	          oQry:GoBottom()
         BEGIN TRANSACTION  
	           cCmdSql:= "INSERT INTO nombres ( "
           cCmdSql += "nombre"    + ","
           cCmdSql += "apellido1" + ","
           cCmdSql += "apellido2" + ","
           cCmdSql += "direccion" + ","
           cCmdSql += "edad"      + ","
           cCmdSql += "poblacion" + ","
           cCmdSql += "provincia )"
	           cCmdSql += "VALUES("
           cCmdSql += "'"+cNombre+"'"     +","
           cCmdSql += "'"+cApellido1+"'"  +","
           cCmdSql += "'"+cApellido2+"'"  +","
           cCmdSql += "'"+cDireccion+"'"  +","
           cCmdSql += ""+str(cEdad)+""    +","
           cCmdSql += "'"+cPoblacion+"'"  +","
           cCmdSql += "'"+cProvincia+"' )"
	       oServer:Execute( cCmdSql )
	       IF oServer:nError = 0
                COMMIT()          
              	BEEP()
              	MSGRUN(OemToAnsi("Registros inclusos com Sucesso..."),OemToAnsi("ATEN€ÇO..."))
           ELSE
                ROLLBACK()
              	BEEP()
              	MSGRUN(OemToAnsi("Nao foi possivel Incluir os Registros..."),OemToAnsi("ATEN€ÇO..."))
              	oServer:ShowError()
           ENDIF
        END TRANSACTION   
	   oServer:End()

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...