Пример #1
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         reader?.Dispose();
         reader = null;
         cmd?.Dispose();
         cmd = null;
     }
     base.Dispose(disposing);
 }
Пример #2
0
        public DataTable GetBySqlQuery(string sqlQuery, bool dbNullParams, PagingProperties currentPaging, params SqlParameter[] _params)
        {
            if (dbNullParams)
            {
                _params = this.DbNullNonSetParams(sqlQuery, _params);
            }
            this.NullToDbNull(_params);
            DataTable dataTable = new DataTable();

            System.Data.Common.DbDataReader reader = null;

            if (currentPaging != null)
            {
                System.Data.Common.DbCommand command = null;
                string commandText;
                if (currentPaging.HasPaging)
                {
                    string countQuery = (sqlQuery.Contains("order") && (!sqlQuery.ToLower().Contains("top") && !sqlQuery.ToLower().Contains("offset"))) ? $"{sqlQuery} OFFSET 0 ROWS " : sqlQuery;
                    //get row count
                    command = this.GetDbCommand($"select count(*) from ({countQuery}) as returntable ", _params);
                    currentPaging.RowsCount = command.ExecuteScalar().ToIntObj();
                    command.Dispose();

                    //get data with paging and sorting
                    commandText = string.Format($@"{sqlQuery} { (!string.IsNullOrWhiteSpace(currentPaging.SortColumn) ? $"order by {currentPaging.SortColumn} {currentPaging.SortType}" : "")} OFFSET {((currentPaging.PageIndex - 1) * currentPaging.PageSize)} ROWS FETCH NEXT {currentPaging.PageSize} ROWS ONLY ");
                }
                else
                {
                    //get data with paging and sorting
                    commandText = string.Format($@"{sqlQuery} { (!string.IsNullOrWhiteSpace(currentPaging.SortColumn) ? $"order by {currentPaging.SortColumn} {currentPaging.SortType}" : "")}");
                }

                command = this.GetDbCommand(commandText, _params);
                reader  = command.ExecuteReader();
                dataTable.Load(reader);
                reader.Close();
            }
            else
            {
                System.Data.Common.DbCommand command = this.GetDbCommand(sqlQuery, _params);
                reader = this.GetDbCommand(sqlQuery, _params).ExecuteReader();
                dataTable.Load(reader);
                reader.Close();
            }


            return(dataTable);
        }
Пример #3
0
        private void Base_InitializeSchema(ref System.Data.DataTable Value, Common.SchemaTypeEnum SchemaType, string ObjectName, bool FullData)
        {
            System.Data.Common.DbCommand objCommand = null;
            try
            {
                objCommand = this.GetCommand();

                if (SchemaType == Common.SchemaTypeEnum.TABLES)
                {
                    objCommand.CommandText = Base_InitializeSchema_TABLES(ObjectName, FullData);
                }
                else if (SchemaType == Common.SchemaTypeEnum.COLUMNS)
                {
                    objCommand.CommandText = Base_InitializeSchema_COLUMNS(ObjectName, FullData);
                }
                else if (SchemaType == Common.SchemaTypeEnum.INDEXES)
                {
                    objCommand.CommandText = Base_InitializeSchema_INDEXES(ObjectName, FullData);
                }
                else if (SchemaType == Common.SchemaTypeEnum.VIEWS)
                {
                    objCommand.CommandText = Base_InitializeSchema_VIEWS(ObjectName, FullData);
                }
                else if (SchemaType == Common.SchemaTypeEnum.PROCEDURES)
                {
                    objCommand.CommandText = Base_InitializeSchema_PROCEDURES(ObjectName, FullData);
                }
                else if (SchemaType == Common.SchemaTypeEnum.FUNCTIONS)
                {
                    objCommand.CommandText = Base_InitializeSchema_FUNCTIONS(ObjectName, FullData);
                }

                Value = this.GetDataTable(objCommand);
            }
            catch (Exception ex) { throw ex; }
            finally
            {
                if (objCommand != null)
                {
                    objCommand.Dispose();
                    objCommand = null;
                }
            }
        }
Пример #4
0
        public Response ValidationSchedule(string bz)
        {
            using (DZEntities dzEntities = new DZEntities())
            {
                Response response = new Response();
                response.IsSuccess = true;

                System.Data.EntityClient.EntityConnection entityConnection = (System.Data.EntityClient.EntityConnection)dzEntities.Connection;
                entityConnection.Open();
                System.Data.Common.DbConnection storeConnection = entityConnection.StoreConnection;
                System.Data.Common.DbCommand    cmd             = storeConnection.CreateCommand();
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.CommandText = "P_UN_VALIDATION";

                OracleParameter[] sqlpara = new OracleParameter[3];
                sqlpara[0] = new OracleParameter("p_bz", bz);
                sqlpara[1] = new OracleParameter("p_ErrCode", OracleDbType.Varchar2, 30);
                sqlpara[2] = new OracleParameter("p_ErrMsg", OracleDbType.Varchar2, 1000);

                sqlpara[0].Direction = ParameterDirection.Input;
                sqlpara[1].Direction = ParameterDirection.Output;
                sqlpara[2].Direction = ParameterDirection.Output;

                cmd.Parameters.Add(sqlpara[0]);
                cmd.Parameters.Add(sqlpara[1]);
                cmd.Parameters.Add(sqlpara[2]);

                cmd.ExecuteNonQuery();


                if (cmd.Parameters[1].Value.ToString() == "1")
                {
                    response.IsSuccess   = true;
                    response.MessageText = cmd.Parameters[2].Value.ToString();
                }
                else
                {
                    response.IsSuccess   = false;
                    response.MessageText = cmd.Parameters[2].Value.ToString();
                }
                cmd.Dispose();
                return(response);
            }
        }
