示例#1
0
文件: Search.java 项目: wspi/Sky-Zone
  public void CarregaLista(String searched) {
    SQLiteDatabase myDB = null;
    try {
      myDB = this.openOrCreateDatabase("skyzone", MODE_PRIVATE, null);

      Cursor mCursor =
          myDB.rawQuery("SELECT * FROM Zones WHERE Name LIKE '" + searched + "%';", null);

      startManagingCursor(mCursor);

      ListAdapter adapter =
          new SimpleCursorAdapter(
              this,
              R.layout.list,
              mCursor,
              new String[] {"Icon", "Name", "Country", "State", "City", "Phone"},
              new int[] {R.id.Icon, R.id.Name, R.id.Country, R.id.State, R.id.City, R.id.Phone});
      this.setListAdapter(adapter);

      this.getListView().setTextFilterEnabled(true);
    } finally {
      if (myDB != null) {
        myDB.close();
      }
    }
  }
  /**
   * Close a database.
   *
   * @param dbName The name of the database-NOT including its extension.
   */
  private void closeDatabase(String dbName) {
    SQLiteDatabase mydb = this.getDatabase(dbName);

    if (mydb != null) {
      mydb.close();
      dbmap.remove(dbName);
    }
  }
  /** Close any open database object. */
  public synchronized void close() {
    if (mIsInitializing) throw new IllegalStateException("Closed during initialization");

    if (mDatabase != null && mDatabase.isOpen()) {
      mDatabase.close();
      mDatabase = null;
    }
  }
示例#4
0
 public void deleteTran(Account acct, String transID) {
   String[] args = {Integer.toString(acct.ID), transID};
   db.beginTransaction();
   try {
     db.delete("trans", "acct_id=? and trans_id=?", args);
     db.setTransactionSuccessful();
   } finally {
     db.endTransaction();
   }
 }
示例#5
0
 private void updateAccount(Account acct) {
   db.beginTransaction();
   try {
     ContentValues newValue = acctValues(acct);
     String[] args = {Integer.toString(acct.ID)};
     db.update("acct", newValue, "_id=?", args);
     db.setTransactionSuccessful();
   } finally {
     db.endTransaction();
   }
 }
示例#6
0
 private void updateTran(Transaction trans) {
   db.beginTransaction();
   try {
     ContentValues newValue = tranValues(trans);
     String[] args = {Integer.toString(trans.ID)};
     db.update("trans", newValue, "_id=?", args);
     db.setTransactionSuccessful();
   } finally {
     db.endTransaction();
   }
 }
示例#7
0
文件: Add.java 项目: nidebo/LowCost
 public void onPressClear(View view) {
   // Do something in response to button
   DataBaseHelper databasehelper = new DataBaseHelper(this);
   SQLiteDatabase db = databasehelper.getWritableDatabase();
   if (db != null) {
     // Se elimina la versión anterior de la tabla
     db.execSQL("DROP TABLE IF EXISTS " + databasehelper.TABLA);
     // Se utiliza para poder crear la nueva base de datos
     databasehelper.onCreate(db);
   }
 }
示例#8
0
文件: Add.java 项目: nidebo/LowCost
  // metodo para insertar a la tabla
  private void insertPrso(String nombre, String ciudad) {
    DataBaseHelper databasehelper = new DataBaseHelper(this);
    SQLiteDatabase db = databasehelper.getWritableDatabase();
    if (db != null) {
      ContentValues cv = new ContentValues();
      cv.put(DataBaseHelper.NOMBRE, nombre);
      cv.put(DataBaseHelper.CIUDAD, ciudad);

      db.insert("tabla", DataBaseHelper.NOMBRE, cv);
      db.close();
    }
  }
示例#9
0
 private int addAccount(Account acct) {
   db.beginTransaction();
   int acct_id;
   try {
     ContentValues newValue = acctValues(acct);
     acct_id = (int) db.insertOrThrow("acct", "name", newValue);
     acct.ID = acct_id;
     db.setTransactionSuccessful();
   } finally {
     db.endTransaction();
   }
   return acct_id;
 }
