Pergunta

É possível com o Ormlite criar um arquivo de script SQL para preencher facilmente o banco de dados com dados?Eu fiz algumas pesquisas e não consegui encontrar nada de fácil.Eu sei que posso criar alguns objetos com dados, estou apenas procurando por um método mais limpo.

Estou pensando em criar um arquivo de script, abra um leitor em carga e processe cada arquivo como o método RAW SQL O executivew ().Quaisquer pensamentos?

Foi útil?

Solução

Good one Joe. I think your idea of the executeRaw() is close but use updateRaw() instead. Update handles INSERT, DELETE, and UPDATE statements.

http://ormlite.com/docs/raw-update

You should call TableUtils to create your schema first of course:

http://ormlite.com/docs/tableUtils

Hope this helps. You may want to use the mailing list for questions in the future:

http://groups.google.com/group/ormlite-user/

Outras dicas

Just wanted to post my solution for anyone who might need it

try {
    tableDAO.updateRaw("DELETE FROM table");
    InputStream is = getResources().openRawResource(R.raw.populate_db);
    DataInputStream in = new DataInputStream(is);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
    while ((strLine = br.readLine()) != null) {
        tableDAO.updateRaw(strLine);
    }
    in.close();
} catch (Exception e) {
    e.printStackTrace();
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top