Back to project page MproEntity.
The source code is released under:
GNU General Public License
If you think the Android project MproEntity listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package br.com.mpro3.utils; /*w w w . j a va 2s . c o m*/ import java.io.File; import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; import android.database.Cursor; import android.database.sqlite.SQLiteConstraintException; import android.database.sqlite.SQLiteDatabase; import android.os.Environment; public class LauDB { private SQLiteDatabase connection; private Cursor sql; private int numRows; private int numCollsl; private String[] elem; private String[][] elems; public LauDB(String file) { File dir = new File(Environment.getExternalStorageDirectory() + "/Android_data/br.com.mpro3/MproEntity/lauses/"); dir.mkdirs(); connection = SQLiteDatabase.openOrCreateDatabase(Environment.getExternalStorageDirectory() + "/Android_data/br.com.mpro3/MproEntity/lauses/" + file, null); connection.execSQL("PRAGMA synchronous=OFF"); /*Cursor cu = connection.rawQuery("PRAGMA journal_mode=memory;", null); cu.moveToFirst();*/ } public String[][] query(String cmd) { sql = this.connection.rawQuery(cmd, null); this.elems = this.fetchAll(sql); return this.elems; } private String[][] fetchAll(Cursor res) { int count = 0; this.numCollsl = res.getColumnCount(); String[][] elemTmp = new String[1][this.numCollsl]; if(res.moveToFirst()) { do { elemTmp = Arrays.copyOf(elemTmp, count +1); elemTmp[count] = new String[this.numCollsl]; for(int i = 0; i < res.getColumnCount(); i++) { elemTmp[count][i] = res.getString(i); } count++; }while(res.moveToNext()); this.numRows = count; } if(count > 0) return elemTmp; else return null; } public boolean unQuery(String cmd) { this.sql = this.connection.rawQuery(cmd, null); this.numCollsl = this.sql.getColumnCount(); return true; } public String Row(int row, int table) { String tmp = ""; tmp = this.elems[row][table]; return tmp; } public String[] prox() { this.elem = new String[this.numCollsl]; if(this.sql.moveToNext()) { for(int i = 0; i < this.numCollsl; i++) { this.elem[i] = sql.getString(i); } return this.elem; } return null; } public String[] getElem() { return this.elem; } public void execute(String cmd) { try { this.connection.execSQL(cmd); } catch (SQLiteConstraintException ex) { Logger.getLogger(MproEntity.class.getName()).log(Level.SEVERE, null, ex); } } public int get_last_insert_rowid() { this.unQuery("SELECT last_insert_rowid();"); if(sql.moveToFirst()) return this.sql.getInt(0); return 0; } public int count() { return this.numRows; } public void close() { this.connection.close(); } }