Ejemplo n.º 1
0
        public object Execute(Query query) {
            var cmd = this.NewCommand(query);
            object id = null;

            try {
                this.Connection.Open();
                //cmd.ExecuteNonQuery();
                id = cmd.ExecuteScalar();
                //this.Bubble(query);
            } catch (Exception ex) {
                ex = new DatabaseException(this.DatabaseName, query, "Execute Error-> " + ex.Message, ex);

                //Self.Fork(delegate(object evt) {
                //    this.Source.Bubble((DatabaseEvent)evt);
                //}, new DatabaseEvent(query, TimeSpan.FromMilliseconds(this.ElapsedTS), ex));

                throw ex;
            } finally {
                cmd.Dispose();
                this.Connection.TryClose();
            }


            if (!query.HasOutputs)
                return id;

            var outputs = query.Outputs;
            if (outputs.Count == 1)
                return outputs[0].Value;

            return outputs.Select(x => x.Value).ToList();
        }
Ejemplo n.º 2
0
        public DataSet Select(Query query) {
            var cmd = this.NewCommand(query);
            var adapter = this.Source.Driver.CreateAdapter(cmd);
            DataSet ds = new DataSet();
            try {
                this.Connection.Open();
                
                adapter.Fill(ds);
                
                //this.Bubble(query);
            } catch (Exception ex) {
                ex = new DatabaseException(this.DatabaseName, query, "Select Error-> " + ex.Message, ex);
                //Self.Fork(delegate(object evt) {
                //    this.Source.Bubble((DatabaseEvent)evt);
                //}, new DatabaseEvent(query, TimeSpan.FromMilliseconds(this.ElapsedTS), ex));

                throw ex;
            } finally {
                cmd.Dispose();
                this.Connection.TryClose();
            }
            return ds;
        }
Ejemplo n.º 3
0
        public object ExecuteScalar(Query query) {
            var cmd = this.NewCommand(query);
            Object o = null;
            try {
                this.Connection.Open();
                o = cmd.ExecuteScalar();
                //this.Bubble(query);
            } catch (Exception ex) {
                //ex = new DataException("Database.ExecuteScalar Error-> " + ex.Message, ex.InnerException);
                ex = new DatabaseException(this.DatabaseName, query, "ExecuteScalar Error-> " + ex.Message, ex);

                //Self.Fork(delegate(object evt) {
                //    this.Source.Bubble((DatabaseEvent)evt);
                //}, new DatabaseEvent(query, TimeSpan.FromMilliseconds(this.ElapsedTS), ex));

                throw ex;
            } finally {
                cmd.Dispose();
                this.Connection.TryClose();
            }

            return o;
        }
Ejemplo n.º 4
0
        public void ExecuteBatch(params Query[] queries) {
            //throw new NotImplementedException();
            if (queries.Length == 0)
                return;

            //var first = queries[0];
            //var cmd = this.NewCommand(first);
            //var connection = command.Connection;
            try {
                this.Connection.Open();
                foreach (var query in queries) {
                    var cmd = this.NewCommand(query);
                    try {
                        cmd.ExecuteNonQuery();
                        //this.Bubble(query);
                    } catch (Exception ex) {
                        ex = new DatabaseException(this.DatabaseName, query, "Execute Error-> " + ex.Message, ex);
                        //this.Bubble(query, ex);
                    } finally {
                        cmd.Dispose();
                    }
                }
            } catch (Exception ex) {
                ex = new DatabaseException(this.DatabaseName, "Execute Error-> " + ex.Message, ex);
                throw ex;
            } finally {
                this.Connection.TryClose();
            }
        }
Ejemplo n.º 5
0
        public void ExecuteReader(Query query, Action<RecordReader> recordReader) {
            var cmd = this.NewCommand(query);
            try {
                this.Connection.Open();

                using (RecordReader reader = new RecordReader(cmd.ExecuteReader() as DbDataReader)) {
                    if (reader.HasRows) {
                        while (reader.Read()) {
                            recordReader(reader);
                        }
                    }

                    reader.Destroy();
                }

                //this.Bubble(query);
            } catch (Exception ex) {
                //ex = new DataException("Database.ExecuteReader Error-> " + ex.Message, ex.InnerException);
                ex = new DatabaseException(this.DatabaseName, query, "ExecuteReader Error-> " + ex.Message, ex);
                //Self.Fork(delegate(object evt) {
                //    this.Source.Bubble((DatabaseEvent)evt);
                //}, new DatabaseEvent(query, TimeSpan.FromMilliseconds(this.ElapsedTS), ex));

                throw ex;
            } finally {
                cmd.Dispose();
                this.Connection.TryClose();
            }
        }