Jump to content
Fivewin Brasil

SQLDD x DbCreate x Varchar


macs

Recommended Posts

Se você desejar aproveitar ao máximo a sintaxe do DBF, pode tentar assim:

FUNCTION CriarTabelas()
   // Criação da tabela itensdel_bd
   aStr:={}
   AADD(aStr,{"CODIGO", "C", 13,  0}) // Código do item
   AADD(aStr,{"DESCRI", "C", 60,  0}) // Descrição do item
   AADD(aStr,{"DTEXCL", "D", 08,  0}) // Data da exclusão
   IF ! SR_ExistTable( "itensdel_bd" )
      TRY
         cComm := XB2SqlStr(aStr, "itensdel_bd")
         nErr := oSql:Execute( cComm )
      CATCH oErr
         SysRefresh()
         MsgAlert("Erro ao tentar criar a tabela itensdel_bd."+CRLF+CRLF+;
                  "Favor verificar as configurações de banco de dados.","Erro")
      END
   ENDIF
RETURN NIL

STATIC FUNCTION XB2SqlStr(aStr, cDBase)
   LOCAL cStrct
   cStrct := "CREATE TABLE `"+LOWER(cDBase)+"` ("
   FOR nF := 1 TO LEN(aStr)
   	 IF LOWER(aStr[nF,1]) !=  "sr_recno"
	       IF nF > 1 ; cStrct += ", " ; ENDIF // Mais de um campo
	       cStrct += "`"+LOWER(aStr[nF,1])+"` "+SetFType(aStr[nF,2],aStr[nF,3],aStr[nF,4])
       ENDIF
   NEXT
   IF LEN(aStr) > 0 ; cStrct += ", " ; ENDIF // Já acrescentado algum campo
   cStrct += "`sr_recno` BIGINT (15) NOT NULL UNIQUE AUTO_INCREMENT)" // Sempre criar o 'sr_recno' no final, para compatibilizar com SQLRDD
RETURN( cStrct )

STATIC FUNCTION SetFType(cTipo,nSize,nDeci)
   LOCAL cFType
   IF cTipo = "C" ; cFType := "varchar("+ALLTRIM(STR(nSize))+")"
   ELSEIF cTipo = "M" ; cFType := "mediumblob"
   ELSEIF cTipo = "N" ; cFType := "double("+ALLTRIM(STR(nSize))+","+ALLTRIM(STR(nDeci))+")"
   ELSEIF cTipo = "L" ; cFType := "tinyint(4)"
   ELSEIF cTipo = "D" ; cFType := "date"
   ENDIF
RETURN(cFType)

 

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...