macs Posted December 10, 2020 Report Share Posted December 10, 2020 Boa tarde pessoal! Existe alguma forma de criar uma tabela pelo DbCreate e os campos tipo CARACTER ser criado como VARCHAR e não CHAR ? Desde já agradeço Quote Link to comment Share on other sites More sharing options...
macs Posted December 10, 2020 Author Report Share Posted December 10, 2020 Corrigindo o Tópico SQLRDD x DbCreate() x Varchar Quote Link to comment Share on other sites More sharing options...
Ariston Santos Posted December 11, 2020 Report Share Posted December 11, 2020 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) Quote Link to comment Share on other sites More sharing options...
macs Posted December 11, 2020 Author Report Share Posted December 11, 2020 Com DbCreate(), eu não preciso me preocupar com a sintaxe do banco de dados que eu estiver utilizando! Existe esta função: SR_SetMininumVarchar2Size(2). Já implementei, mas sempre cria como char. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.