Création et appel de procédures stockées et fonctions
Bonjour tout le monde,
Je me lance dans le grand bain sans savoir nager et avec des parpaings accrochés aux pieds...
En fait je crée des procédures stockées et des fonctions qui seront appelées lors du dump de la base à l'install de mon appli pour faire de la config.
Je voudrais juste que vous me disiez si je suis bon pour la syntaxe :)
Voici mes fonctions :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
-- Get the ConfigurationFileId
CREATE FUNCTION GetConfigurationFileId
(@FileNameToFind NVARCHAR(255))
RETURNS INT
AS
DECLARE @IdxConfigurationFile INT
BEGIN
SELECT @IdxConfigurationFile = IDX_CONFIGURATION_FILE FROM TBL_CONFIGURATION_FILE
WHERE STR_FILENAME = @FileNameToFind AND INT_MAJOR = 1 AND INT_MINOR = 0 AND INT_REVISION = 0 AND INT_BUILD = 0;
END
RETURN(@IdxConfigurationFile);
GO |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
CREATE FUNCTION CreateConfigurationFile
(@TemplateName NVARCHAR(255), @FileNameToFind NVARCHAR(255), @FileNameToCreate NVARCHAR(255))
RETURNS INT
AS
DECLARE @Template INT
DECLARE @IdxConfigurationFile INT
DECLARE @FileContent VARBINARY(MAX)
BEGIN
-- Get the template file
SELECT @Template = IDX_TEMPLATE FROM TBL_TEMPLATE_FILES WHERE STR_NAME = @TemplateName;
-- Get the content of the physical configuration file
SELECT @FileContent = * FROM OPENROWSET(BULK @FileNameToFind, VARBINARY(MAX));
-- Create the new configuration file in the database
INSERT INTO TBL_CONFIGURATION_FILES (STR_FILENAME, STR_FILEPATH, INT_MAJOR, INT_MINOR, INT_REVISION, INT_BUILD, CLOB_CONTENT, FLG_IS_VALID, DAT_LAST_CHANGE, IDX_LAST_CHANGE_USER, IDX_TEMPLATE)
VALUES (@FileNameToCreate, '%HOMEPATH%', 1, 0, 0, 0, @FileContent, 1, GETDATE(), 48264, @Template);
-- Get the new Id
SELECT @IdxConfigurationFile = @@IDENTITY;
END
RETURN(@IdxConfigurationFile);
GO |
Code:
1 2 3 4 5 6 7 8 9 10 11
|
CREATE PROCEDURE SetLink
@IdxConfigurationFile INT,
@IdxTypeOP INT,
@IdxScenario INT,
@IdxOrdre INT,
@IdxCommande INT
AS
INSERT INTO TBL_CONFIG_FILES_COMMANDES (IDX_CONFIGURATION_FILE, IDX_TYPE_OPERATION, IDX_SCENARIO, INT_ORDRE, IDX_COMMANDE)
VALUES (@IdxConfigurationFile, @IdxTypeOP, @IdxScenario, @IdxOrdre, @IdxCommande);
GO |
Et mes appels :
Code:
1 2 3 4 5 6 7 8 9 10 11
|
-- Try to get the file Id
SELECT @IdxConfigurationFile = GetConfigurationFileId('LoadInFile.exe.config');
IF @IdxConfigurationFile < 0 -- File doesn't exist yet in the database
BEGIN
SELECT @IdxConfigurationFile = CreateConfigurationFile('CONFIG_LCABALLECTURE', '{WorkingDir}/LCABALLecture_Template.exe.config', 'LCABALLecture.exe.config');
END
-- Create the link between the configuration file and the command
EXECUTE SetLink @IdxConfigurationFile, @IdxTypeOP, @IdxScenario, @IdxOrdre, @IdxCommande; |
Les paramètres passés aux fonctions sont instanciés avant bien sûr :)
Voila, est-ce que quelque chose vous fait saigner les yeux ? :roll: