Пример #1
0
        /// <summary>
        /// Creates a new connection to the icontent.cache file.
        /// </summary>
        /// <param name="filename">The file to connect to.</param>
        public IGADatabaseConnector(String filename)
        {
            try {
                sqlite = new SqliteConnection("URI=file:" + filename + ",version=3");
                sqlite.Open();

                SqliteCommand query = new SqliteCommand("SELECT [appId] FROM [contentlist] LIMIT 1", sqlite);
                Object result = query.ExecuteScalar();
                sqlite.Close();
                if (result == null)
                {
                    this._appID = 0;
                }
                else
                {
                    this._appID = (int)result;
                }

                if (this._appID > 0) {
                    this._appSupported = Common.AppInfos.ContainsKey(this._appID);
                } else {
                    this._appSupported = false;
                }

                if (this._appSupported)
                {
                    _appInfo = Common.AppInfos[this._appID];
                }

            } catch (Exception) {
                throw new DatabaseConnectionFailureException();
            }
        }
Пример #2
0
        protected IDataReader ExecuteReader(SqliteCommand cmd)
        {
            SqliteConnection newConnection =
                    (SqliteConnection)((ICloneable)m_Connection).Clone();
            newConnection.Open();

            cmd.Connection = newConnection;
            return cmd.ExecuteReader();
        }
Пример #3
0
        //////////////////////////////////////////////////////////////
        //
        // All non queries are funneled through one connection
        // to increase performance a little
        //
        protected int ExecuteNonQuery(SqliteCommand cmd)
        {
            lock (m_Connection)
            {
                cmd.Connection = m_Connection;

                return cmd.ExecuteNonQuery();
            }
        }
Пример #4
0
 // Create SQL Command With Param
 public SqliteCommand CreateCommand(string sql, Hashtable sqlParams)
 {
     SqliteCommand sqlCmd = new SqliteCommand(sql, this);
     if (sqlParams != null) {
         foreach (string key in sqlParams.Keys)
             sqlCmd.Parameters.Add(key, sqlParams[key]);
     }
     return(sqlCmd);
 }
		public void WrongSyntax()
		{
			SqliteCommand insertCmd = new SqliteCommand("INSERT INTO t1 VALUES (,')",_conn);
			using(_conn)
			{
				_conn.Open();
				int res = insertCmd.ExecuteNonQuery();
				Assert.AreEqual(res,1);
			}
		}
		public void InsertRandomValuesWithParameter()
		{
			SqliteParameter textP = new SqliteParameter();
			textP.ParameterName = "textP";
			textP.SourceColumn = "t";
		
			SqliteParameter floatP = new SqliteParameter();
			floatP.ParameterName = "floatP";
			floatP.SourceColumn = "nu";
		
			SqliteParameter integerP = new SqliteParameter();
			integerP.ParameterName ="integerP";
			integerP.SourceColumn = "i";

			SqliteParameter blobP = new SqliteParameter();
			blobP.ParameterName = "blobP";
			blobP.SourceColumn = "b";

			Random random = new Random();
			StringBuilder builder = new StringBuilder();
			for (int k=0; k < random.Next(0,100); k++)
			{
				builder.Append((char)random.Next(65536));
			}
			
			SqliteCommand insertCmd = new SqliteCommand("DELETE FROM t1; INSERT INTO t1  (t, f, i, b ) VALUES(:textP,:floatP,:integerP,:blobP)",_conn);
			
			insertCmd.Parameters.Add(textP);
			insertCmd.Parameters.Add(floatP);
			insertCmd.Parameters.Add(blobP);
			insertCmd.Parameters.Add(integerP);
			
			textP.Value=builder.ToString();
			floatP.Value=Convert.ToInt64(random.Next(999));
			integerP.Value=random.Next(999);
			blobP.Value=System.Text.Encoding.UTF8.GetBytes("\u05D0\u05D1\u05D2" + builder.ToString());
			
			SqliteCommand selectCmd = new SqliteCommand("SELECT * from t1", _conn);

			using(_conn)
			{
				_conn.Open();
				int res = insertCmd.ExecuteNonQuery();
				Assert.AreEqual(res,1);
				
				using (IDataReader reader = selectCmd.ExecuteReader()) {
					Assert.AreEqual(reader.Read(), true);
					Assert.AreEqual(reader["t"], textP.Value);
					Assert.AreEqual(reader["f"], floatP.Value);
					Assert.AreEqual(reader["i"], integerP.Value);
					Assert.AreEqual(reader["b"], blobP.Value);
					Assert.AreEqual(reader.Read(), false);
				}
			}
		}
 public new void ExecuteNonQuery(string sql, string connectionString)
 {
     using (SqliteConnection conn = new SqliteConnection(connectionString))
     {
         SqliteCommand cmd = new SqliteCommand(sql, conn);
         cmd.CommandTimeout = 1200;
         conn.Open();
         cmd.ExecuteNonQuery();
         conn.Close();
     }
 }
 public new object ExecuteScalar(string sql, string connectionString)
 {
     using (SqliteConnection conn = new SqliteConnection(connectionString))
     {
         SqliteCommand cmd = new SqliteCommand(sql, conn);
         cmd.CommandTimeout = 1200;
         conn.Open();
         object retVal = cmd.ExecuteScalar();
         conn.Close();
         return retVal;
     }
 }
		internal SqliteDataReader (SqliteCommand cmd, IntPtr pVm, int version)
		{
			command = cmd;
			rows = new ArrayList ();
			columns = new ArrayList ();
			column_names = new Hashtable ();
			closed = false;
			current_row = -1;
			reading = true;
			ReadpVm (pVm, version);
			ReadingDone ();
		}
