欢迎投稿

今日深度:

Android Sqlite 代码实现 多表联合查询,androidsqlite

Android Sqlite 代码实现 多表联合查询,androidsqlite


最近开发ServerMonitor解决的一个issue,关于数据库的的升级,需要log表内添加一个is_scuuess字段并且对原数据库中每条日志的该记录赋值,判断成功的逻辑是根据不同协议的返回状态码及请求时间进行判断,因为日志表内只有一个site_id字段,具体日志记录的协议类型字段在site表内,于是决定采用多表联合查询的方法,通过site_id,将log表的日志记录与site表内的port_type一同查询出来 然后通过moveToNext()方法对每一条日志进行处理,具体核心代码是:

      Cursor cursorSite_log = db.rawQuery(" SELECT x.*, y.port_type FROM log x, site y "+
                "WHERE x.site_id = y._id",null);

需要在创建一个Log_siteInfo类包含log表内的所有字段和site表的port_type字段 :

  public Log_siteInfo(Cursor cursorSite_log) {
     this.port_type=cursorSite_log.getString(cursorSite_log.getColumnIndex("port_type"));
     ......
  }

然后在

      try {
             while (cursorSite_log != null && cursorSite_log.moveToNext()){
                   Log_siteInfo log_siteInfo = new Log_siteInfo(cursorSite_log);
                    //具体执行代码
                   }
        }finally {
            if (cursorSite_log != null) {
                cursorSite_log.close();
            }
        }

www.htsjk.Com true http://www.htsjk.com/SQLite/36166.html NewsArticle Android Sqlite 代码实现 多表联合查询,androidsqlite 最近开发ServerMonitor解决的一个issue,关于数据库的的升级,需要log表内添加一个is_scuuess字段并且对原数据库中每条日志的该记录赋值,判...
相关文章
    暂无相关文章
评论暂时关闭