Skip to content

Instantly share code, notes, and snippets.

@geraldodev
Created July 21, 2015 23:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save geraldodev/b6e59898caa0f33e19e5 to your computer and use it in GitHub Desktop.
Save geraldodev/b6e59898caa0f33e19e5 to your computer and use it in GitHub Desktop.
(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