Пример #10
0
        public bool Convert()
        {
            try
            {
                SqliteConnection conn = new SqliteConnection(m_connectionString);
                conn.Open();

                Assembly assem = GetType().Assembly;
                Migration m = new Migration(conn, assem, "RegionStore");

                int version = m.Version;

                if (version <= 14)
                {
                    if (version == 0)
                    {
                        //read rex tables and add to rex database
                        m_log.Info("[regionstore] converting rex tables to rexobjectproperties");
                        if (!ConvertLegacyRexDataToModreX())
                        {
                            conn.Close();
                            return false;
                        }

                        m_log.Info("[RegionStore] Update region migrations");
                        //Add new field to Land table
                        SqliteCommand addAuthbyerIDCmd = new SqliteCommand(addAuthbyerID, conn);
                        addAuthbyerIDCmd.ExecuteNonQuery();

                        //Change migration to version 1
                        m.Version = 1;
                    }

                    //Run migrations up to 9
                    //Note: this run migrations only to point nine since only those files exist in application resources.
                    m.Update();

                    //Skip over 10. Change version to 10
                    //This skips adding of the ClickAction since that already exists in 0.4 database
                    //m.Version = 10;
                }

                conn.Close();
                return true;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[RegionStore] Migration failed. Reason: {0}", e);
                return false;
            }
        }
        public AuthenticationData Get(UUID principalID)
        {
            AuthenticationData ret = new AuthenticationData();
            ret.Data = new Dictionary<string, object>();

            SqliteCommand cmd = new SqliteCommand("select * from `" + m_Realm + "` where UUID = :PrincipalID");
            cmd.Parameters.Add(new SqliteParameter(":PrincipalID", principalID.ToString()));

            IDataReader result = ExecuteReader(cmd, m_Connection);

            try
            {
                if (result.Read())
                {
                    ret.PrincipalID = principalID;

                    if (m_ColumnNames == null)
                    {
                        m_ColumnNames = new List<string>();

                        DataTable schemaTable = result.GetSchemaTable();
                        foreach (DataRow row in schemaTable.Rows)
                            m_ColumnNames.Add(row["ColumnName"].ToString());
                    }

                    foreach (string s in m_ColumnNames)
                    {
                        if (s == "UUID")
                            continue;

                        ret.Data[s] = result[s].ToString();
                    }

                    return ret;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
            }
            finally
            {
                CloseCommand(cmd);
            }

            return null;
        }
Пример #12
0
        protected IDataReader ExecuteReader(SqliteCommand cmd, SqliteConnection connection)
        {
            lock (connection)
            {
                SqliteConnection newConnection =
                        (SqliteConnection)((ICloneable)connection).Clone();
                newConnection.Open();

                cmd.Connection = newConnection;
                //Console.WriteLine("XXX " + cmd.CommandText);

                return cmd.ExecuteReader();
            }
        }
Пример #13
0
    public Database(string file)
    {
        bool create = false;
        if (!File.Exists (file)) {
            create = true;
        }

        try {
            StreamReader srVersion = new StreamReader (file+".version");
            dbVersion = srVersion.ReadToEnd ();
            if (dbVersion != null) {
                dbVersion = dbVersion.Trim();
            }
            srVersion.Close();
        }
        catch {
            dbVersion = null;
        }

        string connectionString = "URI=file:"+file;
        connection = new SqliteConnection(connectionString);
        connection.Open();
        command = connection.CreateCommand();

        if (create) {
            Conf.EmptyCache();
            Assembly thisAssembly = Assembly.GetEntryAssembly ();
            Stream stream = thisAssembly.GetManifestResourceStream("Database.sql");
            if (stream != null) {
                StreamReader sr = new StreamReader (stream);
                string sql = sr.ReadToEnd();
                command.CommandText = sql;
                command.ExecuteNonQuery();

                StreamWriter swVersion = new StreamWriter (file+".version", false);
                swVersion.Write (Defines.VERSION);
                swVersion.Close();

                dbVersion = Defines.VERSION;
            }
            else {
                System.Console.WriteLine("Error creating the database");
            }
        }

        if (dbVersion == null || !dbVersion.Equals (Defines.VERSION)) {
            UpdateDatabase(file, dbVersion);
        }
    }
		internal SqliteDataReader (SqliteCommand cmd, IntPtr pVm, int version)
		{
			command = cmd;
			rows = new ArrayList ();
			column_names_sens = new Hashtable ();
#if NET_2_0
			column_names_insens = new Hashtable (StringComparer.InvariantCultureIgnoreCase);
#else
			column_names_insens = new Hashtable (CaseInsensitiveHashCodeProvider.DefaultInvariant,
							     CaseInsensitiveComparer.DefaultInvariant);
#endif
			closed = false;
			current_row = -1;
			reading = true;
			ReadpVm (pVm, version, cmd);
			ReadingDone ();
		}
		static SqliteDataAdapter PrepareDataAdapter()
		{
			SqliteCommand select  = new SqliteCommand("SELECT t, f, i, b FROM t1",_conn);
			SqliteCommand update = new SqliteCommand("UPDATE t1 SET t = :textP, f = :floatP, i = :integerP, n=:blobP WHERE t = :textP ");
			update.Connection=_conn;
			SqliteCommand delete = new SqliteCommand("DELETE FROM t1 WHERE t = :textP");
			delete.Connection=_conn;
			SqliteCommand insert = new SqliteCommand("INSERT INTO t1  (t, f, i, b ) VALUES(:textP,:floatP,:integerP,:blobP)");
			insert.Connection=_conn;
			SqliteDataAdapter custDA = new SqliteDataAdapter(select);
		
			SqliteParameter textP = new SqliteParameter();
			textP.ParameterName = "textP";
			textP.SourceColumn = "t";
		
			SqliteParameter floatP = new SqliteParameter();
			floatP.ParameterName = "floatP";
			floatP.SourceColumn = "f";
		
			SqliteParameter integerP = new SqliteParameter();
			integerP.ParameterName ="integerP";
			integerP.SourceColumn = "i";

			SqliteParameter blobP = new SqliteParameter();
			blobP.ParameterName = "blobP";
			blobP.SourceColumn = "b";
		
			update.Parameters.Add(textP);
			update.Parameters.Add(floatP);
			update.Parameters.Add(integerP);
			update.Parameters.Add(blobP);
		
			delete.Parameters.Add(textP);
		
			insert.Parameters.Add(textP);
			insert.Parameters.Add(floatP);
			insert.Parameters.Add(integerP);
			insert.Parameters.Add(blobP);
		
			custDA.UpdateCommand = update;
			custDA.DeleteCommand = delete;
			custDA.InsertCommand = insert;
		
			return custDA;
		}
		public void Select()
		{
			SqliteCommand simpleSelect = new SqliteCommand("SELECT * FROM t1;  ", _conn); // check trailing spaces
			using(_conn)
			{
				_conn.Open();
				SqliteDataReader dr = simpleSelect.ExecuteReader();
				while(dr.Read())
				{
					string test = dr[0].ToString();
					Assert.AreEqual(dr["T"], stringvalue); // also checks case-insensitive column
					Assert.AreEqual(dr["F"], 123);
					Assert.AreEqual(dr["I"], 123);
					Assert.AreEqual(dr["B"], "123");
				}
				Assert.IsTrue(dr.FieldCount>0);
			}
		}
Пример #17
0
        public bool Convert()
        {
            try
            {
                SqliteConnection conn = new SqliteConnection(m_connectionString);
                conn.Open();

                Assembly assem = GetType().Assembly;
                Migration m = new Migration(conn, assem, "InventoryStore");
                if (m.Version == 0)
                {
                    //Apply all changes to db
                    SqliteCommand addSalePriceCmd = new SqliteCommand(addSalePrice, conn);
                    addSalePriceCmd.ExecuteNonQuery();

                    SqliteCommand addSaleTypeCmd = new SqliteCommand(addSaleType, conn);
                    addSaleTypeCmd.ExecuteNonQuery();

                    SqliteCommand addCreationDateCmd = new SqliteCommand(addCreationDate, conn);
                    addCreationDateCmd.ExecuteNonQuery();

                    SqliteCommand addGroupIDCmd = new SqliteCommand(addGroupID, conn);
                    addGroupIDCmd.ExecuteNonQuery();

                    SqliteCommand addGroupOwnedCmd = new SqliteCommand(addGroupOwned, conn);
                    addGroupOwnedCmd.ExecuteNonQuery();

                    SqliteCommand addFlagsCmd = new SqliteCommand(addFlags, conn);
                    addFlagsCmd.ExecuteNonQuery();

                    //then change version number
                    m.Version = 1;
                }
                return true;
            }
            catch (Exception e)
            {
                m_log.ErrorFormat("[InventoryStore] Migration failed. Reason: {0}", e);
                return false;
            }
        }
Пример #18
0
        public string Get(string scope, string key)
        {
            string command = "SELECT `value` FROM `generic` WHERE `key` = @key";
            if (!String.IsNullOrEmpty(scope))
                command += " AND `scope` = @scope";

            lock (this)
            {
                using (SqliteCommand cmd = new SqliteCommand(command, m_Connection))
                {
                    cmd.Parameters.Add("@key", key);
                    if (!String.IsNullOrEmpty(scope))
                        cmd.Parameters.Add("@scope", scope);

                    using (IDataReader result = cmd.ExecuteReader())
                    {
                        if (result.Read())
                            return result.GetString(0);
                        else
                            return null;
                    }
                }
            }
        }
		public void Create()
		{
			try
			{
				if(File.Exists(_uri))
				{
					_conn.Dispose();
					// We want to start with a fresh db for each full run
					// The database is created on the first open()
					File.Delete(_uri);
					_conn = new SqliteConnection (_connectionString);
				}
			}
			catch(Exception e)
			{
				throw e;
			}
			
			SqliteCommand createCommand = new SqliteCommand("CREATE TABLE t1(t  TEXT,  f FLOAT, i INTEGER, b TEXT);",_conn);
			SqliteCommand insertCommand = new SqliteCommand("INSERT INTO t1  (t, f, i, b ) VALUES('" + stringvalue + "',123,123,'123')",_conn);

			try
			{
				_conn.Open();
				createCommand.ExecuteNonQuery();
				insertCommand.ExecuteNonQuery();
			}
			catch(Exception e)
			{
				throw new AssertionException("Create table failed",e);
			}
			finally
			{
				_conn.Close();  
			}
		}
Пример #20
0
        /// <summary>
        /// <list type="bullet">
        /// <item>Initialises Inventory interface</item>
        /// <item>Loads and initialises a new SQLite connection and maintains it.</item>
        /// <item>use default URI if connect string string is empty.</item>
        /// </list>
        /// </summary>
        /// <param name="dbconnect">connect string</param>
        public void Initialise(string dbconnect)
        {
            if (dbconnect == string.Empty)
            {
                dbconnect = "URI=file:inventoryStore.db,version=3";
            }
            m_log.Info("[INVENTORY DB]: Sqlite - connecting: " + dbconnect);
            conn = new SqliteConnection(dbconnect);

            conn.Open();

            Assembly assem = GetType().Assembly;
            Migration m = new Migration(conn, assem, "InventoryStore");
            m.Update();

            SqliteCommand itemsSelectCmd = new SqliteCommand(invItemsSelect, conn);
            invItemsDa = new SqliteDataAdapter(itemsSelectCmd);
            //            SqliteCommandBuilder primCb = new SqliteCommandBuilder(primDa);

            SqliteCommand foldersSelectCmd = new SqliteCommand(invFoldersSelect, conn);
            invFoldersDa = new SqliteDataAdapter(foldersSelectCmd);

            ds = new DataSet();

            ds.Tables.Add(createInventoryFoldersTable());
            invFoldersDa.Fill(ds.Tables["inventoryfolders"]);
            setupFoldersCommands(invFoldersDa, conn);
            m_log.Info("[INVENTORY DB]: Populated Inventory Folders Definitions");

            ds.Tables.Add(createInventoryItemsTable());
            invItemsDa.Fill(ds.Tables["inventoryitems"]);
            setupItemsCommands(invItemsDa, conn);
            m_log.Info("[INVENTORY DB]: Populated Inventory Items Definitions");

            ds.AcceptChanges();
        }
Пример #21
0
        public stats_default_page_values rep_DefaultReport_data(SqliteConnection db, List<Scene> m_scene)
        {
            stats_default_page_values returnstruct = new stats_default_page_values();
            returnstruct.all_scenes = m_scene.ToArray();
            lock (db)
            {
                string SQL = @"SELECT COUNT(DISTINCT agent_id) as agents, COUNT(*) as sessions, AVG(avg_fps) as client_fps, 
                                AVG(avg_sim_fps) as savg_sim_fps, AVG(avg_ping) as sav_ping, SUM(n_out_kb) as num_in_kb, 
                                SUM(n_out_pk) as num_in_packets, SUM(n_in_kb) as num_out_kb, SUM(n_in_pk) as num_out_packets, AVG(mem_use) as sav_mem_use
                                FROM stats_session_data;";
                SqliteCommand cmd = new SqliteCommand(SQL, db);
                SqliteDataReader sdr = cmd.ExecuteReader();
                if (sdr.HasRows)
                {
                    sdr.Read();
                    returnstruct.total_num_users = Convert.ToInt32(sdr["agents"]);
                    returnstruct.total_num_sessions = Convert.ToInt32(sdr["sessions"]);
                    returnstruct.avg_client_fps = Convert.ToSingle(sdr["client_fps"]);
                    returnstruct.avg_sim_fps = Convert.ToSingle(sdr["savg_sim_fps"]);
                    returnstruct.avg_ping = Convert.ToSingle(sdr["sav_ping"]);
                    returnstruct.total_kb_out = Convert.ToSingle(sdr["num_out_kb"]);
                    returnstruct.total_kb_in = Convert.ToSingle(sdr["num_in_kb"]);
                    returnstruct.avg_client_mem_use = Convert.ToSingle(sdr["sav_mem_use"]);

                }
            }
            return returnstruct;
        }
Пример #22
0
 private bool ExistsFirstLastName(String fname, String lname)
 {
     string FindUser = "******";
     using (SqliteCommand cmd = new SqliteCommand(FindUser, g_conn))
     {
         cmd.Parameters.Add(new SqliteParameter(":username", fname));
         cmd.Parameters.Add(new SqliteParameter(":surname", lname));
         try
         {
             using (IDataReader reader = cmd.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     reader.Close();
                     return true;
                 }
                 else
                 {
                     reader.Close();
                     return false;
                 }
             }
         }
         catch (Exception ex)
         {
             m_log.Error("[USER DB]: Exception searching for user's first and last name: " + ex.ToString());
             return false;
         }
     }
 }
