Ejemplo n.º 1
0
        public async Task <bool> loadAsync <T>(T registry) where T : class, new()
        {
            ConfigStatement c;
            bool            result;

            await this.Semaphore.WaitAsync();

            try
            {
                c = this.getConfigSelect(registry);

                this.addParameters(c.Params);

                using (SQLData d = await this.executeAsync(c.SQL))
                {
                    if (d.next())
                    {
                        d.fill <T>(registry);
                        result = true;
                    }
                    else
                    {
                        result = false;
                    }
                }
            }
            finally
            {
                this.Semaphore.Release();
            }

            return(result);
        }
Ejemplo n.º 2
0
        static internal string buildInString(SQLData data, string field)
        {
            List <string> elements;
            string        result;

            elements = new List <string>();
            result   = "[";

            while (data.next())
            {
                elements.Add(data.getString(field));
            }

            result += buildInString(elements.ToArray());

            result += "]";

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <T> firstAsync <T>(string sql = "", string orderby = "", List <StatementParameter> parameters = null) where T : class, new()
        {
            ConfigStatement c;
            T result;

            if (sql == null)
            {
                sql = "";
            }

            await this.Semaphore.WaitAsync();

            try
            {
                c = this.getConfigSelect(new T(), true);

                if (parameters != null)
                {
                    this.addParameters(parameters);
                }

                using (SQLData d = await this.executeAsync(c.SELECT + " " + sql + " LIMIT 1"))
                {
                    if (d.next())
                    {
                        result = d.fill <T>();
                    }
                    else
                    {
                        result = null;
                    }
                }
            }
            finally
            {
                this.Semaphore.Release();
            }

            return(result);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Método que devuelve la hora del servidor
        /// </summary>
        /// <returns></returns>
        public DateTime getNow()
        {
            DateTime now;
            string   sql;

            this.Semaphore.Wait();
            try
            {
                this.clearParameters();

                if (this.Type == DBMSType.MySQL)
                {
                    sql = "SELECT NOW() AS ahora;";
                }
                else
                {
                    throw new Exception("El sistema gestor de base de datos no pede proporcionar la hora del servidor");
                }

                SQLData d = this.execute(sql);
                try
                {
                    d.next();
                    now = d.getDateTime("ahora");
                }
                finally
                {
                    d.Dispose();
                }
            }
            finally
            {
                this.Semaphore.Release();
            }

            return(now);
        }