Beispiel #1
0
        /// <summary> Retrieves executable 'CREATE TABLE..' text for specified source and target tables.  'sourceTable' is accessible by 'sourceCmd'
        /// </summary>
        /// <param name="sourceCmd"></param>
        /// <param name="sourceTable"></param>
        /// <param name="targetTable"></param>
        /// <returns></returns>
        public string GetSchemaDefinition(VEDatabase sourceCmd, string sourceTable, string targetTable)
        {
            string text     = "",
                   alias    = Alias,
                   errorMsg = "VEAdmin: Unable to generate the requisite definition for the following reason - \r\n";

            if (!ProcedureExists(sourceCmd, alias + getTableSchema))
            {
                message = errorMsg + message;
            }
            else
            {
                VEDataParameters parameters = Parameters(sourceCmd, alias + getTableDefinition);

                if (parameters == null)
                {
                    message = errorMsg + message;
                }
                else
                {
                    int s1 = sourceTable.IndexOf('.'),
                        s2 = sourceTable.LastIndexOf('.'),
                        t1 = targetTable.IndexOf('.'),
                        t2 = targetTable.LastIndexOf('.');

                    parameters["@table"].Value = s1 > 0 && s1 < s2?sourceTable.Substring(s2 + 1) : sourceTable.Substring(s1 + 1);

                    parameters["@sourceOwner"].Value = s1 > 0 && s1 < s2?sourceTable.Substring(s1 + 1, s2 - s1 - 1) : sourceTable.Substring(0, s1);

                    parameters["@targetOwner"].Value = t1 > 0 && t1 < t2?targetTable.Substring(t1 + 1, t2 - t1 - 1) : targetTable.Substring(0, t1);

                    if (sourceCmd.ExecuteStoredProcedure(parameters) >= 0)
                    {
                        text = (string)parameters["@tableDefinition"].Value;
                    }
                }
            }

            return(text);
        }
Beispiel #2
0
        /// <summary> Returns DataTable 'veTableDependencies' generated by stored procedure '[.AdminAccount].GetTableDependcies' containing schema table dependencies sequenced by increasing levels of dependency.
        /// </summary>
        /// <param name="cmd"></param>
        /// <param name="schema"></param>
        /// <returns></returns>
        public DataTable GetTableDependencies(VEDatabase cmd, string schema)
        {
            DataTable copyTableDependencies = null;

            string alias     = Alias,
                   procedure = alias + getTableDependencies;

            VEDataParameters parameters = Parameters(cmd, procedure);

            if (parameters == null || parameters.Count == 0)
            {
                message = "VEDataAdmin.GetTableDependencies: Unable to create the dependencies table because of the following error -\r\n" + message + "\r\n";
            }
            else
            {
                parameters["@owner"].Value = schema;

                if (cmd.ExecuteStoredProcedure(parameters) < 0 || parameters["@table"] == null)
                {
                    message = string.Format("VEDataAdmin.GetTableDependencies: An error occurred executing procedure '{0}'\r\n{1}", procedure, parameters.ToString());
                }
                else
                {
                    string tablename = (string)parameters["@table"].Value;

                    if (cmd.Fill(tablename, string.Format("SELECT * FROM {0} ORDER BY Sequence, Name", tablename)) >= 0)
                    {
                        copyTableDependencies = cmd[tablename];
                    }
                    else
                    {
                        message = string.Format("VEDataAdmin.GetTableDependencies: An error occurred retrieving dependencies from '{0}'", tablename);
                    }
                }
            }

            return(copyTableDependencies);
        }