示例#10
0
  private int addTran(Transaction trans) {
    db.beginTransaction();
    int tran_id;
    try {
      ContentValues newValue = tranValues(trans);
      tran_id = (int) db.insertOrThrow("trans", "acct_id", newValue);
      trans.ID = tran_id;

      db.setTransactionSuccessful();
    } finally {
      db.endTransaction();
    }
    return tran_id;
  }
 /**
  * Enables or disables the use of write-ahead logging for the database.
  *
  * <p>Write-ahead logging cannot be used with read-only databases so the value of this flag is
  * ignored if the database is opened read-only.
  *
  * @param enabled True if write-ahead logging should be enabled, false if it should be disabled.
  * @see SQLiteDatabase#enableWriteAheadLogging()
  */
 public void setWriteAheadLoggingEnabled(boolean enabled) {
   synchronized (this) {
     if (mEnableWriteAheadLogging != enabled) {
       if (mDatabase != null && mDatabase.isOpen() && !mDatabase.isReadOnly()) {
         if (enabled) {
           mDatabase.enableWriteAheadLogging();
         } else {
           mDatabase.disableWriteAheadLogging();
         }
       }
       mEnableWriteAheadLogging = enabled;
     }
   }
 }
示例#12
0
 public Cursor acctList(String constraint) {
   if (constraint == null) {
     return db.query("acct", AC_COLS, null, null, null, null, "name");
   } else {
     return db.query(
         "acct",
         AC_COLS,
         "name like ?",
         new String[] {"%" + constraint + "%"},
         null,
         null,
         "name");
   }
 }
示例#13
0
文件: DBTool.java 项目: yezhidong/mcs
  /**
   * 单个数据查询 2
   *
   * @param sql 传入sql语句直接查询
   * @return 单个数据指针
   */
  public Cursor get(String sql) {
    Cursor mCursor = db.rawQuery(sql, null);
    // 如果指针存在,就把指针移到第一个条目上
    if (mCursor != null) mCursor.moveToFirst();

    return mCursor;
  }
示例#14
0
 public static SQLiteDebug.PagerStats getDatabaseInfo()
 {
   SQLiteDebug.PagerStats localPagerStats = new SQLiteDebug.PagerStats();
   getPagerStats(localPagerStats);
   localPagerStats.dbStats = SQLiteDatabase.getDbStats();
   return localPagerStats;
 }
  private static Cursor getMesesDiferentes() throws SQLException {

    SQLiteDatabase conn = null;
    Cursor rs = null;
    String consulta = " Select distinct month from session ";

    try {
      conn = BaseDatos.getConn();

      rs = conn.rawQuery(consulta, null);
    } catch (SQLException e) {
      throw (e);
    }

    return rs;
  }
示例#16
0
文件: DBTool.java 项目: yezhidong/mcs
  // 获取某个数据库的表的名称
  public String getTablesList() {

    Cursor c = db.rawQuery("select name from sqlite_master where type='table' order by name", null);
    String str = "";
    while (c.moveToNext()) {
      str += c.getString(0) + "\n";
    }
    return "表的名称为:\n" + str;
  }
示例#17
0
文件: DBTool.java 项目: yezhidong/mcs
  // 删除一个表
  public void dropTable(String table) {

    try {
      db.execSQL("drop table if exists " + table);

    } catch (SQLException e) {
      Toast.makeText(mCtx, "数据表删除失败", Toast.LENGTH_LONG).show();
    }
  }
