Esempio n. 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);
        }
Esempio n. 2
0
        /// <summary>
        ///  Get a single info
        /// </summary>
        ///  <returns> info value </returns>
        private string __getInfo(string infoName)
        {
            string value  = null;
            string @where = SqlStr.genWhere(new SqlStr.SqlSimpCond(FSINFO.infoName.ToString(), "=", infoName));

            Cursor c = null;

            try
            {
                c = db.query(DBNAMES.FsInfo.ToString(), new string[] { FSINFO.infoVal.ToString() }, @where, null, null, null, null);

                if (c != null && c.moveToFirst())
                {
                    value = c.getString(0);
                }
            }
            catch (SQLiteException e)
            {
                SqlFsLog.debug(e);
                SqlFsErrCode.CurrentError = FsErr.GetFsInfoErr;
            }
            finally
            {
                SqlFsFunc.close(c);
            }

            return(value);
        }
Esempio n. 3
0
        //////////////////////////FS operations ///////////////////////////////////

        ///  @param [in] id -- get entry using ID directly </param>
        internal static SqlFsNode getFsNodeByID(SQLiteDatabase db, SqlFsLocker fsLocker, FsID id)
        {
            SqlFsNode fsNode = null;

            string @where = SqlStr.genWhere(new SqlStr.SqlSimpCond(SqlFs.FSBLOCK.fsID.ToString(), "=", id));
            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);

                if (c.moveToFirst())
                {
                    fsNode = SqlFsNode.getFsNode(db, fsLocker, c);
                }
            }
            catch (Exception e)
            {
                SqlFsLog.debug(e);
                SqlFsErrCode.CurrentError = FsErr.GetFieldError;
            }
            finally
            {
                SqlFsFunc.close(c);
            }

            return(fsNode);
        }
Esempio n. 4
0
        /// <summary>
        ///  Check existence of tables
        /// </summary>
        ///  <returns> true -- all tables present </returns>
        ///  <returns> false -- should create new tables </returns>
        private bool checkTables()
        {
            int tabCount = 0;

            string @where = SqlStr.genWhere(new SqlStr.SqlSimpCond(DBNAMES.type.ToString(), "=", DBNAMES.table.ToString())
                                            );

            Cursor c = db.query(DBNAMES.SQLITE_MASTER.ToString(), new string[] { DBNAMES.name.ToString() }, @where, null, null, null, null);

            // retrieve all table names and check against our list
            if (c != null && c.moveToFirst())
            {
                do
                {
                    string tabName = c.getString(0);
                    foreach (string n in TABLIST)
                    {
                        if (n.Equals(tabName, StringComparison.CurrentCultureIgnoreCase))
                        {
                            tabCount += 1;
                            break;
                        }
                    }
                } while (c.moveToNext());
            }
            SqlFsFunc.close(c);

            bool isCheckingOK = false;

            do
            {
                // not all tables exists, may be some corruption ...
                if (tabCount < TABLIST.Length)
                {
                    break;
                }

                // may be more checking here ...


                isCheckingOK = true;
            } while (false);

            if (tabCount != 0 && !isCheckingOK)
            {
                close();
                backup();
                open();
            }

            return(isCheckingOK);
        }
Esempio n. 5
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);
        }