Ejemplo n.º 1
0
        public async Task <List <T> > selectAsync <T>(string sql = "", string orderby = "", List <StatementParameter> parameters = null) where T : class, new()
        {
            ConfigStatement c;
            List <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))
                {
                    result = d.fillToList <T>();
                }
            }
            finally
            {
                this.Semaphore.Release();
            }

            return(result);
        }
Ejemplo n.º 2
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.º 3
0
 private void finalizeSqlData()
 {
     if (this._result_data != null)
     {
         this._result_data.Dispose();
         this._result_data = null;
     }
 }
Ejemplo n.º 4
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.º 5
0
        public async Task <SQLData> executeAsync(string sql)
        {
            bool completed = false;

            this.finalizeSqlData();
            this.createCommand();
            this._command.CommandText = sql;

            var stopwatch = Stopwatch.StartNew();

            while (!completed)
            {
                try
                {
                    this._datareader = await this._command.ExecuteReaderAsync();

                    completed = true;
                }
                catch (SqliteException ex)
                {
                    if (!isBusySQLite(ex.SqliteErrorCode) || stopwatch.ElapsedMilliseconds > kMaxTimeWaitUnlock)
                    {
                        this.LastError = ex.Message;
                        throw ex;
                    }
                }
                catch (Exception ex)
                {
                    this.LastError = ex.Message;
                    throw ex;
                }
            }

            SQLData d = new SQLData(this._datareader, this._command, this);

            this._result_data = d;
            this.empty();
            return(d);
        }
Ejemplo n.º 6
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);
        }