示例#18
0
 private boolean tranExists(Transaction trans) {
   String[] args = {Integer.toString(trans.acct.ID), trans.transID};
   Cursor cur = db.query("trans", ID_COLS, "acct_id=? and trans_id=?", args, null, null, null);
   try {
     return cur.moveToNext();
   } finally {
     cur.close();
   }
 }
 private void setMaxConnectionPoolSizeLocked() {
   if (!SQLiteDatabase.hasCodec()
       && (mConfiguration.openFlags & SQLiteDatabase.ENABLE_WRITE_AHEAD_LOGGING) != 0) {
     mMaxConnectionPoolSize = SQLiteGlobal.getWALConnectionPoolSize();
   } else {
     // TODO: We don't actually need to restrict the connection pool size to 1
     // for non-WAL databases.  There might be reasons to use connection pooling
     // with other journal modes.  For now, enabling connection pooling and
     // using WAL are the same thing in the API.
     mMaxConnectionPoolSize = 1;
   }
 }
示例#20
0
文件: DBTool.java 项目: yezhidong/mcs
 /**
  * 列表查询用 1
  *
  * @param tableName 表名
  * @param strCols 列名
  * @param strWhere 条件
  * @param strGroupby 分组
  * @param strOrderby 排序
  * @return 数据指针
  */
 public Cursor getAll(
     String tableName, String[] strCols, String strWhere, String strGroupby, String strOrderby) {
   return db.query(
       tableName, // 表名
       strCols, // 列
       strWhere, // where语句
       null, // where语句的参数
       strGroupby, // GROUP by语句
       null, // HAVING语句
       strOrderby // order by语句
       );
 }
示例#21
0
  public Account getAccount(int ID) {
    Account acct = null;
    String[] args = {Integer.toString(ID)};
    Cursor cur = db.query("acct", AC_COLS, "_id=?", args, null, null, null);
    try {
      if (!cur.moveToNext()) return null;
      acct = getAccountFromCursor(cur);
    } finally {
      cur.close();
    }

    return acct;
  }
示例#22
0
  public void establishAccount(ServiceAcctInfo acct) {
    String[] args = {Integer.toString(acct.ID)};
    Cursor cur = db.query("acct", AC_COLS, "service_id=?", args, null, null, null);
    try {
      if (cur.moveToNext()) return;
    } finally {
      cur.close();
    }

    Account newAcct = new Account();
    newAcct.serviceId = acct.ID;
    newAcct.name = acct.desc;
    addAccount(newAcct);
  }
示例#23
0
文件: DBTool.java 项目: yezhidong/mcs
  public Cursor queryByparams(
      String[] columns, String selection, String table, String[] selectionArgs) {

    // 第一个参数String:表名
    // 第二个参数String[]:要查询的列名
    // 第三个参数String:查询条件
    // 第四个参数String[]:查询条件的参数
    // 第五个参数String:对查询的结果进行分组
    // 第六个参数String:对分组的结果进行限制
    // 第七个参数String:对查询的结果进行排序

    String groupBy = null;
    String having = null;
    String orderBy = null;
    return db.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
  }