Пример #5
0
 protected virtual void Dispose(bool disposing)
 {
     if (_disposed)
     {
         return;
     }
     if (disposing)
     {
         if (dbCommand.Connection != null)
         {
             if (dbCommand.Connection.State != System.Data.ConnectionState.Closed)
             {
                 dbCommand.Connection.Close();
             }
         }
         dbCommand.Dispose();
     }
     _disposed = true;
 }
Пример #6
0
        private void CreateTables()
        {
            string query1 = "CREATE TABLE items ( id INTEGER, parentid INTEGER, name TEXT, chunk INTEGER, data BLOB )";
            string query2 = "CREATE TABLE header ( taskid INTEGER, data BLOB )";
            string query3 = "CREATE TABLE bchunks ( rootdrive INTEGER, id INTEGER, taskid INTEGER, name TEXT, stor1 INTEGER, stor2 INTEGER, stor3 INTEGER )";
            string query4 = "CREATE TABLE rootdrives ( id INTEGER, mountpath TEXT, snapshottedpath TEXT, maxitemid INTEGER )";
            // version : client node version that creates the index. complete : after all inserts have been done ; our way
            // to ensure index is not corrupt at software level (ie software didn't crash before committing all inserts)
            string query5 = "CREATE TABLE config(version TEXT, complete INTEGER)";

            System.Data.Common.DbCommand comm = indexDbConn.CreateCommand();
            comm.CommandText = query1;
            comm.ExecuteNonQuery();
            comm.CommandText = query2;
            comm.ExecuteNonQuery();
            comm.CommandText = query3;
            comm.ExecuteNonQuery();
            comm.CommandText = query4;
            comm.ExecuteNonQuery();
            comm.CommandText = query5;
            comm.ExecuteNonQuery();
            comm.Dispose();
        }
Пример #7
0
        private void Execute_DATAs()
        {
            Int16     iStrategy = 0;
            DataView  oDataView = null;
            DataTable oObjects  = null;

            try
            {
                iStrategy = this.GetExportStrategyByType("DATAs", ref oDataView);
                if (iStrategy == 0)
                {
                    return;
                }
                else
                {
                    if (iStrategy == 1)
                    {
                        oObjects = this.Data.Schema.GetTables(false);
                    }
                    else if (iStrategy == 2)
                    {
                        oObjects = oDataView.ToTable();
                        oObjects.Columns["Name"].ColumnName = "ObjectName";
                    }

                    for (Int32 iCol = (oObjects.Columns.Count - 1); iCol >= 0; iCol--)
                    {
                        if (oObjects.Columns[iCol].ColumnName != "ObjectName")
                        {
                            oObjects.Columns.RemoveAt(iCol);
                        }
                    }

                    this.Progress.ProgressStart(oObjects.Rows.Count);
                    foreach (DataRow oRow in oObjects.Rows)
                    {
                        this.Progress.Progress();
                        System.Data.Common.DbCommand oCommand = null;
                        DataTable oDataTable = null;
                        DataSet   oDataSet   = null;

                        try
                        {
                            oCommand             = this.Data.GetCommand();
                            oCommand.CommandText = "SELECT * FROM " + oRow["ObjectName"].ToString() + "";

                            oDataTable           = this.Data.GetDataTable(oCommand);
                            oDataTable.TableName = oRow["ObjectName"].ToString();

                            oDataSet = new DataSet(oRow["ObjectName"].ToString() + "Dataset");
                            oDataSet.Tables.Add(oDataTable);
                            this.WriteXml(oDataSet, oRow["ObjectName"].ToString());
                        }
                        catch (Exception ex) { throw ex; }
                        finally
                        {
                            if (oDataSet != null)
                            {
                                oDataSet.Dispose();
                                oDataSet = null;
                            }
                            if (oDataTable != null)
                            {
                                oDataTable.Dispose();
                                oDataTable = null;
                            }
                            if (oCommand != null)
                            {
                                oCommand.Dispose();
                                oCommand = null;
                            }
                        }
                    }

                    oObjects.TableName = "DATAs";
                    this.Types.Tables.Add(oObjects);
                }
            }
            catch (Exception ex) { throw ex; }
            finally
            {
                if (oObjects != null)
                {
                    oObjects.Dispose();
                    oObjects = null;
                }
                if (oDataView != null)
                {
                    oDataView.Dispose();
                    oDataView = null;
                }
            }
        }
 //Methods
 public override void Dispose()
 {
     newcommand.Dispose();
     _dbConnection.Close();
 }