Created
July 21, 2015 23:43
-
-
Save geraldodev/b6e59898caa0f33e19e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn exporta-trans-sqlite [db diretorio empresa] | |
(with-open [dbf (org.xBaseJ.DBF. (nome-dbf diretorio trans-base empresa) "r")] | |
(let [field-keys [:funcc :data :tipo :fdeptoant :fdeptonov] | |
fields (apply xbase/keys-to-fields-vec dbf field-keys) | |
n-registros (.getRecordCount dbf) | |
] | |
(println "exportando " (.getName dbf) " para o sqlite") | |
;; (jdbc/execute! db ["PRAGMA synchronous = OFF"]) | |
(jdbc/execute! db ["drop table if exists trans"]) | |
(jdbc/execute! db ["create table trans | |
(funcc varchar(6), | |
data date, | |
tipo char(1), | |
fdeptoant varchar(3), | |
fdeptonov varchar(3) | |
)"]) | |
(time | |
(jdbc/with-db-transaction [conn db ] | |
(dotimes [n n-registros] | |
(.read dbf) | |
(when-not (.deleted dbf) | |
(let [valores (zipmap field-keys | |
(xbase/fields-vec-value fields))] | |
(jdbc/insert! conn :trans valores | |
:transaction? false | |
))))) | |
) | |
(jdbc/execute! db ["create index trans_idx on trans (funcc, tipo, data)"]) | |
(println n-registros " registros") | |
))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment