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();
        }
      }
    }
  }
Exemple #2
0
  private File createNewRawDbFile(List<String> tableList) throws Exception {
    File tempDbFile = File.createTempFile("temp", System.currentTimeMillis() + ".sql");

    SqlJetDb sqlJetDb = SqlJetDb.open(tempDbFile, true);
    sqlJetDb.getOptions().setAutovacuum(true);
    sqlJetDb.beginTransaction(SqlJetTransactionMode.WRITE);
    try {
      sqlJetDb.getOptions().setUserVersion(1);
      for (int i = 0; i < tableList.size(); i++) this.createTableNIndex(sqlJetDb, tableList.get(i));
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
      sqlJetDb.commit();
    }

    return tempDbFile;
  }
 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;
 }