/// <summary> /// Save field to DB using ID /// </summary> private bool __setField(SqlFs.FSBLOCK field, object val) { List <object> colsAndValues = new List <object>(4); switch (field) { case com.sss.sqlfs.SqlFs.FSBLOCK.fsFileSize: case com.sss.sqlfs.SqlFs.FSBLOCK.fsType: case com.sss.sqlfs.SqlFs.FSBLOCK.fsName: case com.sss.sqlfs.SqlFs.FSBLOCK.fsParent: colsAndValues.Add(field.ToString()); colsAndValues.Add(val); break; case com.sss.sqlfs.SqlFs.FSBLOCK.fsChild: sbyte[] blob = idList2Blob((List <FsID>)val); colsAndValues.Add(field.ToString()); colsAndValues.Add(blob); break; } // update last mod time as well colsAndValues.Add(SqlFs.FSBLOCK.fsLastModTime.ToString()); colsAndValues.Add(SqlFsFunc.calToFileTime(new DateTime())); ContentValues contValues = SqlStr.genContentValues(colsAndValues); string @where = SqlStr.genWhere(new SqlStr.SqlSimpCond(SqlFs.FSBLOCK.fsID.ToString(), "=", this.ID)); int rowAffected = 0; try { rowAffected = db.update(SqlFs.DBNAMES.FsBlock.ToString(), contValues, @where, null); } catch (Exception e) { SqlFsLog.debug(e); SqlFsErrCode.CurrentError = FsErr.SetFieldError; } return(rowAffected > 0); }
/// <summary> /// Get a field from DB using ID /// </summary> private object __getField(SqlFs.FSBLOCK field) { string @where = SqlStr.genWhere(new SqlStr.SqlSimpCond(SqlFs.FSBLOCK.fsID.ToString(), "=", this.ID)); // little adjustment SqlFs.FSBLOCK tField = (field == SqlFs.FSBLOCK.fsChildCount) ? SqlFs.FSBLOCK.fsChild : field; Cursor c = null; object val = null; try { c = db.query(SqlFs.DBNAMES.FsBlock.ToString(), new string[] { tField.ToString() }, @where, null, null, null, null); if (c.moveToFirst() && !c.isNull(0)) { switch (field) { case com.sss.sqlfs.SqlFs.FSBLOCK.fsCreateTime: case com.sss.sqlfs.SqlFs.FSBLOCK.fsLastModTime: val = c.getLong(0); break; case com.sss.sqlfs.SqlFs.FSBLOCK.fsFileSize: case com.sss.sqlfs.SqlFs.FSBLOCK.fsType: val = c.getInt(0); break; case com.sss.sqlfs.SqlFs.FSBLOCK.fsName: val = c.getString(0); break; case com.sss.sqlfs.SqlFs.FSBLOCK.fsParent: val = SqlFsFunc.getID(c, 0); break; case com.sss.sqlfs.SqlFs.FSBLOCK.fsChild: { sbyte[] buf = c.getBlob(0); val = blob2idList(buf); } break; case com.sss.sqlfs.SqlFs.FSBLOCK.fsChildCount: { sbyte[] buf = c.getBlob(0); val = buf.Length / FsID.IDSize; } break; } } else { val = __getDefaultValue(field); } } catch (Exception e) { SqlFsLog.debug(e); SqlFsErrCode.CurrentError = FsErr.GetFieldError; val = __getDefaultValue(field); // return a default value here } finally { SqlFsFunc.close(c); } return(val); }