We’re moving our forums to a new platform.

You can still browse and search existing topics, but you can no longer create new topics or post replies.

For questions, technical issues, or feature requests, please don’t hesitate to contact our support team at support@advancedinstaller.com.

Thank you for your understanding!

Antarctica
Posts: 110
Joined: Tue Jul 08, 2014 9:24 am

Custom message on certain SQL error

I would like to tell my inline SQL script to not show the error

"Violation of Primary Key constraint: Cannot insert duplicate key"

but display a custom warning message instead.

Is this possible?
Daniel
Posts: 8283
Joined: Mon Apr 02, 2012 1:11 pm
Contact: Website

Re: Custom message on certain SQL error

Hello,

I'm afraid we don't have support for this. Maybe we'll consider your request in a future version of Advanced Installer. Thank you for your suggestion. Until then, you can only specify the SQL script error behavior using one of the options from "On error" combo box from "SQL Script" tab.

All the best,
Daniel
Daniel Radu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
Antarctica
Posts: 110
Joined: Tue Jul 08, 2014 9:24 am

Re: Custom message on certain SQL error

I stumbled over some interesting question at stackoverflow and found that, at least when connecting to SQL Server, one can throw a custom error message on expected errors.

Code: Select all

IF EXISTS(SELECT * FROM languageStrings)
RAISERROR('Data was already found in database. Skipping insertion.',16,1)
ELSE
BEGIN
    INSERT INTO languageStrings ...
    INSERT INTO languageStrings ...
    INSERT INTO languageStrings ...
END
GO
This error message is only shown if AI shows any error message at that position, which is not always the case. It seems that the following throws an error message; and even one for each duplicate key, if "Continue with next statement" is selected:

Code: Select all

INSERT INTO languageStrings ...
GO
INSERT INTO languageStrings ...
GO
while the following does not throw any error message, where I would expect a single message to be thrown.

Code: Select all

INSERT INTO languageStrings ...
INSERT INTO languageStrings ...
GO
Furthermore, it seems that inside a BEGIN ... END statement block, no GO statement separators are allowed. So, the following sql code throws syntax errors:

Code: Select all

BEGIN TRY
INSERT INTO languageStrings ...
GO
INSERT INTO languageStrings ...
GO
END TRY
BEGIN CATCH
RAISERROR('This error should be shown',16,1)
END CATCH
and the following will work, but not show any error message:

Code: Select all

BEGIN TRY
INSERT INTO languageStrings ...
INSERT INTO languageStrings ...
END TRY
BEGIN CATCH
RAISERROR('This error is never visible in AI',16,1)
END CATCH
mihai.petcu
Posts: 3860
Joined: Thu Aug 05, 2010 8:01 am

Re: Custom message on certain SQL error

Hello,

The exact behavior of RAISERROR in different contexts is ODBC driver specific and is not controlled by Advanced Installer.

The SQL Script option "On error" (abort, goto next script, goto next statement) does not affect the visibility (or severity level) of the raised error, but rather controls the package installation operation: abort install, or proceed with the next script/statement.

For controlling the "visibility" of the raised SQL errors you can work with the two SQL Connection settings: "Connection and all its scripts are verbose" and "Log errors to file". Please check our SQL Connection documentation on how to use them.

That being said, in your particular case, I think you should consider redesigning your data INSERT logic to avoid presenting such error messages to the user, rather just check when you need to INSERT or not, and do it accordingly. You have the option to incorporate this logic within your "data import" SQL script, or you can leverage our SQL Query functionality to make the required "pre-flight" checks BEFORE you actually run any SQL scripts for importing new data. Using SQL Queries with Windows Installer data bindings (properties), you can control (dynamically activate) whole portions of your installation package, including subsequent SQL Scripts and deployment logic.

All the best,
Mihai
Mihai Petcu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Building Installers”