Пример #23
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="queryID"></param>
        /// <param name="query"></param>
        /// <returns></returns>
        override public List<AvatarPickerAvatar> GeneratePickerResults(UUID queryID, string query)
        {
            List<AvatarPickerAvatar> returnlist = new List<AvatarPickerAvatar>();
            string[] querysplit;
            querysplit = query.Split(' ');
            if (querysplit.Length == 2)
            {
                using (SqliteCommand cmd = new SqliteCommand(AvatarPickerAndSQL, g_conn))
                {
                    cmd.Parameters.Add(new SqliteParameter(":username", querysplit[0] + "%"));
                    cmd.Parameters.Add(new SqliteParameter(":surname", querysplit[1] + "%"));

                    using (IDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            AvatarPickerAvatar user = new AvatarPickerAvatar();
                            user.AvatarID = new UUID((string) reader["UUID"]);
                            user.firstName = (string) reader["username"];
                            user.lastName = (string) reader["surname"];
                            returnlist.Add(user);
                        }
                        reader.Close();
                    }
                }
            }
            else if (querysplit.Length == 1)
            {
                using (SqliteCommand cmd = new SqliteCommand(AvatarPickerOrSQL, g_conn))
                {
                    cmd.Parameters.Add(new SqliteParameter(":username", querysplit[0] + "%"));
                    cmd.Parameters.Add(new SqliteParameter(":surname", querysplit[0] + "%"));

                    using (IDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            AvatarPickerAvatar user = new AvatarPickerAvatar();
                            user.AvatarID = new UUID((string) reader["UUID"]);
                            user.firstName = (string) reader["username"];
                            user.lastName = (string) reader["surname"];
                            returnlist.Add(user);
                        }
                        reader.Close();
                    }
                }
            }
            return returnlist;
        }
