Пример #1
0
        ////////////////////////////////////////////////////
        public override IDbCommand GetInsertCommand(DataTable table, IDbDataAdapter adapter, bool bDisableIdsAuto)
        {
            DataColumn[] cols       = table.PrimaryKey;
            string       strChampId = null;

            if (cols != null && cols.Length == 1)
            {
                if (cols[0].AutoIncrement)
                {
                    strChampId = cols[0].ColumnName;
                }
            }

            OracleCommandBuilder builder       = new OracleCommandBuilder((OracleDataAdapter)adapter);
            bool bAvecTriggerMajAuto           = true;
            COracleDatabaseConnexion conOracle = m_connexion as COracleDatabaseConnexion;

            if (conOracle != null)
            {
                if (strChampId != null)
                {
                    conOracle.GetNomSequenceColAuto(table.TableName, strChampId, ref bAvecTriggerMajAuto);
                }
            }
            if (strChampId != null && !bAvecTriggerMajAuto)
            {
                table.Columns[strChampId].AutoIncrement = false;
            }

            OracleCommand cmdInsert = builder.GetInsertCommand();

            if (strChampId != null && !bAvecTriggerMajAuto)
            {
                table.Columns[strChampId].AutoIncrement = true;
            }
            if (m_connexion.IsInTrans())
            {
                cmdInsert.Transaction = (OracleTransaction)m_connexion.Transaction;
            }
            if (strChampId != null)
            {
                C2iOracleDataAdapter oracleAdapter = C2iOracleDataAdapter.GetOracleDataAdapter(adapter);
                if (oracleAdapter != null && !bDisableIdsAuto)
                {
                    oracleAdapter.PreparerInsertionLigneAvecAutoID(table.TableName, strChampId);
                }

                cmdInsert.UpdatedRowSource = UpdateRowSource.Both;
            }

            return(cmdInsert);
        }
Пример #2
0
        ////////////////////////////////////////////////////
        public static C2iOracleDataAdapter GetOracleDataAdapter(IDbDataAdapter adapter)
        {
            C2iOracleDataAdapter oracleAdapter = null;

            if (adapter is C2iDataAdapterForClasseAutoReferencee)
            {
                oracleAdapter = (C2iOracleDataAdapter)((C2iDataAdapterForClasseAutoReferencee)adapter).DataAdapterUtilise;
            }
            else if (adapter is C2iOracleDataAdapter)
            {
                oracleAdapter = (C2iOracleDataAdapter)adapter;
            }

            return(oracleAdapter);
        }
Пример #3
0
        internal void ChargementSYSCHAMPAUTO()
        {
            string strTableChampsAuto = "";

            foreach (string strNomTable in TablesNames)
            {
                if (strNomTable == c_nomTableSysChampAuto)
                {
                    strTableChampsAuto = strNomTable;
                    break;
                }
            }
            if (strTableChampsAuto != "")
            {
                m_dtSYS_CHAMP_AUTO = new DataTable();

                string strRequete            = "SELECT * FROM " + c_nomTableSysChampAuto;
                C2iOracleDataAdapter adapter = (C2iOracleDataAdapter)GetSimpleReadAdapter(strRequete);
                DataSet   ds = new DataSet();
                DataTable dt = new DataTable();
                dt.TableName = "strTableChampsAuto";
                ds.Tables.Add(dt);
                this.FillAdapter(adapter, ds);
                CUtilDataAdapter.DisposeAdapter(adapter);
                m_dtSYS_CHAMP_AUTO = ds.Tables[0];
            }
            if (m_dtSYS_CHAMP_AUTO == null)
            {
                //Création de la tbale
                m_dtSYS_CHAMP_AUTO = new DataTable(c_nomTableSysChampAuto);
                m_dtSYS_CHAMP_AUTO.Columns.Add(c_nomChampSysChampAutoNomTable, typeof(string));
                m_dtSYS_CHAMP_AUTO.Columns.Add(c_nomChampSysChampAutoNomChamp, typeof(string));
                m_dtSYS_CHAMP_AUTO.Columns.Add(c_nomChampSysChampAutoSeqName, typeof(string));
                m_dtSYS_CHAMP_AUTO.Columns.Add(c_nomChampSysChampAutoTriggerName, typeof(string));
            }
            foreach (CInfoChampAuto info in m_listeChampsAutoHorsGestionSys)
            {
                DataRow row = m_dtSYS_CHAMP_AUTO.NewRow();
                row[c_nomChampSysChampAutoNomChamp]    = info.NomChamp;
                row[c_nomChampSysChampAutoNomTable]    = info.NomTable;
                row[c_nomChampSysChampAutoTriggerName] = info.NomTrigger;
                row[c_nomChampSysChampAutoSeqName]     = info.NomSequence;
                m_dtSYS_CHAMP_AUTO.Rows.Add(row);
            }
        }
