public void all(final LogAction action) { try { sdb.readTransaction( new DBAction() { @Override public void run(SqlJetDb db) throws SqlJetException { SqlJetTableHelper t = sdb.logTable(); ISqlJetCursor c = t.order(null); while (!c.eof()) { long id = c.getInteger("id"); LogRecord l = cache.get(id); // TODO: cache if (l == null) { l = LogRecord.create((int) id, sdb); fromCursor(c, l); } if (action.run(l)) break; c.next(); } c.close(); } }, -1); } catch (SqlJetException e) { e.printStackTrace(); } }
public void printAll() { try { sdb.readTransaction( new DBAction() { @Override public void run(SqlJetDb db) throws SqlJetException { SqlJetTableHelper t = sdb.logTable(); ISqlJetCursor c = t.order(null); while (!c.eof()) { Log.d( "LOG", c.getValue("id") + "," + c.getValue("date") + "," + c.getValue("action") + "," + c.getValue("target")); c.next(); } c.close(); } }, -1); } catch (SqlJetException e) { e.printStackTrace(); } }
@Override public void createPartControl(final Composite parent) { if (mExplorer != null) { pullFile(); // pull file from device. final ISqlJetSchema sqlJetSchema = getSqlJetSchema(dbFile); SchemaTree schemaTreeModel = null; String[] tableNames = null; try { schemaTreeModel = SchemaTree.createInstance(sqlJetSchema); tableNames = sqlJetSchema.getTableNames().toArray(new String[0]); } catch (final SqlJetException e) { e.printStackTrace(); } // final TabFolder sqlitebrowserTabFolder = new TabFolder(parent, SWT.BORDER); // Schema structure gui createSchemaGui(sqlitebrowserTabFolder, schemaTreeModel); // Browse data gui createDataGui(sqlitebrowserTabFolder, tableNames); // create SQLQuery Gui // RefactorClass.createSQLQueryGui(sqlitebrowserTabFolder, dbFile); } else { Label label = null; label = new Label(parent, SWT.LEFT); label.setText("Select db file in File Explorer, and open it in SQLite Browser..."); label.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); } }
public void actionPerformed(ActionEvent evt) { String text = textField.getText(); try { handleInput(text); } catch (SqlJetException sqle1) { sqle1.printStackTrace(); MUSGuiImproved.appendLine("SqlException from SQLAdapter print_test();"); } textField.selectAll(); }
private void loadTableData( final File dbFile, final TableViewer guiTableViewer, final String dbTableName) { SqlJetDb db = null; try { db = SqlJetDb.open(dbFile, true); final ISqlJetTable dbTable = db.getTable(dbTableName); final ArrayList<DataRow> data = new ArrayList<DataRow>(); final ISqlJetTableDef tableDef = dbTable.getDefinition(); final List<String> names = new ArrayList<String>(); for (final ISqlJetColumnDef column : tableDef.getColumns()) { names.add(column.getName()); } final String[] namesArray = names.toArray(new String[names.size()]); final Table guiTable = guiTableViewer.getTable(); createGuiTableColumns(guiTable, namesArray); dbTable .getDataBase() .runReadTransaction( new ISqlJetTransaction() { @Override public Object run(final SqlJetDb db) throws SqlJetException { final ISqlJetCursor cursor = dbTable.open(); try { int count = 0; while (!cursor.eof()) { data.add(DataRow.read(cursor, count, namesArray)); cursor.next(); count++; } } finally { cursor.close(); } return null; } }); // Populate data and refresh table viewer guiTableViewer.setInput(data); guiTableViewer.refresh(); } catch (final Exception e) { e.printStackTrace(); } finally { if (db != null) { try { db.close(); } catch (final SqlJetException e) { e.printStackTrace(); } } } }
private ISqlJetSchema getSqlJetSchema(final File dbFile) { SqlJetDb db = null; try { db = SqlJetDb.open(dbFile, true); return db.getSchema(); } catch (final SqlJetException e) { e.printStackTrace(); } finally { if (db != null) { try { db.close(); } catch (final SqlJetException e) { e.printStackTrace(); } } } return null; }