Пример #24
0
        /// <summary>
        /// Get (fetch?) the friendlist for a user
        /// </summary>
        /// <param name="friendlistowner">UUID of the friendlist owner</param>
        /// <returns>The friendlist list</returns>
        override public List<FriendListItem> GetUserFriendList(UUID friendlistowner)
        {
            List<FriendListItem> returnlist = new List<FriendListItem>();

            using (SqliteCommand cmd = new SqliteCommand(SelectFriendsByUUID, g_conn))
            {
                cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.ToString()));

                try
                {
                    using (IDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            FriendListItem user = new FriendListItem();
                            user.FriendListOwner = friendlistowner;
                            user.Friend = new UUID((string)reader[0]);
                            user.FriendPerms = Convert.ToUInt32(reader[1]);
                            user.FriendListOwnerPerms = Convert.ToUInt32(reader[2]);
                            returnlist.Add(user);
                        }
                        reader.Close();
                    }
                }
                catch (Exception ex)
                {
                    m_log.Error("[USER DB]: Exception getting friends list for user: " + ex.ToString());
                }
            }

            return returnlist;
        }
Пример #25
0
 /// <summary>
 /// Update the friendlist permission
 /// </summary>
 /// <param name="friendlistowner">UUID of the friendlist owner</param>
 /// <param name="friend">UUID of the friend to modify</param>
 /// <param name="perms">updated permission flag</param>
 override public void UpdateUserFriendPerms(UUID friendlistowner, UUID friend, uint perms)
 {
     string UpdatePerms = "update userfriends set friendPerms=:perms where ownerID=:ownerID and friendID=:friendID";
     using (SqliteCommand cmd = new SqliteCommand(UpdatePerms, g_conn))
     {
         cmd.Parameters.Add(new SqliteParameter(":perms", perms));
         cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.ToString()));
         cmd.Parameters.Add(new SqliteParameter(":friendID", friend.ToString()));
         cmd.ExecuteNonQuery();
     }
 }
