Quintas,
Perguntas, subindo dados de um dbf para o mysql, e nesse dbf tem datas vazias ' / / ' como você trataria a carga nestes casos?

Moderador: Moderadores
FOR EACH oElemento2 IN aTheDBF
lLast := oElemento2:__enumIsLast()
cNomeCampo:=Upper(oElemento2[1])
cTheValue := &( oElemento2[1] )
DO CASE
CASE oElemento2[2] = "N"
cQuery += Str(cTheValue)+IF(!lLast, ", ", "")
CASE oElemento2[2] = "D"
IF Empty(cTheValue)
cQuery +='null'+IF(!lLast, ", ", "")
ELSE
cQuery +="'"+Transform( Dtos( cTheValue ), "@R 9999-99-99" )+"'"+IF(!lLast, ", ", "")
ENDIF
CASE oElemento2[2] = "L"
cTheValue:="'"+IF(cTheValue, "T", "F")+"'"
cQuery +=cTheValue+IF(!lLast, ", ", "")
CASE oElemento2[2] = "C"
cTheValue:="'"+cTheValue+"'"
cQuery += cTheValue+IF(!lLast, ", ", "")
CASE oElemento2[2] = "M"
cTheValue:=Memoread( oElemento2[1] )
//cTheValue:="'"+cTheValue+"'"
cQuery += cTheValue+IF(!lLast, ", ", "")
ENDCASE
NEXT
cSql := "INSERT INTO ARQUIVO ( CODIGO, NOME, ENDERECO ) VALUES ( " + ValueSql( mcodigo ) + ", " + ValueSql( mnome ) + ", " + ValueSql( mendereco ) + ")"
cnMySql:Execute( cSql )
FUNCTION StringSql( cString )
cString := Trim( cString )
cString := StrTran( cString, [\], [\\] )
cString := StrTran( cString, ['], [\'] )
cString := StrTran( cString, Chr(13), "\" + Chr(13) )
cString := StrTran( cString, Chr(10), "\" + Chr(10) )
cString := ['] + cString + [']
RETURN cString
FUNCTION DateSql( dDate )
LOCAL cString
cString := StrZero( Year( dDate ), 4 ) + "-" + StrZero( Month( dDate ), 2 ) + "-" + StrZero( Day( dDate ), 2 )
IF cString == "0000-00-00"
cString := "NULL"
ELSE
cString := StringSql( cString )
ENDIF
RETURN cString
FUNCTION NumberSql( xValue )
xValue := Ltrim( Str( xValue ) )
IF "." $ xValue
DO WHILE Right( xValue, 1 ) == "0"
xValue := Substr( xValue, 1, Len( xValue ) - 1 )
ENDDO
IF Right( xValue, 1 ) == "."
xValue := Substr( xValue, 1, Len( xValue ) - 1 )
ENDIF
ENDIF
RETURN xValue
FUNCTION ValueSql( xValue )
LOCAL cString
DO CASE
CASE ValType( xValue ) == "N"
cString := NumberSql( xValue )
CASE ValType( xValue ) == "D"
cString := DateSql( xValue )
OTHERWISE
cString := StringSql( xValue )
ENDCASE
RETURN cString
CASE oElemento2[2] = "M"
cTheValue:=Memoread( oElemento2[1] )
//cTheValue:="'"+cTheValue+"'"
cQuery += cTheValue+IF(!lLast, ", ", "")
USE CLIENTES
DO WHILE .NOT. Eof()
CopyRecordToMySql( "CLIENTES", clientes->Codigo )
SKIP
ENDDO
CLOSE DATABASES
FUNCTION CopyRecordToMySql( cDatabase, cChaveAcesso )
LOCAL nCont, xValue, lInsert := .T., oRs, cSql
IF cChaveAcesso != NIL
cSql := "SELECT COUNT(*) AS QTD FROM " + cDatabase + " WHERE " + cChaveAcesso
oRs := AppcnMySqlLocal():Execute( cSql )
IF oRs:Fields( "QTD" ):Value > 0
lInsert := .F.
ENDIF
oRs:Close()
ENDIF
IF lInsert
cSql := "INSERT INTO " + cDatabase + " ( "
FOR nCont = 1 TO FCount()
cSql += FieldName( nCont ) + iif( nCont == FCount(), "", ", " )
NEXT
cSql += ") VALUES ( "
ELSE
cSql := "UPDATE " + cDatabase + " SET "
ENDIF
FOR nCont = 1 TO FCount()
xValue := FieldGet( nCont )
IF ValType( xValue ) $ "NDC"
IF ValType( xValue ) == "C"
xValue := LimpaErro( xValue )
ENDIF
IF lInsert
cSql += ValueSql( xValue )
ELSE
cSql += FieldName( nCont ) + "=" + ValueSql( xValue )
ENDIF
ELSE
MsgExclamation( "Tipo desconhecido pra conversão " + ValType( xValue ) )
QUIT
ENDIF
cSql += iif( nCont == FCount(), "", ", " )
NEXT
IF lInsert
cSql += ")"
ELSE
cSql += "WHERE " + cChaveAcesso
ENDIF
AppcnMySqlLocal():Execute( cSql )
RETURN NIL
STATIC FUNCTION LimpaErro( xValue )
xValue := StrTran( xValue, Chr(91), " " )
xValue := StrTran( xValue, Chr(93), " " )
xValue := StrTran( xValue, Chr(167), " " )
xValue := StrTran( xValue, Chr(128), "C" )
xValue := StrTran( xValue, Chr(135), "C" )
xValue := StrTran( xValue, Chr(166), "A" )
xValue := StrTran( xValue, Chr(198), "A" )
xValue := StrTran( xValue, Chr(0), "" )
xValue := StrTran( xValue, Chr(95), "-" )
xValue := StrTran( xValue, Chr(229), "O" )
xValue := StrTran( xValue, Chr(124), " " )
xValue := StrTran( xValue, Chr(141), " " )
xValue := StrTran( xValue, Chr(181), " " )
xValue := StrTran( xValue, Chr(162), " " )
xValue := StrTran( xValue, Chr(224), " " )
xValue := StrTran( xValue, Chr(133), " " )
xValue := StrTran( xValue, Chr(144), "E" )
xValue := StrTran( xValue, Chr(160), " " )
RETURN xValue
oConnection:BeginTrans()
oConnection:Execute("INSERT INTO TABELA VALUES('TESTE')")
oConnection:BeginTrans()
oConnection:Execute("INSERT INTO TABELA2 VALUES('TESTE')")
oConnection:CommitTrans()
oConnection:CommitTrans()
asimoes escreveu:o meu problema é que no oracle não permite múltiplas transações aninhadas
2016-12-02 20:04 UTC+0100 Viktor Szakats (vszakats users.noreply.github.com)
- extras/gfspell/*
- extras/hbdroid/*
- extras/hbusb/*
- extras/hbvpdf/*
- extras/hbxlsxml/*
- extras/httpsrv/*
- extras/rddado/*
* package/mpkg_win.sh
- remove unfinished, unmaintaned and/or broken packages from the /extras
directory.
You can find the last revision of them archived here:
https://harbour.github.io/archive/gfspell.zip
https://harbour.github.io/archive/hbdroid.zip
https://harbour.github.io/archive/hbusb.zip
https://harbour.github.io/archive/hbvpdf.zip
https://harbour.github.io/archive/hbxlsxml.zip
https://harbour.github.io/archive/httpsrv.zip
https://harbour.github.io/archive/rddado.zip
(Note these contain several maintenance updates compared
to the latest version hosted as part of mainline 3.2 Harbour)
Or as part of the last repository archive that still contained them:
https://github.com/vszakats/harbour-cor ... 170812.zip
Retornar para Contribuições, Dicas e Tutoriais
Usuários vendo este fórum: Nenhum usuário registrado online e 18 visitantes