Exemplo n.º 1
0
        // Name: CheckVersion - Test the stored schema version
        //
        // Description:
        //      Compares the specified version number with the stored version
        //      If the verson matches or exceeds the required version the
        //      function returns true.
        //
        // Inputs:
        //      Major       Major version number.
        //      Minor       Minor version number.
        //      Release     Release version number.
        //
        // Outputs:
        //      None.
        //
        // Returns:
        //      true        Version matches or exceeds the required version.
        //      false       Incorrect version level.
        //
        // History
        //      02-Oct-2006 ([email protected])
        //          Created.
        public bool CheckVersion(int Major, int Minor, int Release)
        {
            bool retcode = false;
            IngresCommand ingresVersionSelect = new IngresCommand();
            IngresDataAdapter ingresVersionAdapter;

            // Create query parameters and store the method parameter values
            // into each one.
            IngresParameter majorVersion = new IngresParameter("ver_major", IngresType.Int);
            IngresParameter minorVersion = new IngresParameter("ver_minor", IngresType.Int); ;
            IngresParameter releaseVersion = new IngresParameter("ver_release", IngresType.Int);

            majorVersion.Value = Major;
            minorVersion.Value = Minor;
            releaseVersion.Value = Release;

            ingresVersionSelect = new IngresCommand(
                "SELECT FIRST 1 ver_major, ver_minor, ver_release, ver_date, ver_install" +
                " FROM version" +
                " WHERE ver_major >= ? AND ver_minor >= ? AND ver_release >=?" +
                " ORDER BY ver_id DESC",
                ingresConnection1);
            ingresVersionSelect.Connection = ingresConnection1;
            ingresVersionAdapter = new IngresDataAdapter(ingresVersionSelect);
            try
            {
                ingresVersionSelect.Connection.Open();
                ingresVersionSelect.Prepare();
                ingresVersionSelect.Parameters.Clear();
                ingresVersionSelect.Parameters.Add(majorVersion);
                ingresVersionSelect.Parameters.Add(minorVersion);
                ingresVersionSelect.Parameters.Add(releaseVersion);
                versionDataSet.Clear();
                ingresVersionAdapter.Fill(versionDataSet);
                if (versionDataSet.Tables[0].Rows.Count > 0)
                {
                    retcode = true;
                }
            }
            catch (Ingres.Client.IngresException ex)
            {
                if (DisplayError(ex) == DialogResult.OK)
                {
                    throw;
                }
                else
                {
                    Application.Exit();
                }
            }
            finally
            {
                if (ingresVersionSelect != null &&
                    ingresVersionSelect.Connection != null)
                    ingresVersionSelect.Connection.Close();
            }
            return (retcode);
        }