2

I saw that i can execute a .sql file with shell commands...

Process process = Runtime.getRuntime().exec(commandLine);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));

The "commandLine" attribute must be something like that?

commandLine = "sqlite> .read database.sql";

And another doubt... Where should i keep my "database.sql" file? Into assets? I've tryed to do that but not worked... Someone knows how to do it?

1
  • I got the same need actually. Waiting for an answer. Commented Apr 15, 2012 at 15:15

1 Answer 1

2

I saw that i can execute a .sql file with shell commands

That would be a really bad idea. There are no shell commands that are part of the Android SDK and therefore are guaranteed to be on all devices.

Read in the SQL script and execute its statements via execSQL() and kin on SQLiteDatabase, perhaps wrapping them in your own transaction using beginTransaction() and kin.

Sign up to request clarification or add additional context in comments.

6 Comments

Well, so how can i read that sql script into application? i read directly from assets?
@Igor: "Well, so how can i read that sql script into application?" -- use Java file I/O. "i read directly from assets?" -- you are welcome to do that too, if that is where your scripts are stored.
Some advice about where should i keep my script? is there any problema to keep sql file into the assets?
@Igor: "Some advice about where should i keep my script?" -- you should be asking yourself why you have such a script in the first place. "is there any problema to keep sql file into the assets?" -- probably not, but that is impossible to answer in the abstract.
well.. so now im having another problem... im reading as you said... and it really worked when i tested with around 10 lines into my database.sql but the problem is when i put there around 50.000 lines and the file get 3MB or something like that... When i put the real script the file code to read the file line by line dont work...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.