Luiz Fernando Posted January 25, 2015 Report Share Posted January 25, 2015 colegas gostaria de saber de vcs qual seria a forma correta de gravar os itens,hoje deixo o commit dentro do for next, mais fiz um teste com ele para fora do for next fica mais rapido, gravando dois, dez itens não percebe a diferença, mais qdo é 150 , 200 itens dai da para anotar a diferença. for i:=1 to len(aItens) SQLBeginTrans() cSql:="INSERT INTO pedido(pedido,tipo... continuação do codigo cSql+="VALUES( "+any2sql(aDados[D_PEDIDO])+" ," cSql+=" "+any2sql(aDados[D_TIPO])+" ," ... continuação do codigo cSql+=" "+any2sql(aItens[i,26])+")" SqlExecute(cSql) if SQLErrorNO() > 0 fMensagem() return(.f.) endif SqlExecute("commit") SQLRollBack() SQLEndTrans() SQLRefresh() next ou assim for i:=1 to len(aItens) SQLBeginTrans() cSql:="INSERT INTO pedido(pedido,tipo... continuação do codigo cSql+="VALUES( "+any2sql(aDados[D_PEDIDO])+" ," cSql+=" "+any2sql(aDados[D_TIPO])+" ," ... continuação do codigo cSql+=" "+any2sql(aItens[i,26])+")" SqlExecute(cSql) if SQLErrorNO() > 0 fMensagem() return(.f.) endif next SqlExecute("commit") SQLRollBack() SQLEndTrans() SQLRefresh() Obrigado Luiz Fernando Quote Link to comment Share on other sites More sharing options...
evandro Posted January 25, 2015 Report Share Posted January 25, 2015 Olá, Eu faria um pouco diferente: SQLBeginTrans() cSql:="INSERT INTO pedido(pedido,tipo... continuação do codigo cSql+="VALUES " for i:=1 to len(aItens) ( "+any2sql(aDados[D_PEDIDO])+" ," cSql+=" "+any2sql(aDados[D_TIPO])+" ," ... continuação do codigo cSql+=" "+any2sql(aItens[i,26])+")" next SqlExecute(cSql) if SQLErrorNO() > 0 fMensagem() return(.f.) endif SqlExecute("commit") SQLRollBack() SQLEndTrans() SQLRefresh() É muito mais rápido. Quote Link to comment Share on other sites More sharing options...
Luiz Fernando Posted January 26, 2015 Author Report Share Posted January 26, 2015 Olá, Eu faria um pouco diferente: SQLBeginTrans() cSql:="INSERT INTO pedido(pedido,tipo... continuação do codigo cSql+="VALUES " for i:=1 to len(aItens) ( "+any2sql(aDados[D_PEDIDO])+" ," cSql+=" "+any2sql(aDados[D_TIPO])+" ," ... continuação do codigo cSql+=" "+any2sql(aItens[i,26])+")" next SqlExecute(cSql) if SQLErrorNO() > 0 fMensagem() return(.f.) endif SqlExecute("commit") SQLRollBack() SQLEndTrans() SQLRefresh() É muito mais rápido. Ola Evandro, obrigado pela resposta, achei bem interessante seu metodo, mais da erro de sintaxe do mysql, vou tentar fazer novos teste, depois retorno ao topico... Abraços Luiz Fernando Quote Link to comment Share on other sites More sharing options...
kleyber Posted January 26, 2015 Report Share Posted January 26, 2015 Luis Fernando, Deu erro porque faltou delimitar cada linha de dados a ser inserida com a vírgula (,). Ficaria mais ou menos assim: SQLBeginTrans() cSql:="INSERT INTO pedido(pedido,tipo... continuação do codigo cSql+="VALUES " for i:=1 to len(aItens) ( "+any2sql(aDados[D_PEDIDO])+" ," cSql+=" "+any2sql(aDados[D_TIPO])+" ," ... continuação do codigo cSql+=" "+any2sql(aItens[i,26])+")," next // cSql:=substr(cSql,1,len(cSql)-1) // Pra tirar a última virgula // SqlExecute(cSql) if SQLErrorNO() > 0 fMensagem() return(.f.) endif SqlExecute("commit") SQLRollBack() SQLEndTrans() SQLRefresh() Quote Link to comment Share on other sites More sharing options...
Luiz Fernando Posted February 4, 2015 Author Report Share Posted February 4, 2015 Vlw Kleyber agora foi, muito bacana esta dica do Evandro, obrigado pela ajuda... Abraços Luiz Fernando 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.