Пример #1
0
        /// <summary>
        ///  Get the last (autoIncrement) rowID after a 'INSERT'
        /// </summary>
        internal static FsID getLastInsertID(SQLiteDatabase db)
        {
            // retrieve the ID of the new entry
            FsID   newID = SqlFsConst.INVALIDID;
            string sql   = "SELECT last_insert_rowid() as [id]";
            Cursor c     = null;

            try
            {
                c = db.rawQuery(sql, null);
                if (c.moveToFirst())
                {
                    newID = SqlFsFunc.getID(c, 0);
                }
            }
            catch (Exception e)
            {
                SqlFsLog.debug(e);
                SqlFsErrCode.CurrentError = FsErr.GetLastInsertIDError;
            }
            finally
            {
                SqlFsFunc.close(c);
            }

            return(newID);
        }
Пример #2
0
        internal static SqlDir getDir(SQLiteDatabase db, SqlFsLocker fsLocker, Cursor c)
        {
            FsID id = SqlFsFunc.getID(c, SqlFs.FSBLOCK.fsID.ordinal());

            return(SqlDir.getDir(db, fsLocker, id));
        }
Пример #3
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);
        }