Пример #4
0
        /// /////////////////////////////////////////////////////
        public override IDataAdapter GetTableAdapter(string strNomTableInDb)
        {
            IDbCommand    commandtmp = GetConnexion().CreateCommand();
            OracleCommand command    = new OracleCommand();

            command.CommandText = "Select * from " + GetNomTableForRequete(strNomTableInDb);
            command.Connection  = new OracleConnection(commandtmp.Connection.ConnectionString);


            if (command.Connection.ConnectionString.Length < ConnexionString.Length)
            {
                command.Connection.ConnectionString = ConnexionString;
            }


            C2iOracleDataAdapter adapter = new C2iOracleDataAdapter(command, this);

            return(adapter);
        }
        ////////////////////////////////////////////////////
        public override IDbCommand GetInsertCommand(CStructureTable structure, bool bDisableIdAuto, IDbDataAdapter adapter)
        {
            bool bGestionAutoId = true;
            COracleDatabaseConnexion conOracle = m_connexion as COracleDatabaseConnexion;

            if (conOracle != null && structure.ChampsId.Length == 1 && structure.ChampsId[0].IsAutoId)
            {
                conOracle.GetNomSequenceColAuto(structure.NomTableInDb, structure.ChampsId[0].NomChamp, ref bGestionAutoId);
            }
            //Stef 2804 : N'exclue pas les champs exclus de l'insertion !

            IDbCommand command = m_cacheRequetes.GetCache(structure.NomTable, ETypeRequete.Insert);

            if (command == null)
            {
                string strReq    = "insert into " + structure.NomTableInDb + "(";
                string strValues = "(";
                foreach (CInfoChampTable champ in structure.Champs)
                {
                    if ((!champ.IsAutoId || bDisableIdAuto || !bGestionAutoId))
                    {
                        if (champ.TypeDonnee != typeof(CDonneeBinaireInRow) && !champ.TypeDonnee.IsSubclassOf(typeof(CDonneeBinaireInRow)))
                        {
                            strReq    += champ.NomChamp + ",";
                            strValues += GetNomParametreFor(champ, DataRowVersion.Current) + ",";
                        }
                    }
                }
                strReq    = strReq.Substring(0, strReq.Length - 1) + ")";
                strValues = strValues.Substring(0, strValues.Length - 1) + ")";
                strReq   += " values " + strValues;

                command             = m_connexion.GetConnexion().CreateCommand();
                command.CommandText = strReq;
                //Ajoute les paramètres
                foreach (CInfoChampTable champ in structure.Champs)
                {
                    if ((!champ.IsAutoId || bDisableIdAuto || !bGestionAutoId))
                    {
                        if (champ.TypeDonnee != typeof(CDonneeBinaireInRow) && !champ.TypeDonnee.IsSubclassOf(typeof(CDonneeBinaireInRow)))
                        {
                            command.Parameters.Add(GetParametreFor(command, champ, DataRowVersion.Current, ParameterDirection.Input));
                        }
                    }
                }
                m_cacheRequetes.SetCache(structure.NomTable, ETypeRequete.Insert, command);
            }


            if (structure.HasChampIdAuto)
            {
                C2iOracleDataAdapter oracleAdapter = C2iOracleDataAdapter.GetOracleDataAdapter(adapter);
                if (oracleAdapter != null && !bDisableIdAuto)
                {
                    oracleAdapter.PreparerInsertionLigneAvecAutoID(structure.NomTableInDb, structure.ChampsId[0].NomChamp);
                }
            }
            command.Connection       = m_connexion.GetConnexion();
            command.CommandType      = CommandType.Text;
            command.Transaction      = m_connexion.Transaction;
            command.UpdatedRowSource = UpdateRowSource.FirstReturnedRecord;

            return(command);
        }
Пример #6
0
        /// /////////////////////////////////////////////////////
        protected override IDbDataAdapter GetNewAdapter(IDbCommand selectCommand)
        {
            C2iOracleDataAdapter adapter = new C2iOracleDataAdapter((OracleCommand)selectCommand, this);

            return((IDbDataAdapter)adapter);
        }
Пример #7
0
        //---------------------------------------------------------------------------
        public CResultAErreur UpdateStructureBase(IIndicateurProgression indicateurProgress)
        {
            CResultAErreur result = CResultAErreur.True;

            m_indicateurProgress = indicateurProgress;

            int nVersionDB     = (int)new CDatabaseRegistre(Connection).GetValeurLong(c_strCleVersionBDD, -1);
            int nVersionFinale = m_structureDB.GetLastVersion();

            int nOldVersion = nVersionDB;

            if (nVersionDB < 0)
            {
                result = InitialisationBase();
            }

            if (m_bForceMAJ)
            {
                nVersionDB = nVersionDB > 0 ? nVersionDB - 1 : 0;
            }

            if (nVersionDB < 0)
            {
                nVersionDB = 0;
            }

            if (m_indicateurProgress != null)
            {
                m_indicateurProgress.PushLibelle(I.T("Database Update|30005"));
                m_indicateurProgress.SetBornesSegment(nVersionDB, nVersionFinale);
                //m_indicateurProgress.PushSegment(nVersionDB, nVersionFinale);
            }

            result = m_connexion.GetDataBaseCreator().UpdateStructureTableRegistre();

            while (nVersionDB < nVersionFinale && result)
            {
                nVersionDB++;

                result = m_connexion.BeginTrans();

                if (!result)
                {
                    return(result);
                }

                if (m_indicateurProgress != null)
                {
                    m_indicateurProgress.SetInfo("Version " + nVersionDB.ToString());
                    m_indicateurProgress.SetValue(nVersionDB - 1);
                    m_indicateurProgress.PushLibelle("DataBase v" + nVersionDB.ToString());
                    m_indicateurProgress.PushSegment(nVersionDB - 1, nVersionDB);
                }

                result = UpdateToVersion(nVersionDB);

                //Validation ou annulation des modifications si erreur
                if (!result)
                {
                    m_connexion.RollbackTrans();
                    result.EmpileErreur(I.T("Database Update Error|30006"));
                    throw new CExceptionErreur(result.Erreur);
                }
                else
                {
                    result = m_connexion.CommitTrans();
                }


                if (m_indicateurProgress != null)
                {
                    m_indicateurProgress.PopSegment();
                    m_indicateurProgress.PopLibelle();
                }
            }

            /*if (m_indicateurProgress != null)
             *      m_indicateurProgress.PopSegment();*/

            //rafraichit les caches de schéma
            CObjetServeur.ClearCacheSchemas();
            C2iOracleDataAdapter.ClearCacheSchemas();
            CStructureTable.ClearCache();

            return(result);
        }