Пример #26
0
 /// <summary>
 /// Remove a user from the friendlist
 /// </summary>
 /// <param name="friendlistowner">UUID of the friendlist owner</param>
 /// <param name="friend">UUID of the friend to remove</param>
 override public void RemoveUserFriend(UUID friendlistowner, UUID friend)
 {
     string DeletePerms = "delete from userfriends where (ownerID=:ownerID and friendID=:friendID) or (ownerID=:friendID and friendID=:ownerID)";
     using (SqliteCommand cmd = new SqliteCommand(DeletePerms, g_conn))
     {
         cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.ToString()));
         cmd.Parameters.Add(new SqliteParameter(":friendID", friend.ToString()));
         cmd.ExecuteNonQuery();
     }
 }
Пример #27
0
        /// <summary>
        /// Add a new friend in the friendlist
        /// </summary>
        /// <param name="friendlistowner">UUID of the friendlist owner</param>
        /// <param name="friend">UUID of the friend to add</param>
        /// <param name="perms">permission flag</param>
        override public void AddNewUserFriend(UUID friendlistowner, UUID friend, uint perms)
        {
            if (ExistsFriend(friendlistowner, friend))
                return;

            string InsertFriends = "insert into userfriends(ownerID, friendID, friendPerms) values(:ownerID, :friendID, :perms)";
            using (SqliteCommand cmd = new SqliteCommand(InsertFriends, g_conn))
            {
                cmd.Parameters.Add(new SqliteParameter(":ownerID", friendlistowner.ToString()));
                cmd.Parameters.Add(new SqliteParameter(":friendID", friend.ToString()));
                cmd.Parameters.Add(new SqliteParameter(":perms", perms));
                cmd.ExecuteNonQuery();
            }
            using (SqliteCommand cmd = new SqliteCommand(InsertFriends, g_conn))
            {
                cmd.Parameters.Add(new SqliteParameter(":ownerID", friend.ToString()));
                cmd.Parameters.Add(new SqliteParameter(":friendID", friendlistowner.ToString()));
                cmd.Parameters.Add(new SqliteParameter(":perms", perms));
                cmd.ExecuteNonQuery();
            }
        }
