/// <summary> /// Create a new entry in FsBlock /// </summary> /// <returns> new ID for the inserted node </returns> internal static FsID addFsNode(SQLiteDatabase db, SqlFsConst.FSTYPE type, string dirName, FsID parentID) { long curTime = SqlFsFunc.calToFileTime(new DateTime()); List <object> colsAndValues = new List <object>(10); colsAndValues.Add(SqlFs.FSBLOCK.fsCreateTime.ToString()); colsAndValues.Add(curTime); colsAndValues.Add(SqlFs.FSBLOCK.fsLastModTime.ToString()); colsAndValues.Add(curTime); colsAndValues.Add(SqlFs.FSBLOCK.fsFileSize.ToString()); colsAndValues.Add(0); colsAndValues.Add(SqlFs.FSBLOCK.fsType.ToString()); colsAndValues.Add(type.v()); colsAndValues.Add(SqlFs.FSBLOCK.fsName.ToString()); colsAndValues.Add(dirName); colsAndValues.Add(SqlFs.FSBLOCK.fsParent.ToString()); colsAndValues.Add(parentID); ContentValues contValues = SqlStr.genContentValues(colsAndValues); try { db.insert(SqlFs.DBNAMES.FsBlock.ToString(), null, contValues); } catch (Exception e) { SqlFsLog.debug(e); SqlFsErrCode.CurrentError = FsErr.AddFsNodeError; return(SqlFsConst.INVALIDID); } // retrieve the ID of the new entry return(SqlFs.getLastInsertID(db)); }
/// @param [in] name -- if null, get all entry </param> /// @param [in] type -- dir, file or any ? </param> private Cursor getEntryByName(string name, SqlFsConst.FSTYPE type) { // conditions List <object> conds = new List <object>(10); conds.Add(new SqlStr.SqlSimpCond(SqlFs.FSBLOCK.fsParent.ToString(), "=", this.ID)); if (name != null) { conds.Add("and"); conds.Add(new SqlStr.SqlSimpCond(SqlFs.FSBLOCK.fsName.ToString(), "=", name)); } if (type != SqlFsConst.FSTYPE.ANY) { conds.Add("and"); conds.Add(new SqlStr.SqlSimpCond(SqlFs.FSBLOCK.fsType.ToString(), "=", type.v())); } string @where = SqlStr.genWhere(conds); // query from DB Cursor c = null; try { c = db.query(SqlFs.DBNAMES.FsBlock.ToString(), new string[] { SqlFs.FSBLOCK.fsID.ToString(), SqlFs.FSBLOCK.fsType.ToString() }, @where, null, null, null, null); } catch (Exception e) { SqlFsLog.debug(e); SqlFsErrCode.CurrentError = SqlFsErrCode.FsErr.NoEntryByName; } // close and set to null if no rows at all if (c != null && c.Count == 0) { c.close(); c = null; } return(c); }