示例#24
0
文件: DBTool.java 项目: yezhidong/mcs
  /**
   * 单个数据查询 1
   *
   * @param rowId 数据id
   * @param tableName 表名
   * @param key 关键字
   * @param strCols 列名
   * @param strWhere 条件
   * @param strGroupby 分组
   * @param strOrderby 排序
   * @return 单个数据指针
   */
  public Cursor get(
      long rowId,
      String tableName,
      String key,
      String[] strCols,
      String strWhere,
      String strGroupby,
      String strOrderby) {
    Cursor mCursor =
        db.query(tableName, strCols, key + "=" + rowId, null, strGroupby, null, strOrderby);

    // 如果指针存在,就把指针移到第一个条目上
    if (mCursor != null) mCursor.moveToFirst();

    return mCursor;
  }
  /**
   * Open a database.
   *
   * @param dbname The name of the database-NOT including its extension.
   * @param password The database password or null.
   */
  private void openDatabase(String dbname, String password) {
    if (this.getDatabase(dbname) != null) this.closeDatabase(dbname);

    String completeDBName = dbname + ".db";

    File dbfile = this.cordova.getActivity().getDatabasePath(dbname + ".db");

    if (!dbfile.exists()) copyPrepopulatedDatabase(completeDBName, dbfile);

    if (!dbfile.exists()) {
      dbfile.getParentFile().mkdirs();
    }

    Log.v("info", "Open sqlite db: " + dbfile.getAbsolutePath());

    SQLiteDatabase mydb = SQLiteDatabase.openOrCreateDatabase(dbfile, null);

    dbmap.put(dbname, mydb);
  }
  /**
   * Delete a database.
   *
   * @param dbname The name of the database-NOT including its extension.
   * @return true if successful or false if an exception was encountered
   */
  private boolean deleteDatabase(String dbname) {
    boolean status = false; // assume the worst case:

    if (this.getDatabase(dbname) != null) this.closeDatabase(dbname);

    File dbfile = this.cordova.getActivity().getDatabasePath(dbname + ".db");

    Log.v("info", "delete sqlite db: " + dbfile.getAbsolutePath());

    // Use try & catch just in case android.os.Build.VERSION.SDK_INT >= 16 was lying:
    try {
      status = SQLiteDatabase.deleteDatabase(dbfile);
    } catch (Exception ex) {
      // log & give up:
      Log.v("executeSqlBatch", "deleteDatabase(): Error=" + ex.getMessage());
      ex.printStackTrace();
    }

    return status;
  }
  /**
   * Create and/or open a database. This will be the same object returned by {@link
   * #getWritableDatabase} unless some problem, such as a full disk, requires the database to be
   * opened read-only. In that case, a read-only database object will be returned. If the problem is
   * fixed, a future call to {@link #getWritableDatabase} may succeed, in which case the read-only
   * database object will be closed and the read/write object will be returned in the future.
   *
   * <p class="caution">Like {@link #getWritableDatabase}, this method may take a long time to
   * return, so you should not call it from the application main thread, including from {@link
   * android.content.ContentProvider#onCreate ContentProvider.onCreate()}.
   *
   * @throws SQLiteException if the database cannot be opened
   * @return a database object valid until {@link #getWritableDatabase} or {@link #close} is called.
   */
  public synchronized SQLiteDatabase getReadableDatabase() {
    if (mDatabase != null) {
      if (!mDatabase.isOpen()) {
        // darn! the user closed the database by calling mDatabase.close()
        mDatabase = null;
      } else {
        return mDatabase; // The database is already open for business
      }
    }

    if (mIsInitializing) {
      throw new IllegalStateException("getReadableDatabase called recursively");
    }

    try {
      return getWritableDatabase();
    } catch (SQLiteException e) {
      if (mName == null) throw e; // Can't open a temp database read-only!
      Log.e(TAG, "Couldn't open " + mName + " for writing (will try read-only):", e);
    }

    SQLiteDatabase db = null;
    try {
      mIsInitializing = true;
      String path = mContext.getDatabasePath(mName).getPath();
      db =
          SQLiteDatabase.openDatabase(
              path, mPasswd, mFactory, SQLiteDatabase.OPEN_READONLY, mErrorHandler);
      if (db.getVersion() != mNewVersion) {
        throw new SQLiteException(
            "Can't upgrade read-only database from version "
                + db.getVersion()
                + " to "
                + mNewVersion
                + ": "
                + path);
      }

      onOpen(db);
      Log.w(TAG, "Opened " + mName + " in read-only mode");
      mDatabase = db;
      return mDatabase;
    } finally {
      mIsInitializing = false;
      if (db != null && db != mDatabase) db.close();
    }
  }
示例#28
0
 public void close() {
   db.close();
 }
示例#29
0
 public void wipeTable(SQLiteDatabase db) {
   for (String cmd : DROP_TABLE) {
     db.execSQL(cmd);
   }
   onCreate(db);
 }
示例#30
0
 @Override
 public void onCreate(SQLiteDatabase db) {
   for (String cmd : CREATE_TABLE) {
     db.execSQL(cmd);
   }
 }