Пример #28
0
 private bool ExistsFriend(UUID owner, UUID friend)
 {
     string FindFriends = "select * from userfriends where (ownerID=:ownerID and friendID=:friendID) or (ownerID=:friendID and friendID=:ownerID)";
     using (SqliteCommand cmd = new SqliteCommand(FindFriends, g_conn))
     {
         cmd.Parameters.Add(new SqliteParameter(":ownerID", owner.ToString()));
         cmd.Parameters.Add(new SqliteParameter(":friendID", friend.ToString()));
         try
         {
             using (IDataReader reader = cmd.ExecuteReader())
             {
                 if (reader.Read())
                 {
                     reader.Close();
                     return true;
                 }
                 else
                 {
                     reader.Close();
                     return false;
                 }
             }
         }
         catch (Exception ex)
         {
             m_log.Error("[USER DB]: Exception getting friends list for user: " + ex.ToString());
             return false;
         }
     }
 }
Пример #29
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="daf"></param>
        /// <param name="conn"></param>
        private void setupAvatarAppearanceCommands(SqliteDataAdapter daa, SqliteConnection conn)
        {
            daa.InsertCommand = SQLiteUtil.createInsertCommand("avatarappearance", ds.Tables["avatarappearance"]);
            daa.InsertCommand.Connection = conn;

            daa.UpdateCommand = SQLiteUtil.createUpdateCommand("avatarappearance", "Owner=:Owner", ds.Tables["avatarappearance"]);
            daa.UpdateCommand.Connection = conn;

            SqliteCommand delete = new SqliteCommand("delete from avatarappearance where Owner=:Owner");
            delete.Parameters.Add(SQLiteUtil.createSqliteParameter("Owner", typeof(String)));
            delete.Connection = conn;
            daa.DeleteCommand = delete;
        }
Пример #30
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="daf"></param>
        /// <param name="conn"></param>
        private void setupUserFriendsCommands(SqliteDataAdapter daf, SqliteConnection conn)
        {
            daf.InsertCommand = SQLiteUtil.createInsertCommand("userfriends", ds.Tables["userfriends"]);
            daf.InsertCommand.Connection = conn;

            daf.UpdateCommand = SQLiteUtil.createUpdateCommand("userfriends", "ownerID=:ownerID and friendID=:friendID", ds.Tables["userfriends"]);
            daf.UpdateCommand.Connection = conn;

            SqliteCommand delete = new SqliteCommand("delete from userfriends where ownerID=:ownerID and friendID=:friendID");
            delete.Parameters.Add(SQLiteUtil.createSqliteParameter("ownerID", typeof(String)));
            delete.Parameters.Add(SQLiteUtil.createSqliteParameter("friendID", typeof(String)));
            delete.Connection = conn;
            daf.DeleteCommand = delete;

        }