Beispiel #1
0
        /// <summary>
        ///  Write a single info
        ///  Update existing entry or add a new one if not present
        /// </summary>
        private void __writeInfo(string infoName, string infoVal)
        {
            List <object> colsAndValues = new List <object>();

            colsAndValues.Add(FSINFO.infoName.ToString());
            colsAndValues.Add(infoName);
            colsAndValues.Add(FSINFO.infoVal.ToString());
            colsAndValues.Add(infoVal);
            ContentValues contVals = SqlStr.genContentValues(colsAndValues);
            string        @where   = SqlStr.genWhere(new SqlStr.SqlSimpCond(FSINFO.infoName.ToString(), "=", infoName));

            try
            {
                // try update first
                if (db.update(DBNAMES.FsInfo.ToString(), contVals, @where, null) == 0)
                {
                    // nothing is updated, insert to table
                    db.insert(DBNAMES.FsInfo.ToString(), null, contVals);
                }
            }
            catch (SQLiteException e)
            {
                SqlFsLog.debug(e);
                SqlFsErrCode.CurrentError = FsErr.WriteFsInfoErr;
                throw e;
            }
        }
Beispiel #2
0
        /// <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));
        }
Beispiel #3
0
        /// <summary>
        ///  Return a ContentValues to be inserted or updated to DB
        /// </summary>
        protected internal override ContentValues __saveData()
        {
            List <object> colsAndValues = new List <object>(2);
            FILETYPE      fType         = FILETYPE.fBin;

            if (this.rawBinData != null)
            {
                colsAndValues.Add(FILEDATABLOCK.dRawBinData.ToString());
                colsAndValues.Add(this.rawBinData);
                colsAndValues.Add(FILEDATABLOCK.dTextData.ToString());            // clear text column
                colsAndValues.Add("");
            }
            else if (this.textData != null)
            {
                colsAndValues.Add(FILEDATABLOCK.dTextData.ToString());
                colsAndValues.Add(this.textData);
                colsAndValues.Add(FILEDATABLOCK.dRawBinData.ToString());            // clear rawbin column
                colsAndValues.Add(null);
                fType = FILETYPE.fText;
            }

            // file type
            colsAndValues.Add(FILEDATABLOCK.dFileType.ToString());
            colsAndValues.Add(fType.ordinal());

            return(SqlStr.genContentValues(colsAndValues));
        }
Beispiel #4
0
        /// <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);
        }