0

I am currently working with the new eclipse ADT (Android Development Tools). When I used an older version, there was a plugin from Motorola named MotoDev Studio which helped you to make a database quite easily. It doesn't seem to work anymore with the new ADT.

Does anyone have a good alternative to making an easy SQLite database with content, and "converting" it to Java code for Android? (I've been looking online, but can't seem to find it)

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
user1393500
  • 199
  • 1
  • 3
  • 16

2 Answers2

1

You can use this eclipse plugin: https://github.com/sromku/android-sqlite-model-generator-plugin

This plugin allow easily generate java source code for Android based on SQLite database schema which you define in JSON file.

  1. Create JSON file that describes your schema. Example is here

  2. Right click on the JSON file -> Generate SQLite Model...:

enter image description here

Then, you can work with the database by using the generated code. For example, if you define Student table with few columns, then adding new student will look like this:

Student student = new Student();
student.setFirstname("John");
student.setLastname("Smith");
student.setAge(30);

Model model = Model.getInstance(context);
model.createStudent(student);

More info and details could be found in the GitHub project

sromku
  • 4,663
  • 1
  • 36
  • 37
0

I just do it by hand. I have this in my Makefile:

# Note: you MUST use the version of sqlite3 provided with Android sdk
SQLITE = ~/Android/android-sdk-linux_86/tools/sqlite3

foo.db: wpt.csv foo.sqlite3
        tail -n +3 wpt.csv > wpt.tmp
        rm -f $@
        ${SQLITE} $@ '.read foo.sqlite3'

And my foo.sqlite3 file looks like:

CREATE TABLE IF NOT EXISTS wpt (
    ident TINYTEXT NOT NULL,
    sector INT,
    lat FLOAT,
    lon FLOAT,
    type TINYTEXT,
    charts TEXT);
CREATE INDEX wptIdx ON wpt (sector);

.separator ":"
.import wpt.tmp wpt

I realize this isn't what you were looking for, but this avoids having dependencies on specific versions of specific IDEs, which you now know can bite you.

Edward Falk
  • 9,991
  • 11
  • 77
  • 112