PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.databases.mysql > ALTER VIEW is not allowed in stored procedures
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
ALTER VIEW is not allowed in stored procedures

Réponse
 
LinkBack Outils de la discussion
Vieux 29/12/2007, 11h16   #1
Michael Martinek
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut ALTER VIEW is not allowed in stored procedures

Greetings!

I'm looking to add a stored procedure that will ALTER an existing
view. Strangely, it isn't working.. and I could swear it was before,
as I remember testing this step by step in developing it.

DROP PROCEDURE IF EXISTS bankIdent_ChangeView;
DELIMITER |
CREATE DEFINER=CURRENT_USER PROCEDURE bankIdent_ChangeView(
IN sNewView ENUM('offline','production')
)
SQL SECURITY INVOKER
MODIFIES SQL DATA
BEGIN
IF sNewView = 'offline' THEN
ALTER VIEW bank_ident_popular_v AS SELECT * FROM
bank_ident_offline_t WHERE is_popular = 'Y';
ELSEIF sNewView = 'production' THEN
ALTER VIEW bank_ident_popular_v AS SELECT * FROM bank_ident_t
WHERE is_popular = 'Y';
END IF;
END; |
DELIMITER ;

It's a simple procedure that allows me to update a view to access an
offline version of a table while weekly maintenance is performed on
the primary table.

What's strange, is that if I instead do:

DROP VIEW IF EXISTS bank_ident_popular_v;
CREATE VIEW bank_ident_popular_v AS SELECT ...;

Then it works. However, I'd prefer not to leave any "gaps". This is
based around an engine type using MyISAM, so transactions aren't an
option. Is anyone aware of a tweak to allow the ALTER to be performed?

Alternatively, is anyone very familiar with the internal locking
mechanisms with the calls? For example, when this maintenance routine
is called.. when this procedure drops the existing view, is there an
opportunity for other calls to fail on their selection since the view
doesn't exist? My understanding is that there is an opportunity for
this, and that is what I'm trying to avoid. Although the routine
shouldn't take long to execute, and certain the view should only take
at most a few milliseconds to create, I'd prefer to minimize as many
functional gaps as possible.

Thanks!
Michael
  Réponse avec citation
Vieux 29/12/2007, 13h37   #2
Kees Nuyt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: ALTER VIEW is not allowed in stored procedures

On Sat, 29 Dec 2007 03:16:49 -0800 (PST), Michael Martinek
<michael.martinek@gmail.com> wrote:

>Greetings!
>
>I'm looking to add a stored procedure that will ALTER an existing
>view. Strangely, it isn't working.. and I could swear it was before,
>as I remember testing this step by step in developing it.
>
>DROP PROCEDURE IF EXISTS bankIdent_ChangeView;
>DELIMITER |
>CREATE DEFINER=CURRENT_USER PROCEDURE bankIdent_ChangeView(
> IN sNewView ENUM('offline','production')
>)
>SQL SECURITY INVOKER
>MODIFIES SQL DATA
>BEGIN
> IF sNewView = 'offline' THEN
> ALTER VIEW bank_ident_popular_v AS SELECT * FROM
>bank_ident_offline_t WHERE is_popular = 'Y';
> ELSEIF sNewView = 'production' THEN
> ALTER VIEW bank_ident_popular_v AS SELECT * FROM bank_ident_t
>WHERE is_popular = 'Y';
> END IF;
>END; |
>DELIMITER ;
>
>It's a simple procedure that allows me to update a view to access an
>offline version of a table while weekly maintenance is performed on
>the primary table.
>
>What's strange, is that if I instead do:
>
>DROP VIEW IF EXISTS bank_ident_popular_v;
>CREATE VIEW bank_ident_popular_v AS SELECT ...;
>
>Then it works. However, I'd prefer not to leave any "gaps". This is
>based around an engine type using MyISAM, so transactions aren't an
>option. Is anyone aware of a tweak to allow the ALTER to be performed?
>
>Alternatively, is anyone very familiar with the internal locking
>mechanisms with the calls? For example, when this maintenance routine
>is called.. when this procedure drops the existing view, is there an
>opportunity for other calls to fail on their selection since the view
>doesn't exist? My understanding is that there is an opportunity for
>this, and that is what I'm trying to avoid. Although the routine
>shouldn't take long to execute, and certain the view should only take
>at most a few milliseconds to create, I'd prefer to minimize as many
>functional gaps as possible.


Perhaps
"CREATE OR REPLACE VIEW"
is a better strategy. You could try it.

From the manual:
This statement creates a new view, or replaces an existing
one if the OR REPLACE clause is given. If the view does
not exist, CREATE OR REPLACE VIEW is the same as CREATE
VIEW. If the view does exist, CREATE OR REPLACE VIEW is
the same as ALTER VIEW.

>Thanks!
>Michael


HTH
--
( Kees
)
c[_] It is difficult to say what is impossible, for the dream of yesterday
is the hope of today and the reality of tomorrow. (Robert Goddard) (#39)
  Réponse avec citation
Vieux 30/12/2007, 00h38   #3
Michael Martinek
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: ALTER VIEW is not allowed in stored procedures

> From the manual:
> This statement creates a new view, or replaces an existing
> one if the OR REPLACE clause is given. If the view does
> not exist, CREATE OR REPLACE VIEW is the same as CREATE
> VIEW. If the view does exist, CREATE OR REPLACE VIEW is
> the same as ALTER VIEW.
> ( Kees


Nice. That does the trick, actually. It's rather odd that we aren't
able to use ALTER VIEW, and instead need to just do "CREATE OR
REPLACE" which has the same effect as an ALTER VIEW. But certainly,
thanks for the ! That was a good catch.


-Michael
  Réponse avec citation
Vieux 30/12/2007, 02h08   #4
Kees Nuyt
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: ALTER VIEW is not allowed in stored procedures

On Sat, 29 Dec 2007 16:38:13 -0800 (PST), Michael Martinek
<michael.martinek@gmail.com> wrote:

>> From the manual:
>> This statement creates a new view, or replaces an existing
>> one if the OR REPLACE clause is given. If the view does
>> not exist, CREATE OR REPLACE VIEW is the same as CREATE
>> VIEW. If the view does exist, CREATE OR REPLACE VIEW is
>> the same as ALTER VIEW.
>> ( Kees

>
>Nice. That does the trick, actually. It's rather odd that we aren't
>able to use ALTER VIEW, and instead need to just do "CREATE OR
>REPLACE" which has the same effect as an ALTER VIEW.


Yes, it is peculiar, and I wasn't very certain it would
work. Thanks for testing and feedback.

>But certainly,
>thanks for the ! That was a good catch.


I'm glad it worked.

>-Michael

--
( Kees
)
c[_] To retain respect for sausages and laws, one must
not watch them in the making. (Otto von Bismarck) (#390)
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h50.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,13701 seconds with 12 queries