Exemple #1
0
        //??? Видалити
        //public string GetViewDirectoryPointers(Query QuerySelect, Guid uid, string field)
        //{
        //	QuerySelect.Field.Add(field);
        //	QuerySelect.Where.Add(new Where("uid", Comparison.EQ, uid));

        //	string query = QuerySelect.Construct();

        //	NpgsqlCommand nCommand = new NpgsqlCommand(query, Connection);
        //	nCommand.Parameters.Add(new NpgsqlParameter("uid", uid));

        //	string value = "";

        //	NpgsqlDataReader reader = nCommand.ExecuteReader();
        //	if (reader.Read())
        //		value = reader[field].ToString();

        //	reader.Close();

        //	return value;
        //}

        public bool FindDirectoryPointer(Query QuerySelect, ref DirectoryPointer directoryPointer)
        {
            QuerySelect.Limit = 1;

            string query = QuerySelect.Construct();

            NpgsqlCommand nCommand = new NpgsqlCommand(query, Connection);

            if (QuerySelect.Where.Count > 0)
            {
                foreach (Where field in QuerySelect.Where)
                {
                    nCommand.Parameters.Add(new NpgsqlParameter(field.Alias, field.Value));
                }
            }

            bool isFind = false;

            NpgsqlDataReader reader = nCommand.ExecuteReader();

            if (reader.Read())
            {
                isFind = true;
                directoryPointer.Init(new UnigueID((Guid)reader["uid"], ""), null);
            }
            reader.Close();

            return(isFind);
        }
        /// <summary>
        /// Пошук по значенню поля (наприклад пошук по назві)
        /// </summary>
        /// <param name="fieldName">Назва поля в базі даних</param>
        /// <param name="fieldValue">Значення поля</param>
        /// <returns>Повертає перший знайдений вказівник</returns>
        protected DirectoryPointer BaseFindByField(string fieldName, object fieldValue)
        {
            DirectoryPointer directoryPointer = new DirectoryPointer(Kernel, Table);

            Query querySelect = new Query(Table);

            querySelect.Where.Add(new Where(fieldName, Comparison.EQ, fieldValue));

            bool isFind = Kernel.DataBase.FindDirectoryPointer(querySelect, ref directoryPointer);

            return(directoryPointer);
        }
Exemple #3
0
        public void SelectDirectoryPointers(Query QuerySelect, List <DirectoryPointer> listDirectoryPointer)
        {
            string query = QuerySelect.Construct();

            NpgsqlCommand nCommand = new NpgsqlCommand(query, Connection);

            foreach (Where field in QuerySelect.Where)
            {
                nCommand.Parameters.Add(new NpgsqlParameter(field.Alias, field.Value));
            }

            NpgsqlDataReader reader = nCommand.ExecuteReader();

            while (reader.Read())
            {
                Dictionary <string, object> fields = null;

                if (QuerySelect.Field.Count > 0 || QuerySelect.FieldAndAlias.Count > 0)
                {
                    fields = new Dictionary <string, object>();

                    foreach (string field in QuerySelect.Field)
                    {
                        fields.Add(field, reader[field]);
                    }

                    foreach (NameValue <string> field in QuerySelect.FieldAndAlias)
                    {
                        fields.Add(field.Value, reader[field.Value]);
                    }
                }

                DirectoryPointer elementPointer = new DirectoryPointer();
                elementPointer.Init(new UnigueID((Guid)reader["uid"]), fields);                 //!!! Подумати як зробити Init protect

                listDirectoryPointer.Add(elementPointer);
            }
            reader.Close();
        }