Пример #1
0
        public UInt64 editQuestion(VKQuestionInfo info)
        {
            if (!connect())
                return 0;
            String query = null;
            if (info.id == 0)
                query = "insert into VK_QUESTION (text, gender) values (:text, :gender) RETURNING id";
            else
                query = "update VK_QUESTION set text = :text, gender = :gender where id = :qid";

            NpgsqlCommand command = new NpgsqlCommand(query, connection);
            command.Parameters.Add(new NpgsqlParameter("text", NpgsqlTypes.NpgsqlDbType.Varchar));
            command.Parameters["text"].Value = info.text;
            String gender;
            switch (info.gender)
            {
                case VKQuestionInfo.Gender.Female:
                    gender = "F";
                    break;
                case VKQuestionInfo.Gender.Male:
                    gender = "M";
                    break;
                default:
                    gender = "A";
                    break;
            }
            command.Parameters.Add(new NpgsqlParameter("gender", NpgsqlTypes.NpgsqlDbType.Char));
            command.Parameters["gender"].Value = gender;
            if (info.id != 0)
            {
                command.Parameters.Add(new NpgsqlParameter("qid", NpgsqlTypes.NpgsqlDbType.Numeric));
                command.Parameters["qid"].Value = info.id;
            }

            UInt64 retId = 0;

            try
            {
                if (info.id == 0)
                {
                    NpgsqlDataReader rd = command.ExecuteReader();
                    while (rd.Read())
                    {
                        retId = Convert.ToUInt64(rd["ID"]);
                    }
                }
                else
                {
                    command.ExecuteNonQuery();
                    retId = info.id;
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            finally
            {
                disconnect();
            }

            return retId;
        }
Пример #2
0
        public VKQuestionInfo getQuestionInfo(UInt64 questionId)
        {
            Logging.log("getQuestionInfo\n");
            if (!connect())
                return null;

            NpgsqlCommand command = new NpgsqlCommand("select ID, TEXT, GENDER from VK_QUESTION WHERE id = :qid", connection);
            command.Parameters.Add(new NpgsqlParameter("qid", NpgsqlTypes.NpgsqlDbType.Numeric));
            command.Parameters["qid"].Value = questionId;

            VKQuestionInfo ret = null;

            try
            {
                NpgsqlDataReader rd = command.ExecuteReader();
                while (rd.Read())
                {
                    ret = new VKQuestionInfo();
                    ret.id = Convert.ToUInt64(rd["ID"]);
                    ret.text = Convert.ToString(rd["TEXT"]);
                    String g = Convert.ToString(rd["GENDER"]);
                    switch (g)
                    {
                        case "M":
                            ret.gender = VKQuestionInfo.Gender.Male;
                            break;
                        case "F":
                            ret.gender = VKQuestionInfo.Gender.Female;
                            break;
                        default:
                            ret.gender = VKQuestionInfo.Gender.All;
                            break;
                    }
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            finally
            {
                disconnect();
            }
            Logging.log("!getQuestionInfo\n");
            return ret;
        }