コード例 #1
0
ファイル: RecordDBClient.java プロジェクト: kebbs/PersonNote
  /**
   * 插入消息队列
   *
   * @param type
   * @param type_id
   * @param create_date
   * @param action_id
   * @param data
   * @param db
   * @return
   */
  public int insertNewTalk(Talk talk, int action_id, SQLiteDatabase db) {
    // 先插入对话中
    String sql = "insert into talk(content,create_time,latitude,longitude) " + " values(?,?,?,?) ";
    try {
      db.execSQL(
          sql,
          new Object[] {
            talk.getContent(), talk.getCreateDate(), talk.getLatitude(), talk.getLongitude()
          });
    } catch (SQLException e) {
      e.printStackTrace();
      return -1;
    }
    // 再插入消息队列中
    Cursor cursor = db.rawQuery("select last_insert_rowid() from talk", null);
    int strid = -1;
    try {
      if (cursor.moveToFirst()) {
        strid = cursor.getInt(0);
      }
    } finally {
      cursor.close();
    }

    if (strid > 0) {
      // 插入一条数据到主列表中
      insertMessage("talk", strid, talk.getCreateDate(), action_id, db);
      //			return strid;
      cursor = db.rawQuery("select last_insert_rowid() from message", null);
      int messageid = -1;
      try {
        if (cursor.moveToFirst()) {
          messageid = cursor.getInt(0);
        }
      } finally {
        cursor.close();
      }
      return messageid;
    }
    return -1;
  }
コード例 #2
0
ファイル: RecordDBClient.java プロジェクト: kebbs/PersonNote
  public int insertMapData(Talk talk, SQLiteDatabase db) {
    String sql = "insert into map(create_time) " + "values(?)";

    String create_date = talk.getCreateDate();

    db.execSQL(sql, new Object[] {create_date});

    Cursor cursor = db.rawQuery("select last_insert_rowid() from map", null);
    int strid = -1;

    try {
      if (cursor.moveToFirst()) {
        strid = cursor.getInt(0);
      }
    } finally {
      cursor.close();
    }